Merge pull request #8640 from annando/annando/issue8635
Issue 8635: Avoid concurrent database updates
This commit is contained in:
commit
7b8178e046
1 changed files with 28 additions and 0 deletions
|
@ -292,6 +292,10 @@ 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)
|
||||||
{
|
{
|
||||||
if ($action && !$install) {
|
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', 1);
|
||||||
DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: Database update', DateTimeFormat::utcNow() . ' ' . date('e')));
|
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);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue