Thread: [Cs-webdbupgrade-commits] SF.net SVN: cs-webdbupgrade:[11] trunk/0.1/cs_webdbupgrade.class.php
Status: Inactive
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-07-14 21:32:35
|
Revision: 11
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=11&view=rev
Author: crazedsanity
Date: 2009-07-14 21:32:27 +0000 (Tue, 14 Jul 2009)
Log Message:
-----------
Load the initial version string properly.
NOTE::: the current system assumes cs_webdblogger is being setup & used; that
may not always be the case... also, keep in mind that this will ALWAYS assume
that if there is no existing version table, then the current version will be
set in the database and no upgrades will be attempted.
/cs_webdbupgrade.class.php:
* check_versions():
-- read the version file BEFORE checking database version, so the
initial version can be loaded properly.
* read_version_file():
-- use preg_match_all() to simplify matching and to remove the
requirement that version string be on line 2 (now it can be almost
anywhere).
-- set internal projectName similar to setting versionFileVersion.
* parse_version_string():
-- rip off the suffix immediately (if it exists)
-- handle non-existent version_maintenance index
-- always add version_suffix
* fix_xml_config():
-- remove commented-out debugging code.
* load_table():
-- set the initial version information and log that fact.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-14 20:37:21 UTC (rev 10)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-14 21:32:27 UTC (rev 11)
@@ -135,8 +135,8 @@
}
else {
//okay, all files present: check the version in the VERSION file.
+ $versionFileVersion = $this->read_version_file();
$dbVersion = $this->get_database_version();
- $versionFileVersion = $this->read_version_file();
$versionsDiffer = TRUE;
$retval = FALSE;
@@ -169,15 +169,24 @@
$retval = NULL;
//okay, all files present: check the version in the VERSION file.
- $versionFileContents = $this->fsObj->read('VERSION');
+ $versionFileContents = $this->fsObj->read($this->versionFileLocation);
- //okay, rip it into bits. NOTE: this *depends* on "VERSION: " being on the third line.
- $lines = explode("\n", $versionFileContents);
- $versionLine = $lines[2];
- if(preg_match('/^VERSION: /', $versionLine)) {
+
+ $versionMatches = array();
+ preg_match_all('/\nVERSION: (.*)\n/', $versionFileContents, $versionMatches);
+ if(count($versionMatches) == 2 && count($versionMatches[1]) == 1) {
+ $retval = trim($versionMatches[1][0]);
+ $this->versionFileVersion = $retval;
- $retval = trim(preg_replace('/VERSION: /', '', $versionLine));
- $this->versionFileVersion = $retval;
+ //now retrieve the PROJECT name.
+ $projectMatches = array();
+ preg_match_all('/\nPROJECT: (.*)\n/', $versionFileContents, $projectMatches);
+ if(count($projectMatches) == 2 && count($projectMatches[1]) == 1) {
+ $this->projectName = trim($projectMatches[1][0]);
+ }
+ else {
+ throw new exception(__METHOD__ .": failed to find PROJECT name");
+ }
}
else {
throw new exception(__METHOD__ .": could not find VERSION data");
@@ -298,51 +307,31 @@
if(is_null($versionString) || !strlen($versionString)) {
throw new exception(__METHOD__ .": invalid version string ($versionString)");
}
- $tmp = explode('.', $versionString);
- //NOTE: the order of the array MUST be major, then minor, then maintenance, so is_higher_version() can check it easily.
- $retval = array(
- 'version_string' => $versionString,
- 'version_major' => $tmp[0],
- 'version_minor' => $tmp[1]
- );
- if(count($tmp) == 3) {
- $retval['version_maintenance'] = $tmp[2];
+ $suffix = "";
+ if(preg_match('/-[A-Z]{2,5}[0-9]{1,}/', $versionString)) {
+ $bits = explode('-', $versionString);
+ $suffix = $bits[1];
+ $versionString = $bits[0];
}
- else {
- $retval['version_maintenance'] = "0";
- }
+ $tmp = explode('.', $versionString);
- //check for a prefix or a suffix.
- if(preg_match('/-/', $versionString)) {
- //make sure there's only ONE dash.
- $tmp = explode('-', $versionString);
- if(count($tmp) == 2) {
- if(preg_match('/-/', $retval['version_major'])) {
- //example: BETA-3.3.0
-
- throw new exception(__METHOD__ .": versions that contain prefixes cannot be upgraded");
-
- #$tmp = explode('-', $retval['version_major']);
- #$retval['version_major'] = $tmp[1];
- #$retval['prefix'] = $tmp[0];
- }
- elseif(preg_match('/-/', $retval['version_maintenance'])) {
- //example: 1.0.0-ALPHA1
- $tmp = explode('-', $retval['version_maintenance']);
- $retval['version_maintenance'] = $tmp[0];
- $retval['version_suffix'] = $tmp[1];
- }
- else {
- throw new exception(__METHOD__ .": invalid location of prefix/suffix in (". $versionString .")");
- }
+
+ if(is_numeric($tmp[0]) && is_numeric($tmp[1])) {
+ $retval = array(
+ 'version_string' => $versionString,
+ 'version_major' => $tmp[0],
+ 'version_minor' => $tmp[1],
+ );
+ if(isset($tmp[2])) {
+ $retval['version_maintenance'] = $tmp[2];
}
else {
- throw new exception(__METHOD__ .": too many dashes in version string (". $versionString .")");
+ $retval['version_maintenance'] = 0;
}
}
else {
- $retval['version_suffix'] = "";
+ throw new exception(__METHOD__ .": invalid version string format, requires MAJOR.MINOR syntax (". $versionString .")");
}
return($retval);
@@ -956,9 +945,6 @@
$oldData = $myA2p->get_data();
$myA2p->set_data($path, $val);
$this->tempXmlConfig = $myA2p->get_data();
- #$this->gfObj->debug_print(__METHOD__ .": set data, path=(". $path ."), val=(". $val ."), current data::: " .
- # $this->gfObj->debug_print($myA2p->get_data(),0) .", OLD DATA::: " .
- # $this->gfObj->debug_print($oldData,0));
}
else {
throw new exception(__METHOD__ .": invalid type (". $myData['type'] .")");
@@ -992,6 +978,20 @@
$loadTableResult = true;
$logRes = 'Successfully loaded ';
$logType = 'initialize';
+
+ //now set the initial version information...
+ if(strlen($this->projectName) && strlen($this->versionFileVersion)) {
+ $insertData = $this->parse_version_string($this->versionFileVersion);
+ $insertData['project_name'] = $this->projectName;
+
+ $sql = 'INSERT INTO '. $this->config['DB_TABLE'] . $this->gfObj->string_from_array($insertData, 'insert');
+ if($this->db->run_insert($sql)) {
+ $this->logsObj->log_by_class('Created initial version info ('. $insertData['version_string'] .')', $logType);
+ }
+ else {
+ $this->logsObj->log_by_class('Failed to create version info ('. $insertData['version_string'] .')', 'error');
+ }
+ }
}
else {
$logRes = 'Failed to load ';
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-15 20:25:19
|
Revision: 13
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=13&view=rev
Author: crazedsanity
Date: 2009-07-15 20:25:11 +0000 (Wed, 15 Jul 2009)
Log Message:
-----------
Fix version-only upgrades.
/cs_webdbupgrade.class.php:
* do_single_upgrade():
-- comments for which is version-only and which is scripted.
-- remove some debugging statements.
-- set newVersion before updating database version (so the check
called from update_database_version() succeeds).
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-15 19:01:11 UTC (rev 12)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-15 20:25:11 UTC (rev 13)
@@ -479,16 +479,12 @@
$versionIndex = "V". $this->get_full_version_string($targetVersion);
$this->gfObj->debug_print(__METHOD__ .": versionIndex=(". $versionIndex ."), config MATCHING::: ". $this->gfObj->debug_print($this->config['UPGRADELIST']['MATCHING'],0));
if(!isset($this->config['UPGRADELIST']['MATCHING'][$versionIndex])) {
- $this->gfObj->debug_print(__METHOD__ .": doing version-only upgrade...");
-
- $this->gfObj->debug_print($this->config['UPGRADELIST']['MATCHING']);
- exit;
//version-only upgrade.
- $this->update_database_version($this->versionFileVersion);
$this->newVersion = $this->versionFileVersion;
+ $this->update_database_version($this->versionFileVersion);
}
else {
- $this->gfObj->debug_print(__METHOD__ .": doing scripted upgrade...");
+ //scripted upgrade...
$scriptIndex = $versionIndex;
$upgradeData = $this->config['UPGRADELIST']['MATCHING'][$versionIndex];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-16 18:46:51
|
Revision: 14
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=14&view=rev
Author: crazedsanity
Date: 2009-07-16 18:46:43 +0000 (Thu, 16 Jul 2009)
Log Message:
-----------
Remove debug printing when upgrade runs, more logging.
/cs_webdbupgrade.class.php:
* __construct():
-- check if DEBUGPRINTOPT is a defined constant before using it.
-- use constant() when getting value of DEBUGPRINTOPT constant to
avoid PHP warnings/notices.
* perform_upgrade():
-- log stuff as debug instead of debug_print()ing.
* check_for_version_conflict():
-- log a debugging message instead of using debug_print()
* do_single_upgrade():
-- remove debug printing
-- log completion of the upgrade.
* update_database_version():
-- remove some debug printing
* check_database_version():
-- remove debug printing of data
-- log version check failure as FATAL
* do_scripted_upgrade():
-- log when the script is about to start
-- log when the script is done.
* is_higher_version():
-- log a debug message if the new version looks lower than current
-- remove TONS of possible debug printing.
-- log if target version has a suffix & current doesn't (i.e.
'upgrading' from 1.0.0 to 1.0.0-BETA1).
* get_upgrade_list():
-- log a warning when it encounters an odd entry (this is most often
a problem with the XML file's format... there is probably a better way
to explain the problem, but I don't know what that would be right now:
this error is incredibly rare in my experience).
-- log debug message about skipping an entry.
-- remove a very unuseful debug message
-- log debug message for no intermediary version upgrades.
* fix_xml_config():
-- log the cs_arrayToPath{} exceptions before throwing them (again)
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-15 20:25:11 UTC (rev 13)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-16 18:46:43 UTC (rev 14)
@@ -99,7 +99,9 @@
$this->fsObj = new cs_fileSystem(constant('SITE_ROOT'));
$this->gfObj = new cs_globalFunctions;
- $this->gfObj->debugPrintOpt = DEBUGPRINTOPT;
+ if(defined('DEBUGPRINTOPT')) {
+ $this->gfObj->debugPrintOpt = constant('DEBUGPRINTOPT');
+ }
if(!defined('DBTYPE')) {
throw new exception(__METHOD__ .": required constant 'DBTYPE' not set");
@@ -260,7 +262,7 @@
throw new exception(__METHOD__ .": failed to set 'upgrade in progress'");
}
else {
- $this->gfObj->debug_print(__METHOD__ .": result of setting 'upgrade in progress': (". $lockConfig .")");
+ $this->logsObj->log_by_class(__METHOD__ .": result of creating lockfile: (". $lockConfig .")", 'debug');
//push data into our internal "config" array.
$this->read_upgrade_config_file();
@@ -272,7 +274,7 @@
$upgradeList = $this->get_upgrade_list();
$i=0;
- $this->gfObj->debug_print(__METHOD__ .": starting to run through the upgrade list, starting at (". $this->databaseVersion .")...");
+ $this->logsObj->log_by_class(__METHOD__ .": starting to run through the upgrade list, starting at (". $this->databaseVersion .")...", 'debug');
$this->db->beginTrans(__METHOD__);
foreach($upgradeList as $fromVersion=>$toVersion) {
@@ -284,12 +286,11 @@
$i++;
$details = __METHOD__ .": finished upgrade #". $i .", now at version (". $this->databaseVersion .")";
- $this->gfObj->debug_print($details);
$this->logsObj->log_by_class($details, 'system');
}
if($this->databaseVersion == $this->versionFileVersion) {
- $this->gfObj->debug_print(__METHOD__ .": finished upgrading after performing (". $i .") upgrades!!!");
+ $this->logsObj->log_by_class(__METHOD__ .": finished upgrading after performing (". $i .") upgrades", 'debug');
$this->newVersion = $this->databaseVersion;
}
else {
@@ -421,8 +422,7 @@
}
if($retval !== false) {
- $this->logsObj->log_by_class('Upgrading '. $retval .', db version is ('. $dbVersion['version_string'] .'), versionFile is ('. $versionFileData['version_string'] .')', 'DEBUG');
- $this->gfObj->debug_print(__METHOD__ .": upgrading ". $retval ." versions, from (". $this->databaseVersion .") to (". $this->versionFileVersion .")");
+ $this->logsObj->log_by_class("Upgrading ". $retval ." versions, from (". $this->databaseVersion .") to (". $this->versionFileVersion .")", 'debug');
}
return($retval);
@@ -477,7 +477,6 @@
private function do_single_upgrade($targetVersion) {
//Use the "matching_syntax" data in the upgrade.xml file to determine the filename.
$versionIndex = "V". $this->get_full_version_string($targetVersion);
- $this->gfObj->debug_print(__METHOD__ .": versionIndex=(". $versionIndex ."), config MATCHING::: ". $this->gfObj->debug_print($this->config['UPGRADELIST']['MATCHING'],0));
if(!isset($this->config['UPGRADELIST']['MATCHING'][$versionIndex])) {
//version-only upgrade.
$this->newVersion = $this->versionFileVersion;
@@ -504,7 +503,7 @@
throw new exception(__METHOD__ .": target version not specified, unable to proceed with upgrade for ". $versionIndex);
}
}
- $this->gfObj->debug_print(__METHOD__ .": done... ");
+ $this->logsObj->log_by_class("Finished upgrade to ". $targetVersion);
}//end do_single_upgrade()
//=========================================================================
@@ -516,7 +515,6 @@
* so the version there is consistent with all the others.
*/
protected function update_database_version($newVersionString) {
- $this->gfObj->debug_print(__METHOD__ .": setting (". $newVersionString .")");
$versionArr = $this->parse_version_string($newVersionString);
$queryArr = array();
@@ -569,8 +567,7 @@
}
if(!$retval) {
- $this->gfObj->debug_print($data);
- $this->gfObj->debug_print(__METHOD__ .": versionString=(". $versionString ."), checkVersion=(". $this->newVersion .")");
+ $this->logsObj->log_by_class("Version check failed, versionString=(". $versionString ."), checkVersion=(". $this->newVersion .")", 'FATAL');
}
}
@@ -588,7 +585,7 @@
private function do_scripted_upgrade(array $upgradeData) {
$myConfigFile = $upgradeData['SCRIPT_NAME'];
- $this->gfObj->debug_print(__METHOD__ .": script name=(". $myConfigFile .")");
+ $this->logsObj->log_by_class("Preparing to run script '". $myConfigFile ."'", 'debug');
//we've got the filename, see if it exists.
if(isset($this->config['UPGRADE_SCRIPTS_DIR'])) {
@@ -619,7 +616,7 @@
else {
throw new exception(__METHOD__ .": upgrade failed (". $upgradeResult .")");
}
- $this->gfObj->debug_print(__METHOD__ .": finished running ". $createClassName ."::". $classUpgradeMethod ."(), result was (". $upgradeResult .")");
+ $this->logsObj->log_by_class("Finished running ". $createClassName ."::". $classUpgradeMethod ."(), result was (". $upgradeResult .")", 'debug');
}
else {
throw new exception(__METHOD__ .": upgrade method doesn't exist (". $createClassName ."::". $classUpgradeMethod
@@ -677,7 +674,7 @@
}
else {
//TODO: should there maybe be an option to throw an exception (freak out) here?
- debug_print(__METHOD__ .": while checking ". $index .", realized the new version (". $checkIfHigher .") is LOWER than current (". $version .")",1);
+ $this->logsObj->log_by_class(__METHOD__ .": while checking ". $index .", realized the new version (". $checkIfHigher .") is LOWER than current (". $version .")",'debug');
}
}
else {
@@ -697,7 +694,6 @@
// Also: (1.0.0-BETA3 to 1.0.0-BETA4) is okay, but (1.0.0-BETA4 to 1.0.0-BETA3) is NOT.
if(strlen($curVersionSuffix) && strlen($checkVersionSuffix) && $curVersionSuffix == $checkVersionSuffix) {
//matching suffixes.
- $this->gfObj->debug_print(__METHOD__ .": suffixes match");
}
elseif(strlen($curVersionSuffix) || strlen($checkVersionSuffix)) {
//we know the suffixes are there and DO match.
@@ -707,19 +703,15 @@
$checkVersionData = $this->parse_suffix($checkVersionSuffix);
if($curVersionData['type'] == $checkVersionData['type']) {
- $this->gfObj->debug_print(__METHOD__ .": got the same type...");
//got the same suffix type (like "BETA"), check the number.
if($checkVersionData['number'] > $curVersionData['number']) {
- $this->gfObj->debug_print(__METHOD__ .": new version's suffix number higher than current... ");
$retval = TRUE;
}
elseif($checkVersionData['number'] == $curVersionData['number']) {
- $this->gfObj->debug_print(__METHOD__ .": new version's suffix number is EQUAL TO current... ");
$retval = FALSE;
}
else {
//umm... they're identical??? LOGIC HAS FAILED ME ALTOGETHER!!!
- $this->gfObj->debug_print(__METHOD__ .": new version's suffix number is LESS THAN current... ");
$retval = FALSE;
}
}
@@ -729,9 +721,6 @@
if($suffixValues[$checkVersionData['type']] > $suffixValues[$curVersionData['type']]) {
$retval = TRUE;
}
- else {
- $this->gfObj->debug_print(__METHOD__ .": current suffix type is higher... ");
- }
}
}
@@ -741,17 +730,12 @@
}
elseif(!strlen($curVersionSuffix) && strlen($checkVersionSuffix)) {
//i.e. "1.0.0" to "1.0.0-BETA1" --->>> NOT ACCEPTABLE!
- $this->gfObj->debug_print(__METHOD__ .": from (". $version .") to (". $checkIfHigher .") isn't acceptable...?");
+ $this->logsObj->log_by_class(__METHOD__ .": from (". $version .") to (". $checkIfHigher .") isn't acceptable...?", 'debug');
}
}
- else {
- $this->gfObj->debug_print(__METHOD__ .": no suffix to care about");
- }
}
}
- $this->gfObj->debug_print(__METHOD__ .": ('". $version ."', '". $checkIfHigher ."') retval=(". $retval .")", 1);
-
return($retval);
}//end is_higher_version()
@@ -798,22 +782,21 @@
$retval[$matchVersion] = $data['TARGET_VERSION'];
}
else {
- $this->gfObj->debug_print(__METHOD__ .": entry in upgrade.xml (". $matchVersion .") is higher than the VERSION file (". $this->versionFileVersion .")");
+ $this->logsObj->log_by_class(__METHOD__ .": entry in upgrade.xml (". $matchVersion .") is higher than the VERSION file (". $this->versionFileVersion .")", 'warning');
}
}
else {
- $this->gfObj->debug_print(__METHOD__ .": SKIPPING (". $matchVersion .")");
+ $this->logsObj->log_by_class(__METHOD__ .": SKIPPING (". $matchVersion .")", 'debug');
}
}
if($lastVersion !== $newVersion && (!isset($retval[$lastVersion]) || $retval[$lastVersion] != $newVersion)) {
- $this->gfObj->debug_print(__METHOD__ .": <b>ALSO (". $lastVersion .") => (". $newVersion .")</b>");
$retval[$lastVersion] = $newVersion;
}
}
else {
//no intermediary upgrades: just pass back the latest version.
- $this->gfObj->debug_print(__METHOD__ .": no intermediary upgrades");
+ $this->logsObj->log_by_class(__METHOD__ .": no intermediary upgrades", 'debug');
$retval[$dbVersion] = $this->versionFileVersion;
}
@@ -868,8 +851,8 @@
$a2p = new cs_arrayToPath($config);
}
catch(exception $e) {
- $this->gfObj->debug_print($config);
- exit("died on #1");
+ $this->logsObj->log_by_class(__METHOD__ .': encountered exception: '. $e->getMessage());
+ throw new exception($e->getMessage());
}
if(!is_array($this->tempXmlConfig)) {
$this->tempXmlConfig = array();
@@ -878,8 +861,8 @@
$myA2p = new cs_arrayToPath(&$this->tempXmlConfig);
}
catch(exception $e) {
-
- exit("died on #2");
+ $this->logsObj->log_by_class(__METHOD__ .': encountered exception: '. $e->getMessage());
+ throw new exception($e->getMessage());
}
$myData = $a2p->get_data($path);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-16 18:55:13
|
Revision: 15
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=15&view=rev
Author: crazedsanity
Date: 2009-07-16 18:55:06 +0000 (Thu, 16 Jul 2009)
Log Message:
-----------
Removed some missed debug printing.
/cs_webdbupgrade.class.php:
* perform_upgrade():
-- remove debug_print on details (they're logged)
* is_higher_version():
-- remove debug_print about checking suffixes.
* get_upgrade_list():
-- remove debug_print about adding an entry from the MATCHING array.
* fix_xml_config():
-- remove commented-out debug print.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-16 18:46:43 UTC (rev 14)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-16 18:55:06 UTC (rev 15)
@@ -279,7 +279,6 @@
foreach($upgradeList as $fromVersion=>$toVersion) {
$details = __METHOD__ .": upgrading from ". $fromVersion ." to ". $toVersion ."... ";
- $this->gfObj->debug_print($details);
$this->logsObj->log_by_class($details, 'system');
$this->do_single_upgrade($fromVersion);
$this->get_database_version();
@@ -687,7 +686,6 @@
// the "$checkIfHigher" is actually higher, don't bother (i.e. suffixes don't matter when
// we already know there's a major, minor, or maintenance version that's also higher.
if($retval === FALSE) {
- $this->gfObj->debug_print(__METHOD__ .": checking suffixes... ");
//EXAMPLE: $version="1.0.0-BETA3", $checkIfHigher="1.1.0"
// Moving from a non-suffixed version to a suffixed version isn't supported, but the inverse is:
// i.e. (1.0.0-BETA3 to 1.0.0) is okay, but (1.0.0 to 1.0.0-BETA3) is NOT.
@@ -777,7 +775,6 @@
$retval[$this->databaseVersion] = $matchVersion;
}
//the MATCHING version is NOT higher than the version file's version, looks ok.
- $this->gfObj->debug_print(__METHOD__ .": adding (". $matchVersion .")");
$lastVersion = $data['TARGET_VERSION'];
$retval[$matchVersion] = $data['TARGET_VERSION'];
}
@@ -841,7 +838,6 @@
//=========================================================================
private function fix_xml_config($config, $path=null) {
- #$this->gfObj->debug_print(__METHOD__ .": path=(". $path ."):: ". $this->gfObj->debug_print($config,0));
$this->xmlLoops++;
if($this->xmlLoops > 1000) {
throw new exception(__METHOD__ .": infinite loop detected...");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-24 14:55:23
|
Revision: 16
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=16&view=rev
Author: crazedsanity
Date: 2009-07-24 14:55:09 +0000 (Fri, 24 Jul 2009)
Log Message:
-----------
Convert most exceptions to call error_handler() for logging.
/cs_webdbUpgrade.class.php:
* __construct():
-- only things happening AFTER database connection throw an exception.
* error_handler() [NEW]:
-- logs the details of the exception before throwing it.
* METHODS CHANGED TO CALL error_handler():
-- read_version_file()
-- read_upgrade_config_file()
-- perform_upgrade()
-- upgrade_in_progress()
-- parse_version_string()
-- check_for_version_conflict()
-- get_database_version()
-- do_single_upgrade()
-- update_database_version()
-- check_database_version()
-- do_scripted_upgrade()
-- is_higher_version()
-- get_upgrade_list()
-- parse_suffix()
-- fix_xml_config()
-- create_lockfile()
-- remove_lockfile()
-- get_full_version_string()
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-16 18:55:06 UTC (rev 15)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-24 14:55:09 UTC (rev 16)
@@ -128,7 +128,7 @@
if($this->check_lockfile()) {
//there is an existing lockfile...
- throw new exception(__METHOD__ .": upgrade in progress: ". $this->fsObj->read($this->lockfile));
+ $this->error_handler(__METHOD__ .": upgrade in progress: ". $this->fsObj->read($this->lockfile));
}
$this->check_versions(false);
@@ -208,11 +208,11 @@
$this->projectName = trim($projectMatches[1][0]);
}
else {
- throw new exception(__METHOD__ .": failed to find PROJECT name");
+ $this->error_handler(__METHOD__ .": failed to find PROJECT name");
}
}
else {
- throw new exception(__METHOD__ .": could not find VERSION data");
+ $this->error_handler(__METHOD__ .": could not find VERSION data");
}
return($retval);
@@ -237,7 +237,7 @@
$this->config['UPGRADELIST'] = $config['UPGRADE'];
}
else {
- throw new exception(__METHOD__ .": failed to retrieve 'UPGRADE' section; " .
+ $this->error_handler(__METHOD__ .": failed to retrieve 'UPGRADE' section; " .
"make sure upgrade.xml's ROOT element is 'UPGRADE'");
}
}//end read_upgrade_config_file()
@@ -250,7 +250,7 @@
//make sure there's not already a lockfile.
if($this->upgrade_in_progress()) {
//ew. Can't upgrade.
- throw new exception(__METHOD__ .": upgrade already in progress...????");
+ $this->error_handler(__METHOD__ .": upgrade already in progress...????");
}
else {
$lockConfig = $this->upgrade_in_progress(TRUE);
@@ -259,7 +259,7 @@
//TODO: not only should the "create_file()" method be run, but also do a sanity check by calling lock_file_exists().
if($lockConfig === 0) {
//can't create the lockfile. Die.
- throw new exception(__METHOD__ .": failed to set 'upgrade in progress'");
+ $this->error_handler(__METHOD__ .": failed to set 'upgrade in progress'");
}
else {
$this->logsObj->log_by_class(__METHOD__ .": result of creating lockfile: (". $lockConfig .")", 'debug');
@@ -293,7 +293,7 @@
$this->newVersion = $this->databaseVersion;
}
else {
- throw new exception(__METHOD__ .": finished upgrade, but version wasn't updated (expecting '". $this->versionFileVersion ."', got '". $this->databaseVersion ."')!!!");
+ $this->error_handler(__METHOD__ .": finished upgrade, but version wasn't updated (expecting '". $this->versionFileVersion ."', got '". $this->databaseVersion ."')!!!");
}
$this->remove_lockfile();
@@ -327,7 +327,7 @@
//=========================================================================
public function parse_version_string($versionString) {
if(is_null($versionString) || !strlen($versionString)) {
- throw new exception(__METHOD__ .": invalid version string ($versionString)");
+ $this->error_handler(__METHOD__ .": invalid version string ($versionString)");
}
$suffix = "";
@@ -356,7 +356,7 @@
$retval['version_suffix'] = $suffix;
}
else {
- throw new exception(__METHOD__ .": invalid version string format, requires MAJOR.MINOR syntax (". $versionString .")");
+ $this->error_handler(__METHOD__ .": invalid version string format, requires MAJOR.MINOR syntax (". $versionString .")");
}
return($retval);
@@ -392,7 +392,7 @@
if($versionFileData['version_minor'] == $dbVersion['version_minor']) {
if($versionFileData['version_maintenance'] == $dbVersion['version_maintenance']) {
if($versionFileData['version_suffix'] == $dbVersion['version_suffix']) {
- throw new exception(__METHOD__ .": no version upgrade detected, but version strings don't match (versionFile=". $versionFileData['version_string'] .", dbVersion=". $dbVersion['version_string'] .")");
+ $this->error_handler(__METHOD__ .": no version upgrade detected, but version strings don't match (versionFile=". $versionFileData['version_string'] .", dbVersion=". $dbVersion['version_string'] .")");
}
else {
$retval = "suffix";
@@ -402,21 +402,21 @@
$retval = "maintenance";
}
else {
- throw new exception(__METHOD__ .": downgrading from maintenance versions is unsupported");
+ $this->error_handler(__METHOD__ .": downgrading from maintenance versions is unsupported");
}
}
elseif($versionFileData['version_minor'] > $dbVersion['version_minor']) {
$retval = "minor";
}
else {
- throw new exception(__METHOD__ .": downgrading minor versions is unsupported");
+ $this->error_handler(__METHOD__ .": downgrading minor versions is unsupported");
}
}
elseif($versionFileData['version_major'] > $dbVersion['version_major']) {
$retval = "major";
}
else {
- throw new exception(__METHOD__ .": downgrading major versions is unsupported");
+ $this->error_handler(__METHOD__ .": downgrading major versions is unsupported");
}
}
@@ -452,12 +452,12 @@
$dberror = $this->db->errorMsg();
}
else {
- throw new exception(__METHOD__ .": no table in database, failed to create one... ORIGINAL " .
+ $this->error_handler(__METHOD__ .": no table in database, failed to create one... ORIGINAL " .
"ERROR: ". $dberror .", SCHEMA LOAD ERROR::: ". $loadTableResult);
}
}
else {
- throw new exception(__METHOD__ .": failed to retrieve version... numrows=(". $numrows ."), DBERROR::: ". $dberror);
+ $this->error_handler(__METHOD__ .": failed to retrieve version... numrows=(". $numrows ."), DBERROR::: ". $dberror);
}
}
else {
@@ -495,11 +495,11 @@
$this->update_database_version($upgradeData['TARGET_VERSION']);
}
else {
- throw new exception(__METHOD__ .": not enough information to run scripted upgrade for ". $versionIndex);
+ $this->error_handler(__METHOD__ .": not enough information to run scripted upgrade for ". $versionIndex);
}
}
else {
- throw new exception(__METHOD__ .": target version not specified, unable to proceed with upgrade for ". $versionIndex);
+ $this->error_handler(__METHOD__ .": target version not specified, unable to proceed with upgrade for ". $versionIndex);
}
}
$this->logsObj->log_by_class("Finished upgrade to ". $targetVersion);
@@ -532,12 +532,12 @@
$retval = $updateRes;
}
else {
- throw new exception(__METHOD__ .": invalid result (". $updateRes .") ");
+ $this->error_handler(__METHOD__ .": invalid result (". $updateRes .") ");
}
//okay, now check that the version string matches the updated bits.
if(!$this->check_database_version($this->newVersion)) {
- throw new exception(__METHOD__ .": database version information is invalid: (". $this->newVersion .")");
+ $this->error_handler(__METHOD__ .": database version information is invalid: (". $this->newVersion .")");
}
return($retval);
@@ -571,7 +571,7 @@
}
else {
- throw new exception(__METHOD__ .": no version string given (". $this->newVersion .")");
+ $this->error_handler(__METHOD__ .": no version string given (". $this->newVersion .")");
}
return($retval);
@@ -613,21 +613,21 @@
$this->logsObj->log_by_class("Upgrade succeeded (". $upgradeResult .")", 'success');
}
else {
- throw new exception(__METHOD__ .": upgrade failed (". $upgradeResult .")");
+ $this->error_handler(__METHOD__ .": upgrade failed (". $upgradeResult .")");
}
$this->logsObj->log_by_class("Finished running ". $createClassName ."::". $classUpgradeMethod ."(), result was (". $upgradeResult .")", 'debug');
}
else {
- throw new exception(__METHOD__ .": upgrade method doesn't exist (". $createClassName ."::". $classUpgradeMethod
+ $this->error_handler(__METHOD__ .": upgrade method doesn't exist (". $createClassName ."::". $classUpgradeMethod
."), unable to perform upgrade ");
}
}
else {
- throw new exception(__METHOD__ .": unable to locate upgrade class name (". $createClassName .")");
+ $this->error_handler(__METHOD__ .": unable to locate upgrade class name (". $createClassName .")");
}
}
else {
- throw new exception(__METHOD__ .": upgrade filename (". $fileName .") does not exist");
+ $this->error_handler(__METHOD__ .": upgrade filename (". $fileName .") does not exist");
}
}//end do_scripted_upgrade()
//=========================================================================
@@ -638,7 +638,7 @@
protected function is_higher_version($version, $checkIfHigher) {
$retval = FALSE;
if(!is_string($version) || !is_string($checkIfHigher)) {
- throw new exception(__METHOD__ .": didn't get strings... ". debug_print(func_get_args(),0));
+ $this->error_handler(__METHOD__ .": didn't get strings... ". debug_print(func_get_args(),0));
}
elseif($version == $checkIfHigher) {
$retval = FALSE;
@@ -677,7 +677,7 @@
}
}
else {
- throw new exception(__METHOD__ .": ". $index ." is not numeric in one of the strings " .
+ $this->error_handler(__METHOD__ .": ". $index ." is not numeric in one of the strings " .
"(versionNumber=". $versionNumber .", checkThis=". $checkThis .")");
}
}
@@ -757,7 +757,7 @@
$retval = array();
if(!$this->is_higher_version($dbVersion, $newVersion)) {
- throw new exception(__METHOD__ .": version (". $newVersion .") isn't higher than (". $dbVersion .")... something is broken");
+ $this->error_handler(__METHOD__ .": version (". $newVersion .") isn't higher than (". $dbVersion .")... something is broken");
}
elseif(is_array($this->config['MATCHING'])) {
$lastVersion = $dbVersion;
@@ -765,7 +765,7 @@
$matchVersion = preg_replace('/^V/', '', $matchVersion);
if($matchVersion == $data['TARGET_VERSION']) {
- throw new exception(__METHOD__ .": detected invalid TARGET_VERSION in (". $matchVersion ."): make sure TARGET_VERSION is higher than matching!");
+ $this->error_handler(__METHOD__ .": detected invalid TARGET_VERSION in (". $matchVersion ."): make sure TARGET_VERSION is higher than matching!");
}
elseif($this->databaseVersion == $matchVersion || $this->is_higher_version($this->databaseVersion, $matchVersion)) {
//the version in MATCHING is equal to or HIGHER than our database version... make sure it is NOT
@@ -820,14 +820,14 @@
);
}
else {
- throw new exception(__METHOD__ .": invalid suffix (". $suffix .")");
+ $this->error_handler(__METHOD__ .": invalid suffix (". $suffix .")");
}
break;
}
}
}
else {
- throw new exception(__METHOD__ .": invalid suffix (". $suffix .")");
+ $this->error_handler(__METHOD__ .": invalid suffix (". $suffix .")");
}
return($retval);
@@ -840,7 +840,7 @@
private function fix_xml_config($config, $path=null) {
$this->xmlLoops++;
if($this->xmlLoops > 1000) {
- throw new exception(__METHOD__ .": infinite loop detected...");
+ $this->error_handler(__METHOD__ .": infinite loop detected...");
}
try {
@@ -848,7 +848,7 @@
}
catch(exception $e) {
$this->logsObj->log_by_class(__METHOD__ .': encountered exception: '. $e->getMessage());
- throw new exception($e->getMessage());
+ $this->error_handler($e->getMessage());
}
if(!is_array($this->tempXmlConfig)) {
$this->tempXmlConfig = array();
@@ -858,7 +858,7 @@
}
catch(exception $e) {
$this->logsObj->log_by_class(__METHOD__ .': encountered exception: '. $e->getMessage());
- throw new exception($e->getMessage());
+ $this->error_handler($e->getMessage());
}
$myData = $a2p->get_data($path);
@@ -875,7 +875,7 @@
$this->tempXmlConfig = $myA2p->get_data();
}
else {
- throw new exception(__METHOD__ .": invalid type (". $myData['type'] .")");
+ $this->error_handler(__METHOD__ .": invalid type (". $myData['type'] .")");
}
}
else {
@@ -887,7 +887,7 @@
}
}
else {
- throw new exception(__METHOD__ .": unable to fix data on path=(". $path .")::: ". $this->gfObj->debug_print($myData,0));
+ $this->error_handler(__METHOD__ .": unable to fix data on path=(". $path .")::: ". $this->gfObj->debug_print($myData,0));
}
}//end fix_xml_config()
//=========================================================================
@@ -964,15 +964,15 @@
$this->fsObj->closeFile();
}
else {
- throw new exception(__METHOD__ .": failed to write contents (". $contents .") to lockfile");
+ $this->error_handler(__METHOD__ .": failed to write contents (". $contents .") to lockfile");
}
}
else {
- throw new exception(__METHOD__ .": failed to create lockfile (". $this->lockfile .")");
+ $this->error_handler(__METHOD__ .": failed to create lockfile (". $this->lockfile .")");
}
}
else {
- throw new exception(__METHOD__ .": failed to create lockfile, one already exists (". $this->lockfile .")");
+ $this->error_handler(__METHOD__ .": failed to create lockfile, one already exists (". $this->lockfile .")");
}
}//end create_lockfile()
//=========================================================================
@@ -986,11 +986,11 @@
private function remove_lockfile() {
if($this->check_lockfile()) {
if(!$this->fsObj->rm($this->lockfile)) {
- throw new exception(__METHOD__ .": failed to remove lockfile (". $this->lockfile .")");
+ $this->error_handler(__METHOD__ .": failed to remove lockfile (". $this->lockfile .")");
}
}
else {
- throw new exception(__METHOD__ .": no lockfile (". $this->lockfile .")");
+ $this->error_handler(__METHOD__ .": no lockfile (". $this->lockfile .")");
}
}//end remove_lockfile()
//=========================================================================
@@ -1009,7 +1009,7 @@
}
}
else {
- throw new exception(__METHOD__ .": no version string given");
+ $this->error_handler(__METHOD__ .": no version string given");
}
return($fullVersion);
@@ -1017,6 +1017,18 @@
//=========================================================================
+
+ //=========================================================================
+ public function error_handler($details) {
+ //log the error.
+ $this->logsObj->log_by_class($details, 'exception in code');
+
+ //now throw an exception so other code can catch it.
+ throw new exception($details);
+ }//end error_handler()
+ //=========================================================================
+
+
}//end upgrade{}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-27 17:24:36
|
Revision: 17
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=17&view=rev
Author: crazedsanity
Date: 2009-07-27 17:24:28 +0000 (Mon, 27 Jul 2009)
Log Message:
-----------
Added a try/catch block to try to fix MySQL problems (see issue #282)
/cs_webdbupgrade.class.php:
* perform_upgrade():
-- log info from check_for_version_conflict() as 'info'
-- use a try/catch block: commit as normal, rollaback on excpetion.
* check_for_version_conflict():
-- remove logging (avoids dupe entries).
* do_single_upgrade():
-- log the final outcome as 'system' instead of the default 'error'
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-24 14:55:09 UTC (rev 16)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-27 17:24:28 UTC (rev 17)
@@ -269,35 +269,47 @@
$this->get_database_version();
//check for version conflicts.
- $this->check_for_version_conflict();
+ $versionConflictInfo = $this->check_for_version_conflict();
+
+ if($versionConflictInfo !== false) {
+ $this->logsObj->log_by_class("Upgrading ". $versionConflictInfo ." versions, from " .
+ "(". $this->databaseVersion .") to (". $this->versionFileVersion .")", 'info');
+ }
+
$upgradeList = $this->get_upgrade_list();
- $i=0;
- $this->logsObj->log_by_class(__METHOD__ .": starting to run through the upgrade list, starting at (". $this->databaseVersion .")...", 'debug');
- $this->db->beginTrans(__METHOD__);
- foreach($upgradeList as $fromVersion=>$toVersion) {
+ try {
+ $i=0;
+ $this->logsObj->log_by_class(__METHOD__ .": starting to run through the upgrade list, starting at (". $this->databaseVersion .")...", 'debug');
+ $this->db->beginTrans(__METHOD__);
+ foreach($upgradeList as $fromVersion=>$toVersion) {
+
+ $details = __METHOD__ .": upgrading from ". $fromVersion ." to ". $toVersion ."... ";
+ $this->logsObj->log_by_class($details, 'system');
+ $this->do_single_upgrade($fromVersion);
+ $this->get_database_version();
+ $i++;
+
+ $details = __METHOD__ .": finished upgrade #". $i .", now at version (". $this->databaseVersion .")";
+ $this->logsObj->log_by_class($details, 'system');
+ }
- $details = __METHOD__ .": upgrading from ". $fromVersion ." to ". $toVersion ."... ";
- $this->logsObj->log_by_class($details, 'system');
- $this->do_single_upgrade($fromVersion);
- $this->get_database_version();
- $i++;
+ if($this->databaseVersion == $this->versionFileVersion) {
+ $this->logsObj->log_by_class(__METHOD__ .": finished upgrading after performing (". $i .") upgrades", 'debug');
+ $this->newVersion = $this->databaseVersion;
+ }
+ else {
+ $this->error_handler(__METHOD__ .": finished upgrade, but version wasn't updated (expecting '". $this->versionFileVersion ."', got '". $this->databaseVersion ."')!!!");
+ }
+ $this->remove_lockfile();
- $details = __METHOD__ .": finished upgrade #". $i .", now at version (". $this->databaseVersion .")";
- $this->logsObj->log_by_class($details, 'system');
+ $this->db->commitTrans();
}
-
- if($this->databaseVersion == $this->versionFileVersion) {
- $this->logsObj->log_by_class(__METHOD__ .": finished upgrading after performing (". $i .") upgrades", 'debug');
- $this->newVersion = $this->databaseVersion;
+ catch(exception $e) {
+ $this->error_handler(__METHOD__ .": upgrade aborted:::". $e->getMessage());
+ $this->db->rollbackTrans();
}
- else {
- $this->error_handler(__METHOD__ .": finished upgrade, but version wasn't updated (expecting '". $this->versionFileVersion ."', got '". $this->databaseVersion ."')!!!");
- }
- $this->remove_lockfile();
-
- $this->db->commitTrans();
}
}
}//end perform_upgrade()
@@ -420,10 +432,6 @@
}
}
- if($retval !== false) {
- $this->logsObj->log_by_class("Upgrading ". $retval ." versions, from (". $this->databaseVersion .") to (". $this->versionFileVersion .")", 'debug');
- }
-
return($retval);
}//end check_for_version_conflict()
//=========================================================================
@@ -502,7 +510,7 @@
$this->error_handler(__METHOD__ .": target version not specified, unable to proceed with upgrade for ". $versionIndex);
}
}
- $this->logsObj->log_by_class("Finished upgrade to ". $targetVersion);
+ $this->logsObj->log_by_class("Finished upgrade to ". $targetVersion, 'system');
}//end do_single_upgrade()
//=========================================================================
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-27 19:59:51
|
Revision: 19
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=19&view=rev
Author: crazedsanity
Date: 2009-07-27 19:59:41 +0000 (Mon, 27 Jul 2009)
Log Message:
-----------
Fix so multiple inline upgrades work.
/cs_webdbupgrade.class.php:
* perform_upgrade():
-- logs total number of upgrades to be preformed
-- logic for handling multiple upgrades vs. a single.
* do_single_upgrade():
-- log the TARGET_VERSION instead of the matching (old) version.
* get_upgrade_list():
-- use proper index of configuration so multiple inline upgrades work.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-27 17:28:59 UTC (rev 18)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-27 19:59:41 UTC (rev 19)
@@ -281,7 +281,8 @@
try {
$i=0;
- $this->logsObj->log_by_class(__METHOD__ .": starting to run through the upgrade list, starting at (". $this->databaseVersion .")...", 'debug');
+ $this->logsObj->log_by_class(__METHOD__ .": starting to run through the upgrade list, starting at (". $this->databaseVersion ."), " .
+ "total number of upgrades to perform: ". count($upgradeList), 'debug');
$this->db->beginTrans(__METHOD__);
foreach($upgradeList as $fromVersion=>$toVersion) {
@@ -295,12 +296,18 @@
$this->logsObj->log_by_class($details, 'system');
}
- if($this->databaseVersion == $this->versionFileVersion) {
- $this->logsObj->log_by_class(__METHOD__ .": finished upgrading after performing (". $i .") upgrades", 'debug');
- $this->newVersion = $this->databaseVersion;
+ if($i < count($upgradeList)) {
+ $this->logsObj->log_by_class(__METHOD__ .": completed upgrade ". $i ." of ". count($upgradeList), 'debug');
}
else {
- $this->error_handler(__METHOD__ .": finished upgrade, but version wasn't updated (expecting '". $this->versionFileVersion ."', got '". $this->databaseVersion ."')!!!");
+ if($this->databaseVersion == $this->versionFileVersion) {
+ $this->logsObj->log_by_class(__METHOD__ .": finished upgrading after performing (". $i .") upgrades", 'debug');
+ $this->newVersion = $this->databaseVersion;
+ }
+ else {
+ $this->logsObj->log_by_class(__METHOD__ .": upgradeList::: ". $this->gfObj->debug_print($upgradeList,0), 'debug');
+ $this->error_handler(__METHOD__ .": finished upgrade, but version wasn't updated (expecting '". $this->versionFileVersion ."', got '". $this->databaseVersion ."')!!!");
+ }
}
$this->remove_lockfile();
@@ -510,7 +517,7 @@
$this->error_handler(__METHOD__ .": target version not specified, unable to proceed with upgrade for ". $versionIndex);
}
}
- $this->logsObj->log_by_class("Finished upgrade to ". $targetVersion, 'system');
+ $this->logsObj->log_by_class("Finished upgrade to ". $upgradeData['TARGET_VERSION'], 'system');
}//end do_single_upgrade()
//=========================================================================
@@ -767,9 +774,9 @@
if(!$this->is_higher_version($dbVersion, $newVersion)) {
$this->error_handler(__METHOD__ .": version (". $newVersion .") isn't higher than (". $dbVersion .")... something is broken");
}
- elseif(is_array($this->config['MATCHING'])) {
+ elseif(is_array($this->config['UPGRADELIST']['MATCHING'])) {
$lastVersion = $dbVersion;
- foreach($this->config['MATCHING'] as $matchVersion=>$data) {
+ foreach($this->config['UPGRADELIST']['MATCHING'] as $matchVersion=>$data) {
$matchVersion = preg_replace('/^V/', '', $matchVersion);
if($matchVersion == $data['TARGET_VERSION']) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-29 19:14:23
|
Revision: 20
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=20&view=rev
Author: crazedsanity
Date: 2009-07-29 19:14:10 +0000 (Wed, 29 Jul 2009)
Log Message:
-----------
Fix logging of invalid version.
/cs_webdbupgrade.class.php:
* do_single_upgrade():
-- change the version in the log message to be the internal
newVersion var (which always contains the current version: with
multiple inline upgrades, it'll contain whatever version it just
finished upgrading to... as opposed to the target version, final
version, or nothing if the wrong one is used).
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-27 19:59:41 UTC (rev 19)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-29 19:14:10 UTC (rev 20)
@@ -517,7 +517,7 @@
$this->error_handler(__METHOD__ .": target version not specified, unable to proceed with upgrade for ". $versionIndex);
}
}
- $this->logsObj->log_by_class("Finished upgrade to ". $upgradeData['TARGET_VERSION'], 'system');
+ $this->logsObj->log_by_class("Finished upgrade to ". $this->newVersion, 'system');
}//end do_single_upgrade()
//=========================================================================
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-30 16:10:07
|
Revision: 21
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=21&view=rev
Author: crazedsanity
Date: 2009-07-30 16:09:55 +0000 (Thu, 30 Jul 2009)
Log Message:
-----------
Log begin & end, fix for mixed version-only & script upgrades (#285).
/cs_webdbupgrade.class.php:
* perform_upgrade():
-- log the beginning of the upgrade: pulling all records of the
proper category that are GREATER than the last recorded event like
this will show all the information on the latest upgrade.
-- pass "$toVersion" to do_single_upgrade()
-- log end of the upgrade
* do_single_upgrade():
-- ARG CHANGE: RENAMED ARG: #1 (now "$fromVersion")
-- ARG CHANGE: NEW ARG: #2 ($toVersion=null)
-- updated references from $targetVersion to $fromVersion
-- use $toVersion for setting the database version: previously, it
was setting the current version to be the versionFileVersion, which
led directly to causing issue #285 and making backwards-compatibility
a big (though undiscovered) issue. Now it correctly logs the current
version in a >1 upgrade chain, and handles intermediary upgrades
properly. More testing would definitely be prudent.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-29 19:14:10 UTC (rev 20)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-30 16:09:55 UTC (rev 21)
@@ -256,6 +256,8 @@
$lockConfig = $this->upgrade_in_progress(TRUE);
$this->fsObj->cd("/");
+ $this->logsObj->log_by_class("Starting upgrade process...", 'begin');
+
//TODO: not only should the "create_file()" method be run, but also do a sanity check by calling lock_file_exists().
if($lockConfig === 0) {
//can't create the lockfile. Die.
@@ -288,7 +290,7 @@
$details = __METHOD__ .": upgrading from ". $fromVersion ." to ". $toVersion ."... ";
$this->logsObj->log_by_class($details, 'system');
- $this->do_single_upgrade($fromVersion);
+ $this->do_single_upgrade($fromVersion, $toVersion);
$this->get_database_version();
$i++;
@@ -317,6 +319,7 @@
$this->error_handler(__METHOD__ .": upgrade aborted:::". $e->getMessage());
$this->db->rollbackTrans();
}
+ $this->logsObj->log_by_class("Upgrade process complete", 'end');
}
}
}//end perform_upgrade()
@@ -488,13 +491,13 @@
//=========================================================================
- private function do_single_upgrade($targetVersion) {
+ private function do_single_upgrade($fromVersion, $toVersion=null) {
//Use the "matching_syntax" data in the upgrade.xml file to determine the filename.
- $versionIndex = "V". $this->get_full_version_string($targetVersion);
+ $versionIndex = "V". $this->get_full_version_string($fromVersion);
if(!isset($this->config['UPGRADELIST']['MATCHING'][$versionIndex])) {
//version-only upgrade.
- $this->newVersion = $this->versionFileVersion;
- $this->update_database_version($this->versionFileVersion);
+ $this->newVersion = $toVersion;
+ $this->update_database_version($toVersion);
}
else {
//scripted upgrade...
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-07-30 16:19:34
|
Revision: 22
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=22&view=rev
Author: crazedsanity
Date: 2009-07-30 16:19:26 +0000 (Thu, 30 Jul 2009)
Log Message:
-----------
Fix method that checks if an upgrade is in progress.
/cs_webdbupgrade.class.php:
* upgrade_in_progress():
-- remove default value for $retval (overwritten anyway)
-- remove reference to "WORKINGONIT"
-- always returns value from check_lockfile() now.
-- NOTE::: previously this would report FALSE even if a lockfile was
in place; this change makes the system internally consistent.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-30 16:09:55 UTC (rev 21)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-07-30 16:19:26 UTC (rev 22)
@@ -329,16 +329,13 @@
//=========================================================================
public function upgrade_in_progress($makeItSo=FALSE) {
- $retval = FALSE;
if($makeItSo === TRUE) {
$this->get_database_version();
$details = $this->projectName .': Upgrade from '. $this->databaseVersion .' started at '. date('Y-m-d H:i:s');
$this->create_lockfile($details);
$retval = TRUE;
}
- elseif(preg_match('/^upgrade/i', $this->mainConfig['WORKINGONIT'])) {
- $retval = TRUE;
- }
+ $retval = $this->check_lockfile();
return($retval);
}//end upgrade_in_progress()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-08-04 16:38:42
|
Revision: 24
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=24&view=rev
Author: crazedsanity
Date: 2009-08-04 16:38:31 +0000 (Tue, 04 Aug 2009)
Log Message:
-----------
Set initial version when loading table into database.
/cs_webdbupgrade.class.php:
* __construct():
-- use a separate connection for the logger so logs don't disappear
with transactions if they get rolled-back.
* read_upgrade_config_file():
-- catch exceptions from cs_fileSystem{} and wrap its own exception
around it, so the error is easier to debug.
* load_table():
-- call read_upgrade_config_file() to see if there is an
INITIAL_VERSION to use instead of using the standard
versionFileVersion (which potentially skips intermediate updates).
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-08-04 15:40:42 UTC (rev 23)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-08-04 16:38:31 UTC (rev 24)
@@ -128,7 +128,10 @@
$this->db = new cs_phpDB(constant('DBTYPE'));
try {
$this->db->connect($this->config['DBPARAMS']);
- $this->logsObj = new cs_webdblogger($this->db, "Upgrade");
+
+ $loggerDb = new cs_phpDB(constant('DBTYPE'));
+ $loggerDb->connect($this->config['DBPARAMS'], true);
+ $this->logsObj = new cs_webdblogger($loggerDb, "Upgrade");
}
catch(exception $e) {
$this->gfObj->debug_print($this->config,1);
@@ -235,7 +238,12 @@
* Read information from our config file, so we know what to expect.
*/
private function read_upgrade_config_file() {
- $xmlString = $this->fsObj->read($this->config['UPGRADE_CONFIG_FILE']);
+ try {
+ $xmlString = $this->fsObj->read($this->config['UPGRADE_CONFIG_FILE']);
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to read upgrade config file::: ". $e->getMessage());
+ }
//parse the file.
$xmlParser = new cs_phpxmlParser($xmlString);
@@ -934,7 +942,15 @@
//now set the initial version information...
if(strlen($this->projectName) && strlen($this->versionFileVersion)) {
- $insertData = $this->parse_version_string($this->versionFileVersion);
+
+ //if there's an INITIAL_VERSION in the upgrade config file, use that.
+ $this->read_upgrade_config_file();
+ if(isset($this->config['UPGRADELIST']['INITIALVERSION'])) {
+ $insertData = $this->parse_version_string($this->config['UPGRADELIST']['INITIALVERSION']);
+ }
+ else {
+ $insertData = $this->parse_version_string($this->versionFileVersion);
+ }
$insertData['project_name'] = $this->projectName;
$sql = 'INSERT INTO '. $this->config['DB_TABLE'] . $this->gfObj->string_from_array($insertData, 'insert');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-08-04 18:59:34
|
Revision: 25
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=25&view=rev
Author: crazedsanity
Date: 2009-08-04 18:59:26 +0000 (Tue, 04 Aug 2009)
Log Message:
-----------
System loads initial version information into the database for ease of use.
NOTE::: this is an intermediate release. While it technically works, it has
a lot of extra debugging information in it that should not be used on a
production system.
/cs_webdbupgrade.class.php:
* MAIN:::
-- requires (and extends) cs_versionAbstract
-- set $gfObj as protected instead of private, for working with
cs_versionAbstract.
-- new private var, $allowNoDBVersion=true (for handling situations
where get_database_version() would normally throw an exception).
* __construct():
-- calls check_internal_upgrades() for doing running any requisite
upgrades for itself.
* check_internal_upgrades() [NEW]:
-- performs any internal upgrades as necessary (eventually).
-- NOTE::: presently, it just loads its own version into the
database... future commits will finalize this logic.
* check_versions():
-- if valid data was not returned from get_database_version(), then
the initial version of the current project (which could also be
itself) is loaded into the database.
* upgrade_in_progress():
-- removed a call to get_database_version()
-- if the internal databaseVersion isn't set, it throws an exception.
* get_database_version():
-- if no rows were returned & there is no database error, it will
throw an exception if the internal allowNoDBVersion is false;
otherwise, it will return false: allows for initial loading of version
info into the db.
* is_higher_version():
-- calls cs_versionAbstract::is_higher_version, which is technically
identical to what this used to be, save for logging.
* load_table():
-- removed extra spaces from log message parts
-- call load_initial_version() instead of manually inserting (so the
code can be reused).
* load_initial_version() [NEW]:
-- inserts version and project information into the database.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-08-04 16:38:31 UTC (rev 24)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-08-04 18:59:26 UTC (rev 25)
@@ -12,13 +12,15 @@
*
*/
-class cs_webdbupgrade {
+require_once(constant('LIBDIR') .'/cs-versionparse/cs_version.abstract.class.php');
+
+class cs_webdbupgrade extends cs_versionAbstract {
/** cs_fileSystem{} object: for filesystem read/write operations. */
private $fsObj;
/** cs_globalFunctions{} object: debugging, array, and string operations. */
- private $gfObj;
+ protected $gfObj;
/** Array of configuration parameters. */
private $config = NULL;
@@ -44,6 +46,9 @@
/** Name (absolute location) of *.lock file that indicates an upgrade is running. */
private $lockfile;
+ /** */
+ private $allowNoDBVersion=true;
+
/** List of acceptable suffixes; example "1.0.0-BETA3" -- NOTE: these MUST be in
* an order that reflects newest -> oldest; "ALPHA happens before BETA, etc. */
private $suffixList = array(
@@ -143,6 +148,8 @@
$this->error_handler(__METHOD__ .": upgrade in progress: ". $this->fsObj->read($this->lockfile));
}
+ $this->check_internal_upgrades();
+
$this->check_versions(false);
}//end __construct()
//=========================================================================
@@ -151,6 +158,42 @@
//=========================================================================
/**
+ * Determine if there are any upgrades that need to be performed...
+ */
+ private function check_internal_upgrades() {
+ $oldVersionFileLocation = $this->versionFileLocation;
+ $oldUpgradeConfigFile = $this->config['UPGRADE_CONFIG_FILE'];
+ $this->config['UPGRADE_CONFIG_FILE'] = dirname(__FILE__) .'/upgrades/upgrade.xml';
+
+ //do stuff here...
+ $this->versionFileLocation = dirname(__FILE__) .'/VERSION';
+ $this->read_version_file();
+
+ $this->gfObj->debug_print($this->parse_version_string($this->versionFileVersion),1);
+
+ //if there is an error, then... uh... yeah.
+ try {
+ $this->get_database_version();
+ }
+ catch(exception $e) {
+ #throw new exception(__METHOD__ .": error while retrieving database version: ". $e->getMessage());
+
+ //try creating the version.
+ $this->load_initial_version();
+ }
+
+ //reset internal vars.
+ $this->versionFileLocation = $oldVersionFileLocation;
+ $this->config['UPGRADE_CONFIG_FILE'] = $oldUpgradeConfigFile;
+ $this->read_version_file();
+
+ }//end check_internal_upgrades()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ /**
* Where everything begins: checks if the version held in config.xml lines-up
* with the one in the VERSION file; if it does, then it checks the version
* listed in the database.
@@ -172,6 +215,9 @@
//okay, all files present: check the version in the VERSION file.
$versionFileVersion = $this->read_version_file();
$dbVersion = $this->get_database_version();
+ if(!is_array($dbVersion)) {
+ $this->load_initial_version();
+ }
$versionsDiffer = TRUE;
$retval = FALSE;
@@ -347,10 +393,14 @@
//=========================================================================
public function upgrade_in_progress($makeItSo=FALSE) {
if($makeItSo === TRUE) {
- $this->get_database_version();
- $details = $this->projectName .': Upgrade from '. $this->databaseVersion .' started at '. date('Y-m-d H:i:s');
- $this->create_lockfile($details);
- $retval = TRUE;
+ if(strlen($this->databaseVersion)) {
+ $details = $this->projectName .': Upgrade from '. $this->databaseVersion .' started at '. date('Y-m-d H:i:s');
+ $this->create_lockfile($details);
+ $retval = TRUE;
+ }
+ else {
+ $this->error_handler(__METHOD__ .": missing internal databaseVersion (". $this->databaseVersion .")");
+ }
}
$retval = $this->check_lockfile();
@@ -488,6 +538,14 @@
"ERROR: ". $dberror .", SCHEMA LOAD ERROR::: ". $loadTableResult);
}
}
+ elseif(!strlen($dberror) && $numrows == 0) {
+ if($this->allowNoDBVersion) {
+ $retval = false;
+ }
+ else {
+ $this->error_handler(__METHOD__ .": no version data found for (". $this->projectName .")");
+ }
+ }
else {
$this->error_handler(__METHOD__ .": failed to retrieve version... numrows=(". $numrows ."), DBERROR::: ". $dberror);
}
@@ -667,104 +725,13 @@
//=========================================================================
- protected function is_higher_version($version, $checkIfHigher) {
- $retval = FALSE;
- if(!is_string($version) || !is_string($checkIfHigher)) {
- $this->error_handler(__METHOD__ .": didn't get strings... ". debug_print(func_get_args(),0));
+ public function is_higher_version($version, $checkIfHigher) {
+ try {
+ $retval = parent::is_higher_version($version, $checkIfHigher);
}
- elseif($version == $checkIfHigher) {
- $retval = FALSE;
+ catch(exception $e) {
+ $this->error_handler($e->getMessage());
}
- else {
- $curVersionArr = $this->parse_version_string($version);
- $checkVersionArr = $this->parse_version_string($checkIfHigher);
-
- unset($curVersionArr['version_string'], $checkVersionArr['version_string']);
-
-
- $curVersionSuffix = $curVersionArr['version_suffix'];
- $checkVersionSuffix = $checkVersionArr['version_suffix'];
-
-
- unset($curVersionArr['version_suffix']);
-
- foreach($curVersionArr as $index=>$versionNumber) {
- $checkThis = $checkVersionArr[$index];
-
- if(is_numeric($checkThis) && is_numeric($versionNumber)) {
- //set them as integers.
- settype($versionNumber, 'int');
- settype($checkThis, 'int');
-
- if($checkThis > $versionNumber) {
- $retval = TRUE;
- break;
- }
- elseif($checkThis == $versionNumber) {
- //they're equal...
- }
- else {
- //TODO: should there maybe be an option to throw an exception (freak out) here?
- $this->logsObj->log_by_class(__METHOD__ .": while checking ". $index .", realized the new version (". $checkIfHigher .") is LOWER than current (". $version .")",'debug');
- }
- }
- else {
- $this->error_handler(__METHOD__ .": ". $index ." is not numeric in one of the strings " .
- "(versionNumber=". $versionNumber .", checkThis=". $checkThis .")");
- }
- }
-
- //now deal with those damnable suffixes, but only if the versions are so far identical: if
- // the "$checkIfHigher" is actually higher, don't bother (i.e. suffixes don't matter when
- // we already know there's a major, minor, or maintenance version that's also higher.
- if($retval === FALSE) {
- //EXAMPLE: $version="1.0.0-BETA3", $checkIfHigher="1.1.0"
- // Moving from a non-suffixed version to a suffixed version isn't supported, but the inverse is:
- // i.e. (1.0.0-BETA3 to 1.0.0) is okay, but (1.0.0 to 1.0.0-BETA3) is NOT.
- // Also: (1.0.0-BETA3 to 1.0.0-BETA4) is okay, but (1.0.0-BETA4 to 1.0.0-BETA3) is NOT.
- if(strlen($curVersionSuffix) && strlen($checkVersionSuffix) && $curVersionSuffix == $checkVersionSuffix) {
- //matching suffixes.
- }
- elseif(strlen($curVersionSuffix) || strlen($checkVersionSuffix)) {
- //we know the suffixes are there and DO match.
- if(strlen($curVersionSuffix) && strlen($checkVersionSuffix)) {
- //okay, here's where we do some crazy things...
- $curVersionData = $this->parse_suffix($curVersionSuffix);
- $checkVersionData = $this->parse_suffix($checkVersionSuffix);
-
- if($curVersionData['type'] == $checkVersionData['type']) {
- //got the same suffix type (like "BETA"), check the number.
- if($checkVersionData['number'] > $curVersionData['number']) {
- $retval = TRUE;
- }
- elseif($checkVersionData['number'] == $curVersionData['number']) {
- $retval = FALSE;
- }
- else {
- //umm... they're identical??? LOGIC HAS FAILED ME ALTOGETHER!!!
- $retval = FALSE;
- }
- }
- else {
- //not the same suffix... see if the new one is higher.
- $suffixValues = array_flip($this->suffixList);
- if($suffixValues[$checkVersionData['type']] > $suffixValues[$curVersionData['type']]) {
- $retval = TRUE;
- }
- }
-
- }
- elseif(strlen($curVersionSuffix) && !strlen($checkVersionSuffix)) {
- //i.e. "1.0.0-BETA1" to "1.0.0" --->>> OKAY!
- $retval = TRUE;
- }
- elseif(!strlen($curVersionSuffix) && strlen($checkVersionSuffix)) {
- //i.e. "1.0.0" to "1.0.0-BETA1" --->>> NOT ACCEPTABLE!
- $this->logsObj->log_by_class(__METHOD__ .": from (". $version .") to (". $checkIfHigher .") isn't acceptable...?", 'debug');
- }
- }
- }
- }
return($retval);
@@ -937,33 +904,20 @@
$loadTableResult = $this->db->errorMsg();
if(!strlen($loadTableResult)) {
$loadTableResult = true;
- $logRes = 'Successfully loaded ';
+ $logRes = 'Successfully loaded';
$logType = 'initialize';
//now set the initial version information...
if(strlen($this->projectName) && strlen($this->versionFileVersion)) {
-
- //if there's an INITIAL_VERSION in the upgrade config file, use that.
- $this->read_upgrade_config_file();
- if(isset($this->config['UPGRADELIST']['INITIALVERSION'])) {
- $insertData = $this->parse_version_string($this->config['UPGRADELIST']['INITIALVERSION']);
- }
- else {
- $insertData = $this->parse_version_string($this->versionFileVersion);
- }
- $insertData['project_name'] = $this->projectName;
-
- $sql = 'INSERT INTO '. $this->config['DB_TABLE'] . $this->gfObj->string_from_array($insertData, 'insert');
- if($this->db->run_insert($sql, $this->sequenceName)) {
- $this->logsObj->log_by_class('Created initial version info ('. $insertData['version_string'] .')', $logType);
- }
- else {
- $this->logsObj->log_by_class('Failed to create version info ('. $insertData['version_string'] .')', 'error');
- }
+ $this->load_initial_version();
}
+ else {
+ throw new exception(__METHOD__ .": missing projectName (". $this->projectName .") " .
+ "or versionFileVersion (". $this->versionFileVersion ."), cannot load data");
+ }
}
else {
- $logRes = 'Failed to load ';
+ $logRes = 'Failed to load';
$logType = 'error';
}
$this->logsObj->log_by_class($logRes .' table ('. $this->config['DB_TABLE'] .') into ' .
@@ -1070,6 +1024,35 @@
//=========================================================================
+
+ //=========================================================================
+ public function load_initial_version() {
+ //if there's an INITIAL_VERSION in the upgrade config file, use that.
+ $this->read_upgrade_config_file();
+ if(isset($this->config['UPGRADELIST']['INITIALVERSION'])) {
+ $insertData = $this->parse_version_string($this->config['UPGRADELIST']['INITIALVERSION']);
+ }
+ else {
+ $insertData = $this->parse_version_string($this->versionFileVersion);
+ }
+ $insertData['project_name'] = $this->projectName;
+
+ $sql = 'INSERT INTO '. $this->config['DB_TABLE'] . $this->gfObj->string_from_array($insertData, 'insert');
+
+ $this->gfObj->debug_print(__METHOD__ .": SQL::: ". $sql,1);
+ if($this->db->run_insert($sql, $this->sequenceName)) {
+ $loadRes = true;
+ $this->logsObj->log_by_class("Created data for '". $this->projectName ."' with version '". $insertData['version_string'] ."'", 'initialize');
+ }
+ else {
+ $this->error_handler(__METHOD__ .": failed to load initial version::: ". $e->getMessage());
+ }
+
+ return($loadRes);
+ }//end load_initial_version()
+ //=========================================================================
+
+
}//end upgrade{}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-08-04 20:33:44
|
Revision: 26
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=26&view=rev
Author: crazedsanity
Date: 2009-08-04 20:33:29 +0000 (Tue, 04 Aug 2009)
Log Message:
-----------
Better logging, internal upgrades "work", removed debugging.
/cs_webdbupgrade.class.php:
* __construct():
-- connect the logger AFTER calling check_internal_upgrades()
-- call connect_logger(): this switches the category.
* check_internal_upgrades():
-- connects logger with "Internal Upgrades" category
-- removed a debug_print().
-- call check_versions(true) without errors!
* load_initial_version():
-- removed a debug_print()
* connect_db_logger() [NEW]:
-- creates the internal cs_webdblogger{} object with the given
category (basically, this is called to switch logged category).
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-08-04 18:59:26 UTC (rev 25)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-08-04 20:33:29 UTC (rev 26)
@@ -133,13 +133,8 @@
$this->db = new cs_phpDB(constant('DBTYPE'));
try {
$this->db->connect($this->config['DBPARAMS']);
-
- $loggerDb = new cs_phpDB(constant('DBTYPE'));
- $loggerDb->connect($this->config['DBPARAMS'], true);
- $this->logsObj = new cs_webdblogger($loggerDb, "Upgrade");
}
catch(exception $e) {
- $this->gfObj->debug_print($this->config,1);
throw new exception(__METHOD__ .": failed to connect to database or logger error: ". $e->getMessage());
}
@@ -149,6 +144,12 @@
}
$this->check_internal_upgrades();
+ try {
+ $this->connect_logger("Upgrade");
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to create logger::: ". $e->getMessage());
+ }
$this->check_versions(false);
}//end __construct()
@@ -165,12 +166,20 @@
$oldUpgradeConfigFile = $this->config['UPGRADE_CONFIG_FILE'];
$this->config['UPGRADE_CONFIG_FILE'] = dirname(__FILE__) .'/upgrades/upgrade.xml';
+
+ //connect the logger...
+ try {
+ $this->connect_logger("Internal Upgrade");
+ }
+ catch(exception $e) {
+ $this->error_handler($e->getMessage());
+ }
+
+
//do stuff here...
$this->versionFileLocation = dirname(__FILE__) .'/VERSION';
$this->read_version_file();
- $this->gfObj->debug_print($this->parse_version_string($this->versionFileVersion),1);
-
//if there is an error, then... uh... yeah.
try {
$this->get_database_version();
@@ -182,6 +191,12 @@
$this->load_initial_version();
}
+ //do upgrades here...
+ $this->check_versions(true);
+
+
+
+
//reset internal vars.
$this->versionFileLocation = $oldVersionFileLocation;
$this->config['UPGRADE_CONFIG_FILE'] = $oldUpgradeConfigFile;
@@ -1039,7 +1054,6 @@
$sql = 'INSERT INTO '. $this->config['DB_TABLE'] . $this->gfObj->string_from_array($insertData, 'insert');
- $this->gfObj->debug_print(__METHOD__ .": SQL::: ". $sql,1);
if($this->db->run_insert($sql, $this->sequenceName)) {
$loadRes = true;
$this->logsObj->log_by_class("Created data for '". $this->projectName ."' with version '". $insertData['version_string'] ."'", 'initialize');
@@ -1053,6 +1067,16 @@
//=========================================================================
+
+ //=========================================================================
+ private function connect_logger($logCategory) {
+ $loggerDb = new cs_phpDB(constant('DBTYPE'));
+ $loggerDb->connect($this->config['DBPARAMS'], true);
+ $this->logsObj = new cs_webdblogger($loggerDb, $logCategory);
+ }//end connect_logger()
+ //=========================================================================
+
+
}//end upgrade{}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-08-06 20:51:56
|
Revision: 32
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=32&view=rev
Author: crazedsanity
Date: 2009-08-06 20:51:45 +0000 (Thu, 06 Aug 2009)
Log Message:
-----------
Changes to go along with the v0.2 release.
/cs_webdbupgrade.class.php:
* update_database_version():
-- only update the version_string field: v0.2 no longer has the
"pieces" columns (version_major, version_minor, etc).
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-08-06 20:45:38 UTC (rev 31)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-08-06 20:51:45 UTC (rev 32)
@@ -619,19 +619,14 @@
* so the version there is consistent with all the others.
*/
protected function update_database_version($newVersionString) {
- $versionArr = $this->parse_version_string($newVersionString);
+ $versionInfo = $this->parse_version_string($newVersionString);
- $queryArr = array();
- foreach($versionArr as $index=>$value) {
- $queryArr[$index] = "SELECT internal_data_set_value('". $index ."', '". $value ."');";
- }
+ $sql = "UPDATE ". $this->config['DB_TABLE'] ." SET version_string='".
+ $this->gfObj->cleanString($versionInfo['version_string'], 'sql')
+ ."' WHERE project_name='".
+ $this->gfObj->cleanString($this->projectName, 'sql') ."'";
- $updateData = $versionArr;
- $sql = "UPDATE ". $this->config['DB_TABLE'] ." SET ".
- $this->gfObj->string_from_array($updateData, 'update', null, 'sql') ." WHERE " .
- "project_name='". $this->gfObj->cleanString($this->projectName, 'sql') ."'";
-
$updateRes = $this->db->run_update($sql,false);
if($updateRes == 1) {
$retval = $updateRes;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-08-11 18:51:15
|
Revision: 36
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=36&view=rev
Author: crazedsanity
Date: 2009-08-11 18:51:07 +0000 (Tue, 11 Aug 2009)
Log Message:
-----------
INTERMEDIATE: use constants instead of passing config, better upgrade support.
NOTE::: there is still much debugging in this version. It should not be used
on production systems (though the logging will probably be stripped out soon
enough). The basic problem is that the upgrade system (cs_webdbupgrade)
depends upon the logger (cs_webdblogger) for logging, but the logger could
potentially upgrade, as could the upgrade system: in the situation where the
logger gets upgraded, bad things happen; when both get upgraded, worse things
happen. One of the errors I experienced was that the system would get stuck
in a loop until the database ran out of available connections.
/cs_webdbupgrade.class.php:
* MAIN:::
-- temporarily include a script for cs_debug_backtrace() (debugging)
-- new private var $internalUpgradeInProgress = false
-- new private vars for log storage (still in progress of
implementation here... there's chicken-or-the-egg issues happening
between this class and cs_webdblogger).
* __construct():
-- VAR CHANGE: RENAMED VAR: #2 ($upgradeConfigFile)
-- VAR CHANGE: NEW VAR: $lockFile='upgrade.lock'
-- Systems MUST send the location of their upgrade.xml file, their
version file, and optionally specify the name of the lockfile (so only
that given system is locked).
-- use constants and passed parameters to build the internal config
array instead of requiring that it be passed.
-- NOTE::: setting $this->versionFileLocation creates a var for this
class that is SEPARATE from the private one in cs_versionAbstract; one
MUST call set_version_file_location() instead of trying to set it
directly.
-- The call to connect_logger() has no arguments so the default log
category can be set in a standardized way.
* CHANGE LOGGING (call do_log())::::
-- check_versions()
-- perform_upgrade()
-- do_single_upgrade()
-- check_database_version()
-- do_scripted_upgrade()
-- get_upgrade_list()
-- fix_xml_config()
-- load_table()
-- error_handler()
-- load_initial_version()
* do_scripted_upgrade():
-- the directory for upgrade scripts should ALWAYS be in the same
place as the upgrade.xml file, so use that as the directory using
dirname() and stop logging errors about it.
* error_handler():
-- logic for handling the situation where logsObj isn't an object,
with additional logic for if the system is currently undergoing an
upgrade...
-- NOTE::: doesthe "suspended logging" logic here actually probably
fit better in cs_webdblogger's domain... ?
* load_initial_version():
-- fix insert logic to match new database schema.
* connect_logger():
-- ARG CHANGE: DEFAULT VALUE SET: $logCategory=null
-- debugging
-- logic for setting logCategory if none passed
-- pass false as the 3rd arg to the pending version of webdblogger,
to tell it NOT to look for upgrades...
* do_log() [NEW]:
-- method for handling logging. The idea here is to have a
standardized way of logging, plus a place where logs can be
temporarily suspended if they need to be (i.e. if the system itself is
undergoing an upgrade).
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-08-07 15:51:14 UTC (rev 35)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-08-11 18:51:07 UTC (rev 36)
@@ -13,6 +13,7 @@
*/
require_once(constant('LIBDIR') .'/cs-versionparse/cs_version.abstract.class.php');
+require_once(constant('LIBDIR') .'/cs_debug.php');
class cs_webdbupgrade extends cs_versionAbstract {
@@ -46,9 +47,16 @@
/** Name (absolute location) of *.lock file that indicates an upgrade is running. */
private $lockfile;
+ /** Determines if an internal upgrade is happening (avoids some infinite loops) */
+ private $internalUpgradeInProgress = false;
+
/** */
private $allowNoDBVersion=true;
+ /** Log messages to store during an internal upgrade (to avoid problems) */
+ private $storedLogs = array();
+ private $debugLogs=array();
+
/** List of acceptable suffixes; example "1.0.0-BETA3" -- NOTE: these MUST be in
* an order that reflects newest -> oldest; "ALPHA happens before BETA, etc. */
private $suffixList = array(
@@ -58,34 +66,17 @@
);
//=========================================================================
- public function __construct($versionFileLocation, array $config) {
+ public function __construct($versionFileLocation, $upgradeConfigFile, $lockFile='upgrade.lock') {
- //Handle the config array (cope with XML-ish array)
- if(is_array($config)) {
- //check if it is in the complex XML array style...
- $keys = array_keys($config);
- if(isset($config[$keys[0]]['type'])) {
- $this->fix_xml_config($config);
- $this->config = $this->tempXmlConfig;
- }
- else {
- $this->config = $config;
- }
- }
- else {
- throw new exception(__METHOD__ .": no configuration available");
- }
-
- //cope with problems in CS-Content v1.0-ALPHA9 (or before)--see http://project.crazedsanity.com/extern/helpdesk/view?ID=281
- if(isset($this->config['DBPARMLINKER'])) {
- $this->config['DBPARAMS'] = array();
- foreach($this->config['DBPARMLINKER'] as $i=>$loc) {
- $this->config['DBPARAMS'][strtolower($i)] = $this->config[$loc];
- unset($this->config[$loc]);
- }
- unset($this->config['DBPARMLINKER']);
- }
-
+ //setup configuration parameters for database connectivity.
+ $dbParams = array(
+ 'host' => constant(__CLASS__ .'-DB_CONNECT_HOST'),
+ 'port' => constant(__CLASS__ .'-DB_CONNECT_PORT'),
+ 'dbname' => constant(__CLASS__ .'-DB_CONNECT_DBNAME'),
+ 'user' => constant(__CLASS__ .'-DB_CONNECT_USER'),
+ 'password' => constant(__CLASS__ .'-DB_CONNECT_PASSWORD')
+ );
+ $this->config['DBPARAMS'] = $dbParams;
//Check for some required constants.
$requisiteConstants = array('LIBDIR');
if(!defined('LIBDIR')) {
@@ -103,32 +94,46 @@
require_once(constant('LIBDIR') .'/cs-phpxml/cs_phpxmlCreator.class.php');
require_once(constant('LIBDIR') .'/cs-phpxml/cs_arrayToPath.class.php');
- $this->versionFileLocation = $versionFileLocation;
-
$this->fsObj = new cs_fileSystem(constant('SITE_ROOT'));
$this->gfObj = new cs_globalFunctions;
if(defined('DEBUGPRINTOPT')) {
$this->gfObj->debugPrintOpt = constant('DEBUGPRINTOPT');
}
- if(!isset($this->config['DB_PRIMARYKEY']) || !isset($this->config['DB_TABLE'])) {
+ if(!defined(__CLASS__ .'-DB_PRIMARYKEY') || !defined(__CLASS__ .'-DB_TABLE')) {
throw new exception(__METHOD__ .": no setting for DB_TABLE or DB_PRIMARYKEY, cannot continue");
}
+ else {
+ $this->config['DB_TABLE'] = constant(__CLASS__ .'-DB_TABLE');
+ $this->config['DB_PRIMARYKEY'] = constant(__CLASS__ .'-DB_PRIMARYKEY');
+ }
$this->sequenceName = $this->config['DB_TABLE'] .'_'. $this->config['DB_PRIMARYKEY'] .'_seq';
if(!defined('DBTYPE')) {
throw new exception(__METHOD__ .": required constant 'DBTYPE' not set");
}
- if(!isset($this->config['CONFIG_FILE_LOCATION'])) {
- throw new exception(__METHOD__ .": required setting 'CONFIG_FILE_LOCATION' not found");
+
+ if(!file_exists($upgradeConfigFile) || !is_readable($upgradeConfigFile)) {
+ throw new exception(__METHOD__ .": required upgrade config file location (". $upgradeConfigFile .") not set or unreadable");
}
+ else {
+ $this->config['UPGRADE_CONFIG_FILE'] = $upgradeConfigFile;
+ }
if(!strlen($versionFileLocation) || !file_exists($versionFileLocation)) {
throw new exception(__METHOD__ .": unable to locate version file (". $versionFileLocation .")");
}
- if(!isset($this->config['RWDIR']) || !is_dir($this->config['RWDIR']) || !is_readable($this->config['RWDIR']) || !is_writable($this->config['RWDIR'])) {
- throw new exception(__METHOD__ .": missing RWDIR (". $this->config['RWDIR'] .") or isn't readable/writable");
+ $this->set_version_file_location($versionFileLocation);
+
+ if(!defined(__CLASS__ .'-RWDIR') || !is_dir(constant(__CLASS__ .'-RWDIR')) || !is_readable(constant(__CLASS__ .'-RWDIR')) || !is_writable(constant(__CLASS__ .'-RWDIR'))) {
+ throw new exception(__METHOD__ .": missing RWDIR (". constant(__CLASS__ .'-RWDIR') .") or isn't readable/writable");
}
- $this->lockfile = $this->config['RWDIR'] .'/upgrade.lock';
+ else {
+ $this->config['RWDIR'] = constant(__CLASS__ .'-RWDIR');
+ }
+ if(!is_string($lockFile)) {
+ $lockFile = 'upgrade.lock';
+ }
+ $this->lockfile = $this->config['RWDIR'] .'/'. $lockFile;
$this->db = new cs_phpDB(constant('DBTYPE'));
try {
@@ -140,17 +145,22 @@
if($this->check_lockfile()) {
//there is an existing lockfile...
- $this->error_handler(__METHOD__ .": upgrade in progress: ". $this->fsObj->read($this->lockfile));
+ throw new exception(__METHOD__ .": upgrade in progress: ". $this->fsObj->read($this->lockfile));
}
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
+
$this->check_internal_upgrades();
+
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
try {
- $this->connect_logger("Upgrade");
+ $this->connect_logger();
}
catch(exception $e) {
throw new exception(__METHOD__ .": failed to create logger::: ". $e->getMessage());
}
+ $this->gfObj->debug_print($this,1);
$this->check_versions(false);
}//end __construct()
//=========================================================================
@@ -162,45 +172,51 @@
* Determine if there are any upgrades that need to be performed...
*/
private function check_internal_upgrades() {
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$oldVersionFileLocation = $this->versionFileLocation;
$oldUpgradeConfigFile = $this->config['UPGRADE_CONFIG_FILE'];
$this->config['UPGRADE_CONFIG_FILE'] = dirname(__FILE__) .'/upgrades/upgrade.xml';
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
- //connect the logger...
- try {
- $this->connect_logger("Internal Upgrade");
- }
- catch(exception $e) {
- $this->error_handler($e->getMessage());
- }
+ //set a status flag so we can store log messages (for now).
+ $this->internalUpgradeInProgress = true;
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
//do stuff here...
- $this->versionFileLocation = dirname(__FILE__) .'/VERSION';
+ $this->set_version_file_location(dirname(__FILE__) .'/VERSION');
$this->read_version_file();
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
//if there is an error, then... uh... yeah.
try {
$this->get_database_version();
}
catch(exception $e) {
- #throw new exception(__METHOD__ .": error while retrieving database version: ". $e->getMessage());
+ throw new exception(__METHOD__ .": error while retrieving database version: ". $e->getMessage());
//try creating the version.
$this->load_initial_version();
}
//do upgrades here...
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$this->check_versions(true);
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
+ $this->internalUpgradeInProgress = false;
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
//reset internal vars.
- $this->versionFileLocation = $oldVersionFileLocation;
+ $this->set_version_file_location($oldVersionFileLocation);
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$this->config['UPGRADE_CONFIG_FILE'] = $oldUpgradeConfigFile;
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$this->read_version_file();
+$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
}//end check_internal_upgrades()
//=========================================================================
@@ -223,7 +239,7 @@
//check to see if the lock files for upgrading exist.
if($this->upgrade_in_progress()) {
- $this->logsObj->log_by_class("Upgrade in progress", 'notice');
+ $this->do_log("Upgrade in progress", 'notice');
throw new exception(__METHOD__ .": upgrade in progress");
}
else {
@@ -334,7 +350,7 @@
$lockConfig = $this->upgrade_in_progress(TRUE);
$this->fsObj->cd("/");
- $this->logsObj->log_by_class("Starting upgrade process...", 'begin');
+ $this->do_log("Starting upgrade process...", 'begin');
//TODO: not only should the "create_file()" method be run, but also do a sanity check by calling lock_file_exists().
if($lockConfig === 0) {
@@ -342,7 +358,7 @@
$this->error_handler(__METHOD__ .": failed to set 'upgrade in progress'");
}
else {
- $this->logsObj->log_by_class(__METHOD__ .": result of creating lockfile: (". $lockConfig .")", 'debug');
+ $this->do_log(__METHOD__ .": result of creating lockfile: (". $lockConfig .")", 'debug');
//push data into our internal "config" array.
$this->read_upgrade_config_file();
@@ -353,39 +369,38 @@
if($versionConflictInfo !== false) {
- $this->logsObj->log_by_class("Upgrading ". $versionConflictInfo ." versions, from " .
+ $this->do_log("Upgrading ". $versionConflictInfo ." versions, from " .
"(". $this->databaseVersion .") to (". $this->versionFileVersion .")", 'info');
}
$upgradeList = $this->get_upgrade_list();
-
try {
$i=0;
- $this->logsObj->log_by_class(__METHOD__ .": starting to run through the upgrade list, starting at (". $this->databaseVersion ."), " .
+ $this->do_log(__METHOD__ .": starting to run through the upgrade list, starting at (". $this->databaseVersion ."), " .
"total number of upgrades to perform: ". count($upgradeList), 'debug');
$this->db->beginTrans(__METHOD__);
foreach($upgradeList as $fromVersion=>$toVersion) {
$details = __METHOD__ .": upgrading from ". $fromVersion ." to ". $toVersion ."... ";
- $this->logsObj->log_by_class($details, 'system');
+ $this->do_log($details, 'system');
$this->do_single_upgrade($fromVersion, $toVersion);
$this->get_database_version();
$i++;
$details = __METHOD__ .": finished upgrade #". $i .", now at version (". $this->databaseVersion .")";
- $this->logsObj->log_by_class($details, 'system');
+ $this->do_log($details, 'system');
}
if($i < count($upgradeList)) {
- $this->logsObj->log_by_class(__METHOD__ .": completed upgrade ". $i ." of ". count($upgradeList), 'debug');
+ $this->do_log(__METHOD__ .": completed upgrade ". $i ." of ". count($upgradeList), 'debug');
}
else {
if($this->databaseVersion == $this->versionFileVersion) {
- $this->logsObj->log_by_class(__METHOD__ .": finished upgrading after performing (". $i .") upgrades", 'debug');
+ $this->do_log(__METHOD__ .": finished upgrading after performing (". $i .") upgrades", 'debug');
$this->newVersion = $this->databaseVersion;
}
else {
- $this->logsObj->log_by_class(__METHOD__ .": upgradeList::: ". $this->gfObj->debug_print($upgradeList,0), 'debug');
+ $this->do_log(__METHOD__ .": upgradeList::: ". $this->gfObj->debug_print($upgradeList,0), 'debug');
$this->error_handler(__METHOD__ .": finished upgrade, but version wasn't updated (expecting '". $this->versionFileVersion ."', got '". $this->databaseVersion ."')!!!");
}
}
@@ -397,7 +412,7 @@
$this->error_handler(__METHOD__ .": upgrade aborted:::". $e->getMessage());
$this->db->rollbackTrans();
}
- $this->logsObj->log_by_class("Upgrade process complete", 'end');
+ $this->do_log("Upgrade process complete", 'end');
}
}
}//end perform_upgrade()
@@ -607,7 +622,7 @@
$this->error_handler(__METHOD__ .": target version not specified, unable to proceed with upgrade for ". $versionIndex);
}
}
- $this->logsObj->log_by_class("Finished upgrade to ". $this->newVersion, 'system');
+ $this->do_log("Finished upgrade to ". $this->newVersion, 'system');
}//end do_single_upgrade()
//=========================================================================
@@ -666,7 +681,7 @@
}
if(!$retval) {
- $this->logsObj->log_by_class("Version check failed, versionString=(". $versionString ."), checkVersion=(". $this->newVersion .")", 'FATAL');
+ $this->do_log("Version check failed, versionString=(". $versionString ."), checkVersion=(". $this->newVersion .")", 'FATAL');
}
}
@@ -684,20 +699,16 @@
private function do_scripted_upgrade(array $upgradeData) {
$myConfigFile = $upgradeData['SCRIPT_NAME'];
- $this->logsObj->log_by_class("Preparing to run script '". $myConfigFile ."'", 'debug');
+ $this->do_log("Preparing to run script '". $myConfigFile ."'", 'debug');
//we've got the filename, see if it exists.
- if(isset($this->config['UPGRADE_SCRIPTS_DIR'])) {
- $scriptsDir = $this->config['UPGRADE_SCRIPTS_DIR'];
- }
- else {
- $this->logsObj->log_by_class("No UPGRADE_SCRIPTS_DIR config setting", 'warning');
- $scriptsDir = dirname($this->config['UPGRADE_CONFIG_FILE']);
- }
+
+ $scriptsDir = dirname($this->config['UPGRADE_CONFIG_FILE']);
$fileName = $scriptsDir .'/'. $myConfigFile;
+
if(file_exists($fileName)) {
-
- $this->logsObj->log_by_class("Performing scripted upgrade (". $myConfigFile .")", 'DEBUG');
+
+ $this->do_log("(". __CLASS__ .") Performing scripted upgrade (". $myConfigFile .") from file '". $fileName ."'", 'DEBUG');
$createClassName = $upgradeData['CLASS_NAME'];
$classUpgradeMethod = $upgradeData['CALL_METHOD'];
require_once($fileName);
@@ -710,12 +721,12 @@
if($upgradeResult === true) {
//yay, it worked!
- $this->logsObj->log_by_class("Upgrade succeeded (". $upgradeResult .")", 'success');
+ $this->do_log("Upgrade succeeded (". $upgradeResult .")", 'success');
}
else {
$this->error_handler(__METHOD__ .": upgrade failed (". $upgradeResult .")");
}
- $this->logsObj->log_by_class("Finished running ". $createClassName ."::". $classUpgradeMethod ."(), result was (". $upgradeResult .")", 'debug');
+ $this->do_log("Finished running ". $createClassName ."::". $classUpgradeMethod ."(), result was (". $upgradeResult .")", 'debug');
}
else {
$this->error_handler(__METHOD__ .": upgrade method doesn't exist (". $createClassName ."::". $classUpgradeMethod
@@ -788,11 +799,11 @@
$retval[$matchVersion] = $data['TARGET_VERSION'];
}
else {
- $this->logsObj->log_by_class(__METHOD__ .": entry in upgrade.xml (". $matchVersion .") is higher than the VERSION file (". $this->versionFileVersion .")", 'warning');
+ $this->do_log(__METHOD__ .": entry in upgrade.xml (". $matchVersion .") is higher than the VERSION file (". $this->versionFileVersion .")", 'warning');
}
}
else {
- $this->logsObj->log_by_class(__METHOD__ .": SKIPPING (". $matchVersion .")", 'debug');
+ $this->do_log(__METHOD__ .": SKIPPING (". $matchVersion .")", 'debug');
}
}
@@ -802,7 +813,7 @@
}
else {
//no intermediary upgrades: just pass back the latest version.
- $this->logsObj->log_by_class(__METHOD__ .": no intermediary upgrades", 'debug');
+ $this->do_log(__METHOD__ .": no intermediary upgrades", 'debug');
$retval[$dbVersion] = $this->versionFileVersion;
}
@@ -856,7 +867,7 @@
$a2p = new cs_arrayToPath($config);
}
catch(exception $e) {
- $this->logsObj->log_by_class(__METHOD__ .': encountered exception: '. $e->getMessage());
+ $this->do_log(__METHOD__ .': encountered exception: '. $e->getMessage());
$this->error_handler($e->getMessage());
}
if(!is_array($this->tempXmlConfig)) {
@@ -866,7 +877,7 @@
$myA2p = new cs_arrayToPath(&$this->tempXmlConfig);
}
catch(exception $e) {
- $this->logsObj->log_by_class(__METHOD__ .': encountered exception: '. $e->getMessage());
+ $this->do_log(__METHOD__ .': encountered exception: '. $e->getMessage());
$this->error_handler($e->getMessage());
}
@@ -930,7 +941,7 @@
$logRes = 'Failed to load';
$logType = 'error';
}
- $this->logsObj->log_by_class($logRes .' table ('. $this->config['DB_TABLE'] .') into ' .
+ $this->do_log($logRes .' table ('. $this->config['DB_TABLE'] .') into ' .
'database::: '. $loadTableResult, $logType);
return($loadTableResult);
@@ -1026,7 +1037,18 @@
//=========================================================================
public function error_handler($details) {
//log the error.
- $this->logsObj->log_by_class($details, 'exception in code');
+ $this->gfObj->debug_print($this->debugLogs,1);
+ if(!is_object($this->logsObj)) {
+ if($this->internalUpgradeInProgress === true) {
+ throw new exception(__METHOD__ .": error while running an internal upgrade::: ". $details);
+ }
+ else {
+ $this->connect_logger();
+ }
+ }
+ if($this->internalUpgradeInProgress === false) {
+ $this->do_log($details, 'exception in code');
+ }
//now throw an exception so other code can catch it.
throw new exception($details);
@@ -1039,19 +1061,24 @@
public function load_initial_version() {
//if there's an INITIAL_VERSION in the upgrade config file, use that.
$this->read_upgrade_config_file();
+ $insertData = array();
if(isset($this->config['UPGRADELIST']['INITIALVERSION'])) {
- $insertData = $this->parse_version_string($this->config['UPGRADELIST']['INITIALVERSION']);
+ $parseThis = $this->config['UPGRADELIST']['INITIALVERSION'];
}
else {
- $insertData = $this->parse_version_string($this->versionFileVersion);
+ $parseThis = $this->versionFileVersion;
}
- $insertData['project_name'] = $this->projectName;
+ $versionInfo = $this->parse_version_string($parseThis);
+ $insertData = array(
+ 'project_name' => $this->projectName,
+ 'version_string' => $versionInfo['version_string']
+ );
$sql = 'INSERT INTO '. $this->config['DB_TABLE'] . $this->gfObj->string_from_array($insertData, 'insert');
if($this->db->run_insert($sql, $this->sequenceName)) {
$loadRes = true;
- $this->logsObj->log_by_class("Created data for '". $this->projectName ."' with version '". $insertData['version_string'] ."'", 'initialize');
+ $this->do_log("Created data for '". $this->projectName ."' with version '". $insertData['version_string'] ."'", 'initialize');
}
else {
$this->error_handler(__METHOD__ .": failed to load initial version::: ". $e->getMessage());
@@ -1064,14 +1091,35 @@
//=========================================================================
- private function connect_logger($logCategory) {
+ private function connect_logger($logCategory=null) {
+
+ cs_debug_backtrace(1);
+
+ if(is_null($logCategory) || !strlen($logCategory)) {
+ $logCategory = "Upgrade ". $this->projectName;
+ }
+
$loggerDb = new cs_phpDB(constant('DBTYPE'));
$loggerDb->connect($this->config['DBPARAMS'], true);
- $this->logsObj = new cs_webdblogger($loggerDb, $logCategory);
+ $this->logsObj = new cs_webdblogger($loggerDb, $logCategory, false);
}//end connect_logger()
//=========================================================================
+
+ //=========================================================================
+ protected function do_log($message, $type) {
+ $this->debugLogs[] = array('project'=>$this->projectName,'upgradeFile'=>$this->config['UPGRADE_CONFIG_FILE'],'message'=>$message,'type'=>$type);
+ if($this->internalUpgradeInProgress === true) {
+ $this->storedLogs[] = func_get_args();
+ }
+ else {
+ $this->logsObj->log_by_class($message, $type);
+ }
+ }//end do_log()
+ //=========================================================================
+
+
}//end upgrade{}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-08-13 03:19:40
|
Revision: 37
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=37&view=rev
Author: crazedsanity
Date: 2009-08-13 03:19:31 +0000 (Thu, 13 Aug 2009)
Log Message:
-----------
INTERMEDIATE: fixes for logging + some debugging.
/cs_webdbupgrade.class.php:
* __construct():
-- better checking on the value of $lockFile
-- drop some debugging
-- connect logger manually instead of calling connect_logger()
* check_internal_upgrades():
-- remove lots of debugging
* perform_upgrade():
-- suspend logging for the entire method & handle the pending logs at
the very end.
-- added some debugging
-- NOTE::: logging should only be suspended if $this->projectName
matches "cs-webdblogger".
* error_handler():
-- emit debugging messages
* do_log():
-- emit debugging messages
* connect_logger() [DELETED]:
-- stop allowing methods to call this... allowing this can lead to
situations where it overruns the database server with connections.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-08-11 18:51:07 UTC (rev 36)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-08-13 03:19:31 UTC (rev 37)
@@ -130,7 +130,7 @@
else {
$this->config['RWDIR'] = constant(__CLASS__ .'-RWDIR');
}
- if(!is_string($lockFile)) {
+ if(is_null($lockFile) || !strlen($lockFile)) {
$lockFile = 'upgrade.lock';
}
$this->lockfile = $this->config['RWDIR'] .'/'. $lockFile;
@@ -148,19 +148,17 @@
throw new exception(__METHOD__ .": upgrade in progress: ". $this->fsObj->read($this->lockfile));
}
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
-
$this->check_internal_upgrades();
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
- try {
- $this->connect_logger();
+ try {
+ $loggerDb = new cs_phpDB(constant('DBTYPE'));
+ $loggerDb->connect($this->config['DBPARAMS'], true);
+ $this->logsObj = new cs_webdblogger($loggerDb, "Upgrade ". $this->projectName, false);
}
catch(exception $e) {
throw new exception(__METHOD__ .": failed to create logger::: ". $e->getMessage());
}
- $this->gfObj->debug_print($this,1);
$this->check_versions(false);
}//end __construct()
//=========================================================================
@@ -172,22 +170,18 @@
* Determine if there are any upgrades that need to be performed...
*/
private function check_internal_upgrades() {
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$oldVersionFileLocation = $this->versionFileLocation;
$oldUpgradeConfigFile = $this->config['UPGRADE_CONFIG_FILE'];
$this->config['UPGRADE_CONFIG_FILE'] = dirname(__FILE__) .'/upgrades/upgrade.xml';
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
//set a status flag so we can store log messages (for now).
$this->internalUpgradeInProgress = true;
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
//do stuff here...
$this->set_version_file_location(dirname(__FILE__) .'/VERSION');
$this->read_version_file();
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
//if there is an error, then... uh... yeah.
try {
@@ -201,22 +195,16 @@
}
//do upgrades here...
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$this->check_versions(true);
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$this->internalUpgradeInProgress = false;
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
//reset internal vars.
$this->set_version_file_location($oldVersionFileLocation);
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$this->config['UPGRADE_CONFIG_FILE'] = $oldUpgradeConfigFile;
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
$this->read_version_file();
-$this->gfObj->debug_print(__METHOD__ .": line#". __LINE__ ." (". $this->projectName ." - ". $this->versionFileLocation .") -- CONFIG::: ". $this->gfObj->debug_print($this->config,0),1);
}//end check_internal_upgrades()
//=========================================================================
@@ -341,6 +329,7 @@
//=========================================================================
private function perform_upgrade() {
+ $this->logsObj->suspendLogging=true;
//make sure there's not already a lockfile.
if($this->upgrade_in_progress()) {
//ew. Can't upgrade.
@@ -409,12 +398,17 @@
$this->db->commitTrans();
}
catch(exception $e) {
- $this->error_handler(__METHOD__ .": upgrade aborted:::". $e->getMessage());
+ $transactionStatus = $this->db->get_transaction_status(false);
+ $this->error_handler(__METHOD__ .": transaction status=(". $transactionStatus ."), upgrade aborted:::". $e->getMessage());
$this->db->rollbackTrans();
}
+ $this->logsObj->suspendLogging=false;
$this->do_log("Upgrade process complete", 'end');
}
}
+ $this->logsObj->suspendLogging=false;
+ $logsHandled = $this->logsObj->handle_suspended_logs();
+ $this->gfObj->debug_print(__METHOD__ .": done, handled (". $logsHandled .") logs that had been suspended... ",1);
}//end perform_upgrade()
//=========================================================================
@@ -1037,14 +1031,8 @@
//=========================================================================
public function error_handler($details) {
//log the error.
- $this->gfObj->debug_print($this->debugLogs,1);
if(!is_object($this->logsObj)) {
- if($this->internalUpgradeInProgress === true) {
- throw new exception(__METHOD__ .": error while running an internal upgrade::: ". $details);
- }
- else {
- $this->connect_logger();
- }
+ throw new exception(__METHOD__ .": error while running an internal upgrade::: ". $details);
}
if($this->internalUpgradeInProgress === false) {
$this->do_log($details, 'exception in code');
@@ -1091,24 +1079,8 @@
//=========================================================================
- private function connect_logger($logCategory=null) {
-
- cs_debug_backtrace(1);
-
- if(is_null($logCategory) || !strlen($logCategory)) {
- $logCategory = "Upgrade ". $this->projectName;
- }
-
- $loggerDb = new cs_phpDB(constant('DBTYPE'));
- $loggerDb->connect($this->config['DBPARAMS'], true);
- $this->logsObj = new cs_webdblogger($loggerDb, $logCategory, false);
- }//end connect_logger()
- //=========================================================================
-
-
-
- //=========================================================================
protected function do_log($message, $type) {
+ $this->gfObj->debug_print(__METHOD__ .": loggerSuspend=(". $this->logsObj->suspendLogging ."), type=(". $type ."), MESSAGE::: ". $message,1);
$this->debugLogs[] = array('project'=>$this->projectName,'upgradeFile'=>$this->config['UPGRADE_CONFIG_FILE'],'message'=>$message,'type'=>$type);
if($this->internalUpgradeInProgress === true) {
$this->storedLogs[] = func_get_args();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-08-13 04:09:27
|
Revision: 38
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=38&view=rev
Author: crazedsanity
Date: 2009-08-13 04:09:12 +0000 (Thu, 13 Aug 2009)
Log Message:
-----------
Remove some debugging.
NOTE::: this version seems pretty stable, but it is dependent on unreleased
cs-webdblogger v0.2.0. Using older 0.1.x code will cause errors, as this
calls methods in that library that wouldn't exist yet.
/cs_webdbupgrade.class.php:
* perform_upgrade():
-- remove debug printing
* do_log():
-- remove debug logging.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-08-13 03:19:31 UTC (rev 37)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-08-13 04:09:12 UTC (rev 38)
@@ -408,7 +408,6 @@
}
$this->logsObj->suspendLogging=false;
$logsHandled = $this->logsObj->handle_suspended_logs();
- $this->gfObj->debug_print(__METHOD__ .": done, handled (". $logsHandled .") logs that had been suspended... ",1);
}//end perform_upgrade()
//=========================================================================
@@ -1080,7 +1079,6 @@
//=========================================================================
protected function do_log($message, $type) {
- $this->gfObj->debug_print(__METHOD__ .": loggerSuspend=(". $this->logsObj->suspendLogging ."), type=(". $type ."), MESSAGE::: ". $message,1);
$this->debugLogs[] = array('project'=>$this->projectName,'upgradeFile'=>$this->config['UPGRADE_CONFIG_FILE'],'message'=>$message,'type'=>$type);
if($this->internalUpgradeInProgress === true) {
$this->storedLogs[] = func_get_args();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|