Fix setting current database version in the Updater

This commit is contained in:
Dmitriy Simushev 2015-01-26 12:17:52 +00:00
parent 84b0d891e0
commit 626145340e

View File

@ -109,6 +109,12 @@ class Updater
return false; return false;
} }
if (version_compare($current_version, MIBEW_VERSION) == 0) {
$this->log[] = getlocal('The database is already up to date');
return true;
}
if (version_compare($current_version, self::MIN_VERSION) < 0) { if (version_compare($current_version, self::MIN_VERSION) < 0) {
$this->errors[] = getlocal( $this->errors[] = getlocal(
'You can update the system only from {0} and later versions. The current version is {1}', 'You can update the system only from {0} and later versions. The current version is {1}',
@ -121,21 +127,9 @@ class Updater
return false; return false;
} }
// Get list of all available updates
$updates = Utils::getUpdates($this);
// Check if updates should be performed
$versions = array_keys($updates);
$last_version = end($versions);
if (version_compare($current_version, $last_version) >= 0) {
$this->log[] = getlocal('The database is already up to date');
return true;
}
try { try {
// Perform incremental updates // Perform incremental updates
foreach ($updates as $version => $method) { foreach (Utils::getUpdates($this) as $version => $method) {
if (version_compare($version, $current_version) <= 0) { if (version_compare($version, $current_version) <= 0) {
// Skip updates to lower versions. // Skip updates to lower versions.
continue; continue;
@ -152,8 +146,6 @@ class Updater
// we can rerun the updating process if one of pending // we can rerun the updating process if one of pending
// updates fails. // updates fails.
if (!$this->setDatabaseVersion($version)) { if (!$this->setDatabaseVersion($version)) {
$this->errors[] = getlocal('Cannot store new version number');
return false; return false;
} else { } else {
$this->log[] = getlocal('Updated to {0}', array($version)); $this->log[] = getlocal('Updated to {0}', array($version));
@ -171,6 +163,12 @@ class Updater
return false; return false;
} }
// Use the version from the PHP's constant as the current database
// version.
if ($this->setDatabaseVersion(MIBEW_VERSION)) {
return false;
}
// Clean up the cache // Clean up the cache
$this->cache->flush(); $this->cache->flush();
@ -255,6 +253,8 @@ class Updater
); );
} catch (\Exception $e) { } catch (\Exception $e) {
// The query fails by some reason. // The query fails by some reason.
$this->errors[] = getlocal('Cannot store new version number');
return false; return false;
} }
} }