X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FUpdate.php;h=2718d03d0c3318d69e33e0fd84b28e2ac325cf09;hb=5704a433f00887b35fe866af6b161b096b27f9d9;hp=8ec96dc9893662d68216900712c29ad015e3cd78;hpb=fe547b7851e5175aed1e9335f265ea25b24bca7c;p=friendica.git diff --git a/src/Core/Update.php b/src/Core/Update.php index 8ec96dc989..2718d03d0c 100644 --- a/src/Core/Update.php +++ b/src/Core/Update.php @@ -1,6 +1,6 @@ get('system', 'update', Update::SUCCESS, true) == Update::FAILED) { + if (DI::config()->get('system', 'update', Update::SUCCESS) == Update::FAILED) { return; } $build = DI::config()->get('system', 'build'); if (empty($build)) { - DI::config()->set('system', 'build', DB_UPDATE_VERSION - 1); - $build = DB_UPDATE_VERSION - 1; + // legacy option - check if there's something in the Config table + if (DBStructure::existsTable('config')) { + $dbConfig = DBA::selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'build']); + if (!empty($dbConfig)) { + $build = $dbConfig['v']; + } + } + + if (empty($build)) { + DI::config()->set('system', 'build', DB_UPDATE_VERSION - 1); + $build = DB_UPDATE_VERSION - 1; + } } // We don't support upgrading from very old versions anymore @@ -76,7 +86,7 @@ class Update } // The postupdate has to completed version 1288 for the new post views to take over - $postupdate = DI::config()->get('system', 'post_update_version', self::NEW_TABLE_STRUCTURE_VERSION); + $postupdate = DI::keyValue()->get('post_update_version') ?? self::NEW_TABLE_STRUCTURE_VERSION; if ($postupdate < self::NEW_TABLE_STRUCTURE_VERSION) { $error = DI::l10n()->t('Updates from postupdate version %s are not supported. Please update at least to version 2021.01 and wait until the postupdate finished version 1383.', $postupdate); if (DI::mode()->getExecutor() == Mode::INDEX) { @@ -119,11 +129,18 @@ class Update DI::lock()->release('dbupdate', true); } - $build = DI::config()->get('system', 'build', null, true); + $build = DI::config()->get('system', 'build'); + + if (empty($build)) { + $dbConfig = DBA::selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'build']); + if (!empty($dbConfig)) { + $build = $dbConfig['v']; + } - if (empty($build) || ($build > DB_UPDATE_VERSION)) { - $build = DB_UPDATE_VERSION - 1; - DI::config()->set('system', 'build', $build); + if (empty($build) || ($build > DB_UPDATE_VERSION)) { + DI::config()->set('system', 'build', DB_UPDATE_VERSION - 1); + $build = DB_UPDATE_VERSION - 1; + } } if ($build != DB_UPDATE_VERSION || $force) { @@ -132,7 +149,7 @@ class Update $stored = intval($build); $current = intval(DB_UPDATE_VERSION); if ($stored < $current || $force) { - DI::config()->load('database'); + DI::config()->reload(); // Compare the current structure with the defined structure // If the Lock is acquired, never release it automatically to avoid double updates @@ -141,11 +158,21 @@ class Update Logger::notice('Update starting.', ['from' => $stored, 'to' => $current]); // Checks if the build changed during Lock acquiring (so no double update occurs) - $retryBuild = DI::config()->get('system', 'build', null, true); - if ($retryBuild !== $build) { - Logger::notice('Update already done.', ['from' => $stored, 'to' => $current]); - DI::lock()->release('dbupdate'); - return ''; + $retryBuild = DI::config()->get('system', 'build'); + if ($retryBuild != $build) { + // legacy option - check if there's something in the Config table + if (DBStructure::existsTable('config')) { + $dbConfig = DBA::selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'build']); + if (!empty($dbConfig)) { + $retryBuild = intval($dbConfig['v']); + } + } + + if ($retryBuild != $build) { + Logger::notice('Update already done.', ['from' => $build, 'retry' => $retryBuild, 'to' => $current]); + DI::lock()->release('dbupdate'); + return ''; + } } DI::config()->set('system', 'maintenance', 1); @@ -160,8 +187,10 @@ class Update Logger::warning('Pre update failed', ['version' => $version]); DI::config()->set('system', 'update', Update::FAILED); DI::lock()->release('dbupdate'); - DI::config()->set('system', 'maintenance', 0); - DI::config()->set('system', 'maintenance_reason', ''); + DI::config()->beginTransaction() + ->set('system', 'maintenance', false) + ->delete('system', 'maintenance_reason') + ->commit(); return $r; } else { Logger::notice('Pre update executed.', ['version' => $version]); @@ -181,8 +210,10 @@ class Update Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]); DI::config()->set('system', 'update', Update::FAILED); DI::lock()->release('dbupdate'); - DI::config()->set('system', 'maintenance', 0); - DI::config()->set('system', 'maintenance_reason', ''); + DI::config()->beginTransaction() + ->set('system', 'maintenance', false) + ->delete('system', 'maintenance_reason') + ->commit(); return $retval; } else { Logger::notice('Database structure update finished.', ['from' => $stored, 'to' => $current]); @@ -198,8 +229,10 @@ class Update Logger::warning('Post update failed', ['version' => $version]); DI::config()->set('system', 'update', Update::FAILED); DI::lock()->release('dbupdate'); - DI::config()->set('system', 'maintenance', 0); - DI::config()->set('system', 'maintenance_reason', ''); + DI::config()->beginTransaction() + ->set('system', 'maintenance', false) + ->delete('system', 'maintenance_reason') + ->commit(); return $r; } else { DI::config()->set('system', 'build', $version); @@ -210,8 +243,10 @@ class Update DI::config()->set('system', 'build', $current); DI::config()->set('system', 'update', Update::SUCCESS); DI::lock()->release('dbupdate'); - DI::config()->set('system', 'maintenance', 0); - DI::config()->set('system', 'maintenance_reason', ''); + DI::config()->beginTransaction() + ->set('system', 'maintenance', false) + ->delete('system', 'maintenance_reason') + ->commit(); Logger::notice('Update success.', ['from' => $stored, 'to' => $current]); if ($sendMail) {