mirror of
https://github.com/friendica/friendica
synced 2024-11-20 01:03:41 +00:00
Avoid double update runs
This commit is contained in:
parent
d67ae7cbdd
commit
e46a7cdf80
1 changed files with 65 additions and 54 deletions
|
@ -68,26 +68,26 @@ class Update
|
||||||
Lock::release('dbupdate', true);
|
Lock::release('dbupdate', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$build = Config::get('system', 'build');
|
$current = intval(DB_UPDATE_VERSION);
|
||||||
|
$stored = self::getBuild();
|
||||||
|
|
||||||
if (empty($build) || ($build > DB_UPDATE_VERSION)) {
|
if ($stored < $current || $force) {
|
||||||
$build = DB_UPDATE_VERSION - 1;
|
|
||||||
Config::set('system', 'build', $build);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($build != DB_UPDATE_VERSION || $force) {
|
|
||||||
require_once 'update.php';
|
require_once 'update.php';
|
||||||
|
|
||||||
$stored = intval($build);
|
|
||||||
$current = intval(DB_UPDATE_VERSION);
|
|
||||||
if ($stored < $current || $force) {
|
|
||||||
Config::load('database');
|
Config::load('database');
|
||||||
|
|
||||||
Logger::log('Update from \'' . $stored . '\' to \'' . $current . '\' - starting', Logger::DEBUG);
|
Logger::log('Update from \'' . $stored . '\' to \'' . $current . '\' - starting', Logger::DEBUG);
|
||||||
|
|
||||||
// Compare the current structure with the defined structure
|
// Compare the current structure with the defined structure
|
||||||
// If the Lock is acquired, never release it automatically to avoid double updates
|
// If the Lock is acquired, never release it automatically to avoid double updates
|
||||||
if (Lock::acquire('dbupdate', 120, Cache::INFINITE)) {
|
if (Lock::acquire('dbupdate', 0, Cache::INFINITE)) {
|
||||||
|
|
||||||
|
// recheck again in case we accidentally spawned multiple updates
|
||||||
|
$stored = intval(self::getBuild());
|
||||||
|
if ($stored >= $current) {
|
||||||
|
Lock::release('dbupdate');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
// run the pre_update_nnnn functions in update.php
|
// run the pre_update_nnnn functions in update.php
|
||||||
for ($x = $stored + 1; $x <= $current; $x++) {
|
for ($x = $stored + 1; $x <= $current; $x++) {
|
||||||
|
@ -131,7 +131,6 @@ class Update
|
||||||
Lock::release('dbupdate');
|
Lock::release('dbupdate');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -293,4 +292,16 @@ class Update
|
||||||
//try the logger
|
//try the logger
|
||||||
Logger::log("Database structure update successful.", Logger::TRACE);
|
Logger::log("Database structure update successful.", Logger::TRACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function getBuild()
|
||||||
|
{
|
||||||
|
$build = Config::get('system', 'build');
|
||||||
|
|
||||||
|
if (empty($build) || ($build > DB_UPDATE_VERSION)) {
|
||||||
|
$build = DB_UPDATE_VERSION - 1;
|
||||||
|
Config::set('system', 'build', $build);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (is_int($build) ? intval($build) : DB_UPDATE_VERSION - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue