Setting "maintenance" for pre and post updates
This commit is contained in:
parent
43f0f6bbdc
commit
90f1175cf5
|
@ -27,6 +27,7 @@ use Friendica\Database\DBA;
|
||||||
use Friendica\Database\DBStructure;
|
use Friendica\Database\DBStructure;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
class Update
|
class Update
|
||||||
|
@ -143,14 +144,20 @@ class Update
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DI::config()->set('system', 'maintenance', 1);
|
||||||
|
|
||||||
// run the pre_update_nnnn functions in update.php
|
// run the pre_update_nnnn functions in update.php
|
||||||
for ($version = $stored + 1; $version <= $current; $version++) {
|
for ($version = $stored + 1; $version <= $current; $version++) {
|
||||||
Logger::notice('Execute pre update.', ['version' => $version]);
|
Logger::notice('Execute pre update.', ['version' => $version]);
|
||||||
|
DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: executing pre update %d',
|
||||||
|
DateTimeFormat::utcNow() . ' ' . date('e'), $version));
|
||||||
$r = self::runUpdateFunction($version, 'pre_update', $sendMail);
|
$r = self::runUpdateFunction($version, 'pre_update', $sendMail);
|
||||||
if (!$r) {
|
if (!$r) {
|
||||||
Logger::warning('Pre update failed', ['version' => $version]);
|
Logger::warning('Pre update failed', ['version' => $version]);
|
||||||
DI::config()->set('system', 'update', Update::FAILED);
|
DI::config()->set('system', 'update', Update::FAILED);
|
||||||
DI::lock()->release('dbupdate');
|
DI::lock()->release('dbupdate');
|
||||||
|
DI::config()->set('system', 'maintenance', 0);
|
||||||
|
DI::config()->set('system', 'maintenance_reason', '');
|
||||||
return $r;
|
return $r;
|
||||||
} else {
|
} else {
|
||||||
Logger::notice('Pre update executed.', ['version' => $version]);
|
Logger::notice('Pre update executed.', ['version' => $version]);
|
||||||
|
@ -170,6 +177,8 @@ class Update
|
||||||
Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]);
|
Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]);
|
||||||
DI::config()->set('system', 'update', Update::FAILED);
|
DI::config()->set('system', 'update', Update::FAILED);
|
||||||
DI::lock()->release('dbupdate');
|
DI::lock()->release('dbupdate');
|
||||||
|
DI::config()->set('system', 'maintenance', 0);
|
||||||
|
DI::config()->set('system', 'maintenance_reason', '');
|
||||||
return $retval;
|
return $retval;
|
||||||
} else {
|
} else {
|
||||||
Logger::notice('Database structure update finished.', ['from' => $stored, 'to' => $current]);
|
Logger::notice('Database structure update finished.', ['from' => $stored, 'to' => $current]);
|
||||||
|
@ -178,11 +187,15 @@ class Update
|
||||||
// run the update_nnnn functions in update.php
|
// run the update_nnnn functions in update.php
|
||||||
for ($version = $stored + 1; $version <= $current; $version++) {
|
for ($version = $stored + 1; $version <= $current; $version++) {
|
||||||
Logger::notice('Execute post update.', ['version' => $version]);
|
Logger::notice('Execute post update.', ['version' => $version]);
|
||||||
|
DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: executing post update %d',
|
||||||
|
DateTimeFormat::utcNow() . ' ' . date('e'), $version));
|
||||||
$r = self::runUpdateFunction($version, 'update', $sendMail);
|
$r = self::runUpdateFunction($version, 'update', $sendMail);
|
||||||
if (!$r) {
|
if (!$r) {
|
||||||
Logger::warning('Post update failed', ['version' => $version]);
|
Logger::warning('Post update failed', ['version' => $version]);
|
||||||
DI::config()->set('system', 'update', Update::FAILED);
|
DI::config()->set('system', 'update', Update::FAILED);
|
||||||
DI::lock()->release('dbupdate');
|
DI::lock()->release('dbupdate');
|
||||||
|
DI::config()->set('system', 'maintenance', 0);
|
||||||
|
DI::config()->set('system', 'maintenance_reason', '');
|
||||||
return $r;
|
return $r;
|
||||||
} else {
|
} else {
|
||||||
DI::config()->set('system', 'build', $version);
|
DI::config()->set('system', 'build', $version);
|
||||||
|
@ -193,6 +206,8 @@ class Update
|
||||||
DI::config()->set('system', 'build', $current);
|
DI::config()->set('system', 'build', $current);
|
||||||
DI::config()->set('system', 'update', Update::SUCCESS);
|
DI::config()->set('system', 'update', Update::SUCCESS);
|
||||||
DI::lock()->release('dbupdate');
|
DI::lock()->release('dbupdate');
|
||||||
|
DI::config()->set('system', 'maintenance', 0);
|
||||||
|
DI::config()->set('system', 'maintenance_reason', '');
|
||||||
|
|
||||||
Logger::notice('Update success.', ['from' => $stored, 'to' => $current]);
|
Logger::notice('Update success.', ['from' => $stored, 'to' => $current]);
|
||||||
if ($sendMail) {
|
if ($sendMail) {
|
||||||
|
|
|
@ -375,6 +375,8 @@ class DBStructure
|
||||||
*/
|
*/
|
||||||
public static function update($basePath, $verbose, $action, $install = false, array $tables = null, array $definition = null)
|
public static function update($basePath, $verbose, $action, $install = false, array $tables = null, array $definition = null)
|
||||||
{
|
{
|
||||||
|
$in_maintenance = DI::config()->get('system', 'maintenance');
|
||||||
|
|
||||||
if ($action && !$install) {
|
if ($action && !$install) {
|
||||||
if (self::isUpdating()) {
|
if (self::isUpdating()) {
|
||||||
return DI::l10n()->t('Another database update is currently running.');
|
return DI::l10n()->t('Another database update is currently running.');
|
||||||
|
@ -737,8 +739,10 @@ class DBStructure
|
||||||
self::checkInitialValues();
|
self::checkInitialValues();
|
||||||
|
|
||||||
if ($action && !$install) {
|
if ($action && !$install) {
|
||||||
|
if (!$in_maintenance) {
|
||||||
DI::config()->set('system', 'maintenance', 0);
|
DI::config()->set('system', 'maintenance', 0);
|
||||||
DI::config()->set('system', 'maintenance_reason', '');
|
DI::config()->set('system', 'maintenance_reason', '');
|
||||||
|
}
|
||||||
|
|
||||||
if ($errors) {
|
if ($errors) {
|
||||||
DI::config()->set('system', 'dbupdate', self::UPDATE_FAILED);
|
DI::config()->set('system', 'dbupdate', self::UPDATE_FAILED);
|
||||||
|
|
Loading…
Reference in a new issue