*/
public static function update($basePath, $verbose, $action, $install = false, array $tables = null, array $definition = null)
{
- if (!$install) {
+ if ($action && !$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')));
}
}
}
- foreach ($existing_foreign_keys as $constraint => $param) {
- $sql2 = self::dropForeignKey($constraint);
+ foreach ($existing_foreign_keys as $param) {
+ $sql2 = self::dropForeignKey($param['CONSTRAINT_NAME']);
if ($sql3 == "") {
$sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
if (DBA::isResult($foreign_keys)) {
foreach ($foreign_keys as $foreign_key) {
- $constraint = $foreign_key['CONSTRAINT_NAME'];
- unset($foreign_key['CONSTRAINT_NAME']);
+ $parameters = ['foreign' => [$foreign_key['REFERENCED_TABLE_NAME'] => $foreign_key['REFERENCED_COLUMN_NAME']]];
+ $constraint = self::getConstraintName($table, $foreign_key['COLUMN_NAME'], $parameters);
$foreigndata[$constraint] = $foreign_key;
}
}
$fielddata[$field['COLUMN_NAME']]['not null'] = true;
}
- if (isset($field['COLUMN_DEFAULT'])) {
- $fielddata[$field['COLUMN_NAME']]['default'] = $field['COLUMN_DEFAULT'];
+ if (isset($field['COLUMN_DEFAULT']) && ($field['COLUMN_DEFAULT'] != 'NULL')) {
+ $fielddata[$field['COLUMN_NAME']]['default'] = trim($field['COLUMN_DEFAULT'], "'");
}
if (!empty($field['EXTRA'])) {
$foreign_table = array_keys($parameters['foreign'])[0];
$foreign_field = array_values($parameters['foreign'])[0];
- $constraint = self::getConstraintName($tablename, $fieldname, $parameters);
-
- $sql = "CONSTRAINT `" . $constraint . "` FOREIGN KEY (`" . $fieldname . "`)" .
- " REFERENCES `" . $foreign_table . "` (`" . $foreign_field . "`)";
+ $sql = "FOREIGN KEY (`" . $fieldname . "`) REFERENCES `" . $foreign_table . "` (`" . $foreign_field . "`)";
if (!empty($parameters['foreign']['on update'])) {
$sql .= " ON UPDATE " . strtoupper($parameters['foreign']['on update']);
*/
public static function checkInitialValues()
{
+ if (self::existsTable('verb') && !DBA::exists('verb', ['id' => 1])) {
+ foreach (Item::ACTIVITIES as $index => $activity) {
+ DBA::insert('verb', ['id' => $index + 1, 'name' => $activity], true);
+ }
+ }
+
if (self::existsTable('contact') && !DBA::exists('contact', ['id' => 0])) {
DBA::insert('contact', ['nurl' => '']);
$lastid = DBA::lastInsertId();
*/
private static function isUpdating()
{
- $processes = DBA::select(['information_schema' => 'processlist'],
- ['command', 'info'], ['db' => DBA::databaseName()]);
-
$isUpdate = false;
+ $processes = DBA::select(['information_schema' => 'processlist'], ['info'],
+ ['db' => DBA::databaseName(), 'command' => ['Query', 'Execute']]);
+
while ($process = DBA::fetch($processes)) {
- if (empty($process['info'])) {
- continue;
- }
$parts = explode(' ', $process['info']);
- $command = strtolower(array_shift($parts));
- if ($command == 'alter') {
+ if (in_array(strtolower(array_shift($parts)), ['alter', 'create', 'drop', 'rename'])) {
$isUpdate = true;
}
}
+
DBA::close($processes);
return $isUpdate;