Merge pull request #8640 from annando/annando/issue8635

Issue 8635: Avoid concurrent database updates
This commit is contained in:
Hypolite Petovan 2020-05-16 08:04:18 -04:00 committed by GitHub
commit 7b8178e046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 0 deletions

View File

@ -292,6 +292,10 @@ class DBStructure
public static function update($basePath, $verbose, $action, $install = false, array $tables = null, array $definition = null)
{
if ($action && !$install) {
if (self::isUpdating()) {
return DI::l10n()->t('Another database update is currently running.');
}
DI::config()->set('system', 'maintenance', 1);
DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: Database update', DateTimeFormat::utcNow() . ' ' . date('e')));
}
@ -1060,4 +1064,28 @@ class DBStructure
DBA::close($tokens);
}
}
/**
* Checks if a database update is currently running
*
* @return boolean
*/
private static function isUpdating()
{
$isUpdate = false;
$processes = DBA::select(['information_schema' => 'processlist'], ['info'],
['db' => DBA::databaseName(), 'command' => ['Query', 'Execute']]);
while ($process = DBA::fetch($processes)) {
$parts = explode(' ', $process['info']);
if (in_array(strtolower(array_shift($parts)), ['alter', 'create', 'drop', 'rename'])) {
$isUpdate = true;
}
}
DBA::close($processes);
return $isUpdate;
}
}