[CS-Project-svn_notify] SF.net SVN: cs-project: [858] trunk/1.2/upgrade
Brought to you by:
crazedsanity
From: <cra...@us...> - 2008-03-30 04:08:47
|
Revision: 858 http://cs-project.svn.sourceforge.net/cs-project/?rev=858&view=rev Author: crazedsanity Date: 2008-03-29 21:08:45 -0700 (Sat, 29 Mar 2008) Log Message: ----------- Consolidated all upgrades into 1.2.0-ALPHA4, removed previous upgrade scripts. Modified Paths: -------------- trunk/1.2/upgrade/upgrade.xml trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA4.php Removed Paths: ------------- trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA2.php trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA3.php Modified: trunk/1.2/upgrade/upgrade.xml =================================================================== --- trunk/1.2/upgrade/upgrade.xml 2008-03-28 05:16:39 UTC (rev 857) +++ trunk/1.2/upgrade/upgrade.xml 2008-03-30 04:08:45 UTC (rev 858) @@ -19,17 +19,11 @@ in an unstable state. Unstable is bad, m'kay?</system_note> <matching> - <v1.2.0-ALPHA1> - <target_version>1.2.0-ALPHA2</target_version> - <script_name>upgradeTo1.2.0-ALPHA2.php</script_name> - <class_name>upgrade_to_1_2_0_ALPHA2</class_name> + <v1.2.0-ALPHA3> + <target_version>1.2.0-ALPHA4</target_version> + <script_name>upgradeTo1.2.0-ALPHA4.php</script_name> + <class_name>upgrade_to_1_2_0_ALPHA4</class_name> <call_method>run_upgrade</call_method> - </v1.2.0-ALPHA1> - <v1.2.0-ALPHA2> - <target_version>1.2.0-ALPHA3</target_version> - <script_name>upgradeTo1.2.0-ALPHA3.php</script_name> - <class_name>upgrade_to_1_2_0_ALPHA3</class_name> - <call_method>run_upgrade</call_method> - </v1.2.0-ALPHA2> + </v1.2.0-ALPHA3> </matching> </upgrade> Deleted: trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA2.php =================================================================== --- trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA2.php 2008-03-28 05:16:39 UTC (rev 857) +++ trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA2.php 2008-03-30 04:08:45 UTC (rev 858) @@ -1,95 +0,0 @@ -<?php -/* - * Created on Nov 20, 2007 - */ - - -class upgrade_to_1_2_0_ALPHA2 extends dbAbstract { - - private $logsObj; - - //========================================================================= - public function __construct(cs_phpDB &$db) { - if(!$db->is_connected()) { - throw new exception(__METHOD__ .": database is not connected"); - } - $this->db = $db; - - $this->logsObj = new logsClass($this->db, 'Upgrade'); - - $this->gfObj = new cs_globalFunctions; - $this->gfObj->debugPrintOpt = DEBUGPRINTOPT; - }//end __construct() - //========================================================================= - - - - //========================================================================= - public function run_upgrade() { - - - $this->db->beginTrans(__METHOD__); - - $this->run_schema_changes(); - $this->update_tag_icons(); - - $this->db->commitTrans(__METHOD__); - - }//end run_upgrade() - //========================================================================= - - - - //========================================================================= - private function run_schema_changes() { - - $this->gfObj->debug_print(__METHOD__ .": running SQL file..."); - $this->run_sql_file(dirname(__FILE__) .'/../docs/sql/upgrades/upgradeTo1.2.0-ALPHA2.sql'); - - $details = "Executed SQL file, '". $this->lastSQLFile ."'. Encoded contents::: ". - base64_encode($this->fsObj->read($this->lastSQLFile)); - $this->logsObj->log_by_class($details, 'system'); - }//end run_schema_changes() - //========================================================================= - - - - //========================================================================= - private function update_tag_icons() { - - $sql = "SELECT tag_name_id, name, icon_name FROM tag_name_table ORDER BY tag_name_id"; - if($this->run_sql($sql) && $this->lastNumrows > 1) { - $allTags = $this->db->farray_fieldnames('name', 'tag_name_id'); - - $iconMods = array( - 'critical' => 'red_x', - 'bug' => 'bug', - 'feature request' => 'feature_request', - 'committed' => 'check_red', - 'verified' => 'check_yellow', - 'released' => 'check_green' - ); - - $updates = 0; - foreach($iconMods as $name=>$icon) { - if(isset($allTags[$name])) { - //update. - $sql = "UPDATE tag_name_table SET icon_name='". $icon ."' WHERE tag_name_id=". $allTags[$name]['tag_name_id']; - } - else { - //insert. - $sql = "INSERT INTO tag_name_table (name, icon_name) VALUES ('". $name ."', '". $icon ."');"; - } - $this->run_sql($sql); - $updates += $this->lastNumrows; - } - } - else { - throw new exception(__METHOD__ .": failed to retrieve tag names"); - } - - }//end update_tag_modifiers() - //========================================================================= -} - -?> Deleted: trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA3.php =================================================================== --- trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA3.php 2008-03-28 05:16:39 UTC (rev 857) +++ trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA3.php 2008-03-30 04:08:45 UTC (rev 858) @@ -1,86 +0,0 @@ -<?php -/* - * Created on February 08, 2008 - */ - - -class upgrade_to_1_2_0_ALPHA3 extends dbAbstract { - - private $logsObj; - - //========================================================================= - public function __construct(cs_phpDB &$db) { - if(!$db->is_connected()) { - throw new exception(__METHOD__ .": database is not connected"); - } - $this->db = $db; - - $this->logsObj = new logsClass($this->db, 'Upgrade'); - - $this->gfObj = new cs_globalFunctions; - $this->gfObj->debugPrintOpt = 1; - }//end __construct() - //========================================================================= - - - - //========================================================================= - public function run_upgrade() { - - $this->update_config_file(); - - return('Upgrade complete'); - }//end run_upgrade() - //========================================================================= - - - - //========================================================================= - public function update_config_file() { - $fs = new cs_fileSystemClass(dirname(__FILE__) .'/../'); - $sampleXmlObj = new XMLParser($fs->read('docs/samples/sample_config.xml')); - $siteXmlObj = new XMLParser($fs->read(CONFIG_FILE_LOCATION)); - - $updateXml = new xmlCreator(); - $updateXml->load_xmlparser_data($siteXmlObj); - - - //BACKUP ORIGINAL XML CONFIG... - $backupFile = 'lib/__BACKUP__'. time() .'__'. CONFIG_FILENAME; - $fs->create_file($backupFile); - $fs->openFile($backupFile); - $fs->write($updateXml->create_xml_string()); - - $sampleIndexes = $sampleXmlObj->get_tree(TRUE); - $sampleIndexes = $sampleIndexes['CONFIG']; - - $siteConfigIndexes = $siteXmlObj->get_tree(TRUE); - $siteConfigIndexes = $siteConfigIndexes['CONFIG']; - - foreach($sampleIndexes as $indexName=>$indexValue) { - $path = '/CONFIG/'. $indexName; - $attributes = $sampleXmlObj->get_attribute($path); - #debug_print(__METHOD__ .": attributes from sample (/CONFIG/". $indexName ."::: ",1); - #debug_print($attributes,1); - debug_print(__METHOD__ .': indexName=('. $indexName .'), indexValue=('. $indexValue .'), original config value=('. $siteConfigIndexes[$indexName] .')'); - - //add tag if it's not there, update values otherwise. - $tagValue = $attributes['DEFAULT']; - if(isset($siteConfigIndexes[$indexName])) { - $tagValue = $siteConfigIndexes[$indexName]; - } - elseif($indexName == 'PHPMAILER_HOST' && isset($siteConfigIndexes['CONFIG_EMAIL_SERVER_IP'])) { - $tagValue = $siteConfigIndexes['CONFIG_EMAIL_SERVER_IP']; - $updateXml->remove_path('/CONFIG/CONFIG_EMAIL_SERVER_IP'); - } - $updateXml->add_tag($path, $tagValue, $attributes); - } - - $this->gfObj->debug_print($this->gfObj->cleanString($updateXml->create_xml_string(), 'htmlentity_plus_brackets')); - $fs->openFile(CONFIG_FILE_LOCATION); - $fs->write($updateXml->create_xml_string()); - }//end update_config_file() - //========================================================================= -} - -?> Modified: trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA4.php =================================================================== --- trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA4.php 2008-03-28 05:16:39 UTC (rev 857) +++ trunk/1.2/upgrade/upgradeTo1.2.0-ALPHA4.php 2008-03-30 04:08:45 UTC (rev 858) @@ -1,10 +1,6 @@ <?php -/* - * Created on February 08, 2008 - */ - -class upgrade_to_1_2_0_ALPHA3 extends dbAbstract { +class upgrade_to_1_2_0_ALPHA4 extends dbAbstract { private $logsObj; @@ -27,8 +23,16 @@ //========================================================================= public function run_upgrade() { + $this->db->beginTrans(__METHOD__); + + + $this->run_schema_changes(); + $this->update_tag_icons(); $this->update_config_file(); + + $this->db->commitTrans(__METHOD__); + return('Upgrade complete'); }//end run_upgrade() //========================================================================= @@ -36,35 +40,102 @@ //========================================================================= + private function run_schema_changes() { + + $this->gfObj->debug_print(__METHOD__ .": running SQL file..."); + $this->run_sql_file(dirname(__FILE__) .'/../docs/sql/upgrades/upgradeTo1.2.0-ALPHA2.sql'); + + $details = "Executed SQL file, '". $this->lastSQLFile ."'. Encoded contents::: ". + base64_encode($this->fsObj->read($this->lastSQLFile)); + $this->logsObj->log_by_class($details, 'system'); + }//end run_schema_changes() + //========================================================================= + + + + //========================================================================= + private function update_tag_icons() { + + $sql = "SELECT tag_name_id, name, icon_name FROM tag_name_table ORDER BY tag_name_id"; + if($this->run_sql($sql) && $this->lastNumrows > 1) { + $allTags = $this->db->farray_fieldnames('name', 'tag_name_id'); + + $iconMods = array( + 'critical' => 'red_x', + 'bug' => 'bug', + 'feature request' => 'feature_request', + 'committed' => 'check_red', + 'verified' => 'check_yellow', + 'released' => 'check_green' + ); + + $updates = 0; + foreach($iconMods as $name=>$icon) { + if(isset($allTags[$name])) { + //update. + $sql = "UPDATE tag_name_table SET icon_name='". $icon ."' WHERE tag_name_id=". $allTags[$name]['tag_name_id']; + } + else { + //insert. + $sql = "INSERT INTO tag_name_table (name, icon_name) VALUES ('". $name ."', '". $icon ."');"; + } + $this->run_sql($sql); + $updates += $this->lastNumrows; + } + } + else { + throw new exception(__METHOD__ .": failed to retrieve tag names"); + } + + }//end update_tag_modifiers() + //========================================================================= + + + + //========================================================================= public function update_config_file() { $fs = new cs_fileSystemClass(dirname(__FILE__) .'/../'); + $sampleXmlObj = new XMLParser($fs->read('docs/samples/sample_config.xml')); + $siteXmlObj = new XMLParser($fs->read(CONFIG_FILE_LOCATION)); - $configFileContents = $fs->read(CONFIG_FILE_LOCATION); + $updateXml = new xmlCreator(); + $updateXml->load_xmlparser_data($siteXmlObj); - //TODO: test that /rw is readable & writable - //TODO: write to new config file location - //TODO: delete old config file - /* - * PROBLEMS WITH MOVING THE CONFIG FILE: - * 1.) upgrades currently won't survive (through multiple version updates) - * if the config location changes, since it is statically set. - * - * 2.) upgrades from 1.1 MUST be able to work automatically. - * - * 3.) upgrades MUST BE SURVIVABLE through multiple version changes (see #1) - * - * SOLUTION: - * - * TODO: add "trigger" to check for old config file; if old config exists, bypass setup & go to upgrade. - * TODO: remove support for pre-alpha4 installs - * TODO: consolidate pre-alpha4 changes into alpha4 upgrade - * TODO: warn existing developers of changes and how to manually upgrade (update to r{x}, let setup run, update db + VERSION file) - * - * NOTE: while it might cause headaches for one or two developers, this - * minimizes pain for users upgrading from previous versions. Yay. - */ + //BACKUP ORIGINAL XML CONFIG... + $backupFile = 'lib/__BACKUP__'. time() .'__'. CONFIG_FILENAME; + $fs->create_file($backupFile); + $fs->openFile($backupFile); + $fs->write($updateXml->create_xml_string()); + $sampleIndexes = $sampleXmlObj->get_tree(TRUE); + $sampleIndexes = $sampleIndexes['CONFIG']; + + $siteConfigIndexes = $siteXmlObj->get_tree(TRUE); + $siteConfigIndexes = $siteConfigIndexes['CONFIG']; + + foreach($sampleIndexes as $indexName=>$indexValue) { + $path = '/CONFIG/'. $indexName; + $attributes = $sampleXmlObj->get_attribute($path); + #debug_print(__METHOD__ .": attributes from sample (/CONFIG/". $indexName ."::: ",1); + #debug_print($attributes,1); + debug_print(__METHOD__ .': indexName=('. $indexName .'), indexValue=('. $indexValue .'), original config value=('. $siteConfigIndexes[$indexName] .')'); + + //add tag if it's not there, update values otherwise. + $tagValue = $attributes['DEFAULT']; + if(isset($siteConfigIndexes[$indexName])) { + $tagValue = $siteConfigIndexes[$indexName]; + } + elseif($indexName == 'PHPMAILER_HOST' && isset($siteConfigIndexes['CONFIG_EMAIL_SERVER_IP'])) { + $tagValue = $siteConfigIndexes['CONFIG_EMAIL_SERVER_IP']; + $updateXml->remove_path('/CONFIG/CONFIG_EMAIL_SERVER_IP'); + } + $updateXml->add_tag($path, $tagValue, $attributes); + } + + $this->gfObj->debug_print($this->gfObj->cleanString($updateXml->create_xml_string(), 'htmlentity_plus_brackets')); + $fs->openFile(CONFIG_FILE_LOCATION); + $fs->write($updateXml->create_xml_string()); }//end update_config_file() //========================================================================= } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |