Commit 04665d034b51d0a2d423a51b31a86a21def4e9e5

Authored by Paul Barrett
1 parent b14a2b27

Fixed problem with version compare causing recurring 'upgrade your database' error

Committed by: Paul Barrett

Reviewed by: Jarrett Jordaan
lib/dispatcher.inc.php
@@ -343,8 +343,8 @@ class KTStandardDispatcher extends KTDispatcher { @@ -343,8 +343,8 @@ class KTStandardDispatcher extends KTDispatcher {
343 } 343 }
344 344
345 function loginRequired() { 345 function loginRequired() {
346 - $oKTConfig =& KTConfig::getSingleton();  
347 - if ($oKTConfig->get('allowAnonymousLogin', false)) { 346 + $oKTConfig =& KTConfig::getSingleton();
  347 + if ($oKTConfig->get('allowAnonymousLogin', false)) {
348 // anonymous logins are now allowed. 348 // anonymous logins are now allowed.
349 // the anonymous user is -1. 349 // the anonymous user is -1.
350 // 350 //
@@ -352,9 +352,9 @@ class KTStandardDispatcher extends KTDispatcher { @@ -352,9 +352,9 @@ class KTStandardDispatcher extends KTDispatcher {
352 352
353 $oUser =& User::get(-2); 353 $oUser =& User::get(-2);
354 if (PEAR::isError($oUser) || ($oUser->getName() != 'Anonymous')) { 354 if (PEAR::isError($oUser) || ($oUser->getName() != 'Anonymous')) {
355 - ; // do nothing - the database integrity would break if we log the user in now. 355 + ; // do nothing - the database integrity would break if we log the user in now.
356 } else { 356 } else {
357 - $session = new Session(); 357 + $session = new Session();
358 $sessionID = $session->create($oUser); 358 $sessionID = $session->create($oUser);
359 $this->sessionStatus = $this->session->verify(); 359 $this->sessionStatus = $this->session->verify();
360 if ($this->sessionStatus === true) { 360 if ($this->sessionStatus === true) {
lib/session/Session.inc
@@ -228,7 +228,7 @@ class Session { @@ -228,7 +228,7 @@ class Session {
228 // Compare the system version and the database version to determine if the database needs to be upgraded. 228 // Compare the system version and the database version to determine if the database needs to be upgraded.
229 $version = KTUtil::getSystemSetting('databaseVersion'); 229 $version = KTUtil::getSystemSetting('databaseVersion');
230 230
231 - if ($default->systemVersion != $version) { 231 + if (trim($default->systemVersion) != trim($version)) {
232 if (KTLOG_CACHE) $default->log->info("Session::verify : Database not upgraded"); 232 if (KTLOG_CACHE) $default->log->info("Session::verify : Database not upgraded");
233 $_SESSION['errormessage']['login'] = sprintf(_kt('Database incompatibility error: <br> Please ensure that you have completed the database upgrade procedure. <br> Please <a href=%s>click here</a> to complete.'),'setup/upgrade.php'); 233 $_SESSION['errormessage']['login'] = sprintf(_kt('Database incompatibility error: <br> Please ensure that you have completed the database upgrade procedure. <br> Please <a href=%s>click here</a> to complete.'),'setup/upgrade.php');
234 return PEAR::raiseError($_SESSION['errormessage']['login']); 234 return PEAR::raiseError($_SESSION['errormessage']['login']);
setup/upgrade/lib/UpgradeItems.inc.php
@@ -269,7 +269,7 @@ class SQLUpgradeItem extends UpgradeItem { @@ -269,7 +269,7 @@ class SQLUpgradeItem extends UpgradeItem {
269 * 269 *
270 * STATIC 270 * STATIC
271 */ 271 */
272 - function getUpgrades($origVersion, $currVersion) { 272 + public static function getUpgrades($origVersion, $currVersion) {
273 // global $default; 273 // global $default;
274 274
275 // $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/'; 275 // $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/';
@@ -343,7 +343,7 @@ class SQLUpgradeItem extends UpgradeItem { @@ -343,7 +343,7 @@ class SQLUpgradeItem extends UpgradeItem {
343 return $ret; 343 return $ret;
344 } 344 }
345 345
346 - function _getDetailsFromFileName($path) { 346 + public static function _getDetailsFromFileName($path) {
347 // Old format (pre 2.0.6) 347 // Old format (pre 2.0.6)
348 $matched = preg_match('#^([\d.]*)-to-([\d.]*).sql$#', $path, $matches); 348 $matched = preg_match('#^([\d.]*)-to-([\d.]*).sql$#', $path, $matches);
349 if ($matched != 0) { 349 if ($matched != 0) {
setup/upgrade/lib/upgrade.inc.php
@@ -92,25 +92,24 @@ function &amp;describeUpgrade ($origVersion, $currVersion) { @@ -92,25 +92,24 @@ function &amp;describeUpgrade ($origVersion, $currVersion) {
92 // How to figure out what upgrades to do: 92 // How to figure out what upgrades to do:
93 // 93 //
94 // 1. Get all SQL upgrades >= origVersion and <= currVersion 94 // 1. Get all SQL upgrades >= origVersion and <= currVersion
95 - // 2. Get all Function upgrades >= origVersion and <= currVersion  
96 - // 3. Categorise each into version they upgrade to  
97 - // 4. Sort each version subgroup into correct order 95 + // 2. Categorise each into version they upgrade to
  96 + // 3. Sort each version subgroup into correct order
98 // 5. Add "recordSubUpgrade" for each version there. 97 // 5. Add "recordSubUpgrade" for each version there.
99 - // 6. Add back into one big list again  
100 - // 7. Add "recordUpgrade" for whole thing 98 + // 5. Add back into one big list again
  99 + // 6. Add "recordUpgrade" for whole thing
101 100
102 // $recordUpgrade = array('upgrade*' . $currVersion, 'Upgrade to ' . $currVersion, null); 101 // $recordUpgrade = array('upgrade*' . $currVersion, 'Upgrade to ' . $currVersion, null);
103 102
104 $steps = array(); 103 $steps = array();
105 foreach (array('SQLUpgradeItem') as $itemgen) { 104 foreach (array('SQLUpgradeItem') as $itemgen) {
106 $f = array($itemgen, 'getUpgrades'); 105 $f = array($itemgen, 'getUpgrades');
107 - $ssteps =& call_user_func($f, $origVersion, $currVersion); 106 + $ssteps = call_user_func($f, $origVersion, $currVersion);
108 $scount = count($ssteps); 107 $scount = count($ssteps);
109 for ($i = 0; $i < $scount; $i++) { 108 for ($i = 0; $i < $scount; $i++) {
110 $steps[] =& $ssteps[$i]; 109 $steps[] =& $ssteps[$i];
111 } 110 }
112 } 111 }
113 - $upgradestep =& new RecordUpgradeItem($currVersion, $origVersion); 112 + $upgradestep = new RecordUpgradeItem($currVersion, $origVersion);
114 $steps[] =& $upgradestep; 113 $steps[] =& $upgradestep;
115 $stepcount = count($steps); 114 $stepcount = count($steps);
116 for ($i = 0; $i < $stepcount; $i++) { 115 for ($i = 0; $i < $stepcount; $i++) {
setup/upgrade/steps/upgradeDatabase.php
@@ -169,15 +169,16 @@ class upgradeDatabase extends Step @@ -169,15 +169,16 @@ class upgradeDatabase extends Step
169 $this->sysVersion = $this->readVersion(); 169 $this->sysVersion = $this->readVersion();
170 $this->temp_variables['systemVersion'] = $this->sysVersion; 170 $this->temp_variables['systemVersion'] = $this->sysVersion;
171 $dconf = $this->util->iniUtilities->getSection('db'); 171 $dconf = $this->util->iniUtilities->getSection('db');
172 - $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', 'system_settings');  
173 $this->util->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); 172 $this->util->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']);
  173 +
  174 + $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', 'system_settings');
174 $result = $this->util->dbUtilities->query($query); 175 $result = $this->util->dbUtilities->query($query);
175 $assArr = $this->util->dbUtilities->fetchAssoc($result); 176 $assArr = $this->util->dbUtilities->fetchAssoc($result);
176 if ($result) { 177 if ($result) {
177 $lastVersion = $assArr[0]['value']; 178 $lastVersion = $assArr[0]['value'];
178 } 179 }
179 $currentVersion = $this->sysVersion; 180 $currentVersion = $this->sysVersion;
180 - require_once("lib/upgrade.inc.php"); 181 +
181 $upgrades = describeUpgrade($lastVersion, $currentVersion); 182 $upgrades = describeUpgrade($lastVersion, $currentVersion);
182 $ret = "<table border=1 cellpadding=1 cellspacing=1 width='100%'>\n"; 183 $ret = "<table border=1 cellpadding=1 cellspacing=1 width='100%'>\n";
183 $ret .= "<tr bgcolor='darkgrey'><th width='10'>Code</th><th width='100%'>Description</th><th width='30'>Applied</th></tr>\n"; 184 $ret .= "<tr bgcolor='darkgrey'><th width='10'>Code</th><th width='100%'>Description</th><th width='30'>Applied</th></tr>\n";