From: Michael Date: Sat, 16 May 2020 08:15:51 +0000 (+0000) Subject: Issue 8635: Avoid concurrent database updates X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4e1b1c0811763b82bb69cb1c62574df7a16a315d;p=friendica.git Issue 8635: Avoid concurrent database updates Possibly helps with #8635 --- diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 0ff97d0c6c..9f225cbb93 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -291,6 +291,12 @@ class DBStructure */ public static function update($basePath, $verbose, $action, $install = false, array $tables = null, array $definition = null) { + if (!$install) { + if (self::isUpdating()) { + return DI::l10n()->t('Another database update is currently running.'); + } + } + if ($action && !$install) { DI::config()->set('system', 'maintenance', 1); DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: Database update', DateTimeFormat::utcNow() . ' ' . date('e'))); @@ -1060,4 +1066,31 @@ class DBStructure DBA::close($tokens); } } + + /** + * Checks if a database update is currently running + * + * @return boolean + */ + private static function isUpdating() + { + $processes = DBA::select(['information_schema' => 'processlist'], + ['command', 'info'], ['db' => DBA::databaseName()]); + + $isUpdate = false; + + while ($process = DBA::fetch($processes)) { + if (empty($process['info'])) { + continue; + } + $parts = explode(' ', $process['info']); + $command = strtolower(array_shift($parts)); + if ($command == 'alter') { + $isUpdate = true; + } + } + DBA::close($processes); + + return $isUpdate; + } }