DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: Database update', DateTimeFormat::utcNow() . ' ' . date('e')));
}
+ // ensure that all initial values exist. This test has to be done prior and after the structure check.
+ // Prior is needed if the specific tables already exists - after is needed when they had been created.
+ self::checkInitialValues();
+
$errors = '';
Logger::log('updating structure', Logger::DEBUG);
View::create(false, $action);
+ self::checkInitialValues();
+
if ($action && !$install) {
DI::config()->set('system', 'maintenance', 0);
DI::config()->set('system', 'maintenance_reason', '');
private static function tableStructure($table)
{
// This query doesn't seem to be executable as a prepared statement
- $indexes = DBA::toArray(DBA::p(sprintf("SHOW INDEX FROM `%s`", $table)));
+ $indexes = DBA::toArray(DBA::p("SHOW INDEX FROM " . DBA::quoteIdentifier($table)));
$fields = DBA::selectToArray(['INFORMATION_SCHEMA' => 'COLUMNS'],
['COLUMN_NAME', 'COLUMN_TYPE', 'IS_NULLABLE', 'COLUMN_DEFAULT', 'EXTRA',
$fielddata[$field['COLUMN_NAME']]['type'] = $field['COLUMN_TYPE'];
if ($field['IS_NULLABLE'] == 'NO') {
- $fielddata[$field['COLUMN_NAME']]['not null'] = 1;
+ $fielddata[$field['COLUMN_NAME']]['not null'] = true;
}
if (isset($field['COLUMN_DEFAULT'])) {
}
if ($field['COLUMN_KEY'] == 'PRI') {
- $fielddata[$field['COLUMN_NAME']]['primary'] = 1;
+ $fielddata[$field['COLUMN_NAME']]['primary'] = true;
}
$fielddata[$field['COLUMN_NAME']]['Collation'] = $field['COLLATION_NAME'];
$stmtColumns = DBA::p("SHOW COLUMNS FROM `" . $table . "`");
return DBA::toArray($stmtColumns);
}
+
+ /**
+ * Check if initial database values do exist - or create them
+ */
+ public static function checkInitialValues()
+ {
+ if (DBA::tableExists('contact') && !DBA::exists('contact', ['id' => 0])) {
+ DBA::insert('contact', ['nurl' => '']);
+ $lastid = DBA::lastInsertId();
+ if ($lastid != 0) {
+ DBA::update('contact', ['id' => 0], ['id' => $lastid]);
+ }
+ }
+
+ if (DBA::tableExists('permissionset') && !DBA::exists('permissionset', ['id' => 0])) {
+ DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
+ $lastid = DBA::lastInsertId();
+ if ($lastid != 0) {
+ DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
+ }
+ }
+
+ if (DBA::tableExists('tag') && !DBA::exists('tag', ['id' => 0])) {
+ DBA::insert('tag', ['name' => '']);
+ $lastid = DBA::lastInsertId();
+ if ($lastid != 0) {
+ DBA::update('tag', ['id' => 0], ['id' => $lastid]);
+ }
+ }
+ }
}