[CS-Project-svn_notify] SF.net SVN: cs-project: [839] trunk/1.2
Brought to you by:
crazedsanity
From: <cra...@us...> - 2008-02-14 07:58:07
|
Revision: 839 http://cs-project.svn.sourceforge.net/cs-project/?rev=839&view=rev Author: crazedsanity Date: 2008-02-13 23:58:02 -0800 (Wed, 13 Feb 2008) Log Message: ----------- Beginning to convert setup to use new config::build_update_interface() to display page that builds the config.xml file. Modified Paths: -------------- trunk/1.2/includes/setup/3.inc trunk/1.2/includes/setup.inc trunk/1.2/lib/config.class.php trunk/1.2/lib/site_config.php trunk/1.2/templates/setup/3.content.tmpl Modified: trunk/1.2/includes/setup/3.inc =================================================================== --- trunk/1.2/includes/setup/3.inc 2008-02-14 07:05:11 UTC (rev 838) +++ trunk/1.2/includes/setup/3.inc 2008-02-14 07:58:02 UTC (rev 839) @@ -6,41 +6,23 @@ if($_POST) { - switch($_POST['selectedOption']) { - case 'convertExisting': { - store_setup_data(3, $_POST['fields'], 'convertExisting_post_info'); - $convertObj = new __convertDatabase(); - store_setup_data(3, $convertObj->go(), 'text'); - $convertObj->finish($page); - } - break; - - - case 'newInstall': { - $validSubmission = test_submitted_data($page, $_POST['users']); - if($validSubmission === TRUE) { - $obj = new __setupDefaultValues(); - store_setup_data(3, $obj->go(), 'text'); - $obj->finish($page); - } - else { - store_setup_data(3, $_POST['users'], 'post_info'); - $page->set_message_wrapper( - array( - 'title' => "Invalid User Data", - 'message' => "The user data you submitted appears to be invalid: <BR>\n". $validSubmission, - 'type' => "error" - ) - ); - $page->conditional_header("/setup/3", TRUE); - } - } - break; - - - default: - throw new exception("Invalid option selected!"); - }; + $validSubmission = test_submitted_data($page, $_POST['users']); + if($validSubmission === TRUE) { + $obj = new __setupDefaultValues(); + store_setup_data(3, $obj->go(), 'text'); + $obj->finish($page); + } + else { + store_setup_data(3, $_POST['users'], 'post_info'); + $page->set_message_wrapper( + array( + 'title' => "Invalid User Data", + 'message' => "The user data you submitted appears to be invalid: <BR>\n". $validSubmission, + 'type' => "error" + ) + ); + $page->conditional_header("/setup/3", TRUE); + } $page->conditional_header("/setup/3", TRUE); } @@ -58,14 +40,6 @@ } } } - - //now parse the "convertExisting" stuff... - $convertData = get_setup_data(3, 'convertExisting_post_info'); - if(is_array($convertData)) { - foreach($convertData as $userField => $userValue) { - $page->add_template_var($userField, $userValue); - } - } } @@ -1172,191 +1146,6 @@ -class __convertDatabase { - - - - private $db; - private $newDb; - private $gfObj; - - private $lastNumrows=NULL; - private $lastDberror=NULL; - - //========================================================================= - public function __construct() { - $this->db = new cs_phpDB; - - //retrieve the connection parameters. - $storedParams = get_setup_data(3, 'convertExisting_post_info'); - $params = array(); - foreach($storedParams as $index=>$value) { - $key = preg_replace('/^database__/', '', $index); - $params[$key] = $value; - } - $this->db->connect($params); - - $this->gfObj = new cs_globalFunctions; - $this->gfObj->debugPrintOpt=1; - - - $this->newDb = new cs_phpDb;; - $this->newDb->connect(get_db_params()); - }//end __construct() - //========================================================================= - - - //========================================================================= - public function go() { - //determine what script we have to include & run. - if(!$this->db->is_connected()) { - throw new exception(__METHOD__ .": failed to connect to database..."); - } - else { - $numrows = $this->db->exec("SELECT internal_data_get_value('version_string')"); - $dberror = $this->db->errorMsg(); - - if(!strlen($dberror) && $numrows == 1) { - $data = $this->db->farray(); - $version = $data[0]; - $this->run_conversion($version); - } - else { - throw new exception(__METHOD__ .": failed to get version... ". $dberror); - } - } - - }//end go() - //========================================================================= - - - - //========================================================================= - private function run_conversion($fromVersion) { - - //check if the script exists. - $convertScript = dirname(__FILE__) .'/../../upgrade/convert/'. $fromVersion .'.php'; - if(file_exists($convertScript)) { - require_once($convertScript); - try { - //create the object... - $obj = new convertDatabase($this->db, $this->newDb); - if(method_exists($obj, 'go')) { - $result = $obj->go(); - } - else { - throw new exception(__METHOD__ .": convertDatabase::go() does not exist"); - } - } - catch(exception $e) { - $this->gfObj->debug_print(__METHOD__ .": FATAL EXCEPTION OCCURRED::: ". $e->getMessage(),1); - } - } - else { - throw new exception(__METHOD__ .": conversion script does not exist: ". $convertScript); - } - }//end run_conversion() - //========================================================================= - - - - //========================================================================= - private function get_config_values() { - - store_setup_data(3, 0, 'result'); - $configData = array(); - //setup the list of required items. - $requiredItems = array( - 'log_category_table' => array( - 'prefix' => 'logcat', - 'idColumn' => 'log_category_id', - 'data' => array( - 'database', 'authentication', 'users', 'general', 'project', 'helpdesk', 'todo', - 'tags', 'estimates', 'navigation', 'preferences' - ), - ), - 'record_type_table' => array( - 'prefix' => 'rectype', - 'idColumn' => 'record_type_id', - 'data' => array( - 'project', 'todo', 'helpdesk' - ) - ) - ); - - foreach($requiredItems as $tableName => $info) { - //check that all the required values are present.} - foreach($info['data'] as $itemName) { - $configIndex = $info['prefix'] .'__'. $itemName; - - $getItemSql = "SELECT * FROM ". $tableName ." WHERE lower(name) = '". $itemName ."'"; - $numrows = $this->db->exec($getItemSql); - $dberror = $this->db->errorMsg(); - - if(!strlen($dberror)) { - if($numrows == 1) { - //retrieve the id & store it. - $data = $this->db->farray_fieldnames(); - $configData[$configIndex] = $data[$info['idColumn']]; - } - else { - throw new exception(__METHOD__ .": invalid data...? numrows=(". $numrows ."), dberror::: ". $dberror ."<BR>\nSQL::: ". $getItemSql); - } - } - else { - throw new exception(__METHOD__ .": failed to retrieve id for (". $itemName ."), rows=(". $numrows .") ERROR::: ". $dberror ."<BR>\nSQL::: ". $getItemSql); - } - } - } - - $this->gfObj->debug_print(__METHOD__ .": config data::: ". $this->gfObj->debug_print($configData,0)); - - //set this step's results. - store_setup_data(3, $configData, 'data'); - store_setup_data(3, 1, 'result'); - - return($configData); - }//end get_config_values() - //========================================================================= - - - - //========================================================================= - public function finish(cs_genericPage &$page) { - //retrieve some configuration values. - $this->get_config_values(); - - //create an upgrade{} object, for setting some internal values. - $obj = new _setupUpgrade($this->newDb); - $config = get_setup_data(3, 'data'); - $config['version_string'] = $obj->finalize_conversion(); - store_setup_data(3, $config, 'data'); - - store_setup_data(4, 1, 'accessible'); - $stepRes = get_setup_data(3, 'result'); - if($stepRes == 1) { - $page->set_message_wrapper(array( - 'title' => "Successfully Setup Data", - 'message' => "All default data was stored in the new database successfully!", - 'type' => "status" - )); - $page->conditional_header("/setup/4", TRUE); - } - else { - $page->set_message_wrapper(array( - 'title' => "Step Failed", - 'message' => "Please review the errors below and proceed accordingly.", - 'type' => "error" - )); - $page->conditional_header("/setup/3", TRUE); - } - - }//end finish() - //========================================================================= - -}//end __convertDatabase{} - - class _setupUpgrade extends upgrade { public function __construct(cs_phpDB $db) { Modified: trunk/1.2/includes/setup.inc =================================================================== --- trunk/1.2/includes/setup.inc 2008-02-14 07:05:11 UTC (rev 838) +++ trunk/1.2/includes/setup.inc 2008-02-14 07:58:02 UTC (rev 839) @@ -19,7 +19,8 @@ require_once(dirname(__FILE__) .'/../lib/simpletest/unit_tester.php'); require_once(dirname(__FILE__) .'/../lib/simpletest/reporter.php'); -$configData = read_config_file(FALSE); +$configObj = new config(NULL, FALSE); +$configData = $configObj->read_config_file(FALSE); if(strlen($configData['DATABASE__DBNAME'])) { //setup already complete. Stop 'em. Modified: trunk/1.2/lib/config.class.php =================================================================== --- trunk/1.2/lib/config.class.php 2008-02-14 07:05:11 UTC (rev 838) +++ trunk/1.2/lib/config.class.php 2008-02-14 07:58:02 UTC (rev 839) @@ -12,7 +12,7 @@ private $fileName; //------------------------------------------------------------------------- - public function __construct($fileName=NULL, $redirectOnFileMissing=TRUE) { + public function __construct($fileName=NULL) { $this->gf = new cs_globalFunctions(); $this->fs = new cs_fileSystemClass(dirname(__FILE__) .'/..'); @@ -24,10 +24,6 @@ //Redirect them to the setup page. if(!file_exists($this->fileName)) { $this->fileExists = FALSE; - if($redirectOnFileMissing) { - $this->gf->conditional_header("/setup?from=". urlencode($_SERVER['REQUEST_URI'])); - exit; - } } else { $this->fileExists = TRUE; @@ -58,7 +54,7 @@ } } else { - throw new exception(__METHOD__ .": config file doesn't exist"); + $config = NULL; } return($config); @@ -75,7 +71,7 @@ public function read_config_file($defineConstants=TRUE, $setEverything=TRUE) { $config = $this->get_config_contents(TRUE); - if($defineConstants) { + if(!is_null($config) && $defineConstants) { $conditionallySet = array('VERSION_STRING', 'WORKINGONIT'); foreach($config as $index=>$value) { if(in_array($index, $conditionallySet)) { @@ -104,17 +100,24 @@ //read the sample config. $config = new config(dirname(__FILE__) .'/config.xml', FALSE); - $myData = $config->get_config_contents(FALSE); + $myData = $config->get_config_contents(); + //parse the sample config for it's attributes, so we can display the page properly. + $sampleConfig = new config(dirname(__FILE__) .'/../docs/samples/sample_config.xml', FALSE); + $systemData = $sampleConfig->get_config_contents(FALSE); + $mainAttributes = $myData['attributes']; + unset($myData['type'], $myData['attributes']); $parsedRows = ""; $defaultRowName = 'setting_text'; - foreach($myData as $indexName=>$data) { - $attributes = $data['attributes']; - $value = $data['value']; - unset($data['type'], $data['attributes'], $data['value']); + foreach($systemData as $indexName=>$defaultValue) { + $value = NULL; + if(is_array($myData) && isset($myData[$indexName])) { + $value = $myData[$indexName]; + } + $attributes = $systemData[$indexName]['attributes']; $indexName = strtolower($indexName); //pull the appropriate template row. Modified: trunk/1.2/lib/site_config.php =================================================================== --- trunk/1.2/lib/site_config.php 2008-02-14 07:05:11 UTC (rev 838) +++ trunk/1.2/lib/site_config.php 2008-02-14 07:58:02 UTC (rev 839) @@ -22,6 +22,7 @@ require_once(dirname(__FILE__) .'/cs-phpxml/xmlCreatorClass.php'); require_once(dirname(__FILE__) .'/cs-phpxml/xmlParserClass.php'); require_once(dirname(__FILE__) .'/cs-content/cs_globalFunctions.php'); +require_once(dirname(__FILE__) .'/config.class.php'); define(CONFIG_FILENAME, 'config.xml'); //Set of functions that should be usefull to everyone @@ -62,43 +63,8 @@ //########################################################################## -//------------------------------------------------------------------- -function read_config_file($setEverything=TRUE) { - if(!file_exists(dirname(__FILE__) .'/'. CONFIG_FILENAME)) { - $gf = new cs_globalFunctions; - $gf->conditional_header("/setup?from=". urlencode($_SERVER['REQUEST_URI'])); - exit; - } - - $fs = new cs_fileSystemClass(dirname(__FILE__)); - - $xmlString = $fs->read(CONFIG_FILENAME); - - - //parse the file. - $xmlParser = new xmlParser($xmlString); - - $config = $xmlParser->get_tree(TRUE); - $config = $config['CONFIG']; - unset($config['type'], $config['attributes']); - - $conditionallySet = array('VERSION_STRING', 'WORKINGONIT'); - foreach($config as $index=>$value) { - if(in_array($index, $conditionallySet)) { - //only set this part if we're told to. - if($setEverything) { - define($index, $value); - } - } - else { - define($index, $value); - } - } - - return($config); - -}//end read_config_file() -//------------------------------------------------------------------- +$config = new config(dirname(__FILE__) .'/'. CONFIG_FILENAME, FALSE); +$config->read_config_file(TRUE, TRUE); check_external_lib_versions(); Modified: trunk/1.2/templates/setup/3.content.tmpl =================================================================== --- trunk/1.2/templates/setup/3.content.tmpl 2008-02-14 07:05:11 UTC (rev 838) +++ trunk/1.2/templates/setup/3.content.tmpl 2008-02-14 07:58:02 UTC (rev 839) @@ -2,20 +2,9 @@ {stepData} <form method="POST"> -<div id="setup_text" style="display:inline;"> -<h2>Please Select an Option:</h2> -<a href="javascript:void(setup__enableInput('setup', 'newInstall'));">Perform New Install</a> -or -<a href="javascript:void(setup__enableInput('setup', 'convertExisting'));">Convert Existing Database</a> -</div> -<input type="hidden" id="setup_selectedOption" name="selectedOption" value=""> - -<div id="setup_newInstall_div" style="display:none;"> - - <p> This step will build the following default values in the database: <ul> @@ -59,80 +48,9 @@ </tr> </table> -</div> -<div id="setup_convertExisting_div" style="display:none;"> -<p> - <blink><font color="red">!!!WARNING!!!<b></b></font></blink> This process may take <b>several minutes</b> to complete, - depending upon the speed of the two servers, this webserver, and how many records need to be transferred.<BR><BR> - - This step will attempt to do the following: - <ul> - <li>Determine existing database version</li> - <li>Convert existing information</li> - <li>Ensure the following items contain the necessary values (in new database): - <ul> - <li>Version information</li> - <li>Log categories, classes, and record type data</li> - <li>Attribute records</li> - <li>Anonymous contact data & groups</li> - <li>Status records</li> - <li>Tag names</li> - <li>Preferences & options</li> - <li>Administrator/user information</li> - </ul> - </li> - </ul> -</p> -<table border="1" cellpadding="3" cellspacing="0"> - <tr> - <th>Database Name (cs_project)</th> - - <td><input type="text" name="fields[database__dbname]" value="{database__dbname}"></td> - - <td>Name of the database within PostgreSQL (i.e. "cs_project")</td> - </tr> - <tr> +<input id="submitButton" type="submit" name="go" value="Create default values & proceed to the next step" onClick="new Effect.DropOut('submitButton');"> - <th>Hostname (localhost)</th> - - <td><input type="text" name="fields[database__host]" value="{database__host}"></td> - - <td>Fully qualified host name (like "taz.google.com" or "localhost").</td> - </tr> - <tr> - <th>Port (5432)</th> - - <td><input type="text" name="fields[database__port]" value="{database__port}"></td> - - - <td>Port to connect to PostgreSQL on (default is 5432).</td> - </tr> - <tr> - <th>Database Username (postgres)</th> - - <td><input type="text" name="fields[database__user]" value="{database__user}"></td> - - <td>Username for connecting to PostgreSQL (if you don't know, it's probably "postgres", though connecting as a SUPERUSER is generally accepted as a BAD THING).</td> - </tr> - - <tr> - <th>Database Password</th> - - <td><input type="text" name="fields[database__password]" value="{database__password}"></td> - - <td>Password for connecting to PostgreSQL (for a trusted connection, this can be blank).</td> - </tr> -</table> -</div> - -<div id="setup_newInstall_submitButton" style="display:none;"> - <input id="submitButton" type="submit" name="go" value="Create default values & proceed to the next step" onClick="new Effect.DropOut('submitButton');"> -</div> -<div id="setup_convertExisting_submitButton" style="display:none;"> - <input id="submitButton2" type="submit" name="go" value="Convert existing database & proceed to the next step" onClick="new Effect.DropOut('submitButton2');"> -</div> - </form> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |