Ensure that the initial values are set
This commit is contained in:
parent
1efcee030e
commit
e333f45d0f
3 changed files with 56 additions and 0 deletions
|
@ -741,6 +741,17 @@ class DBA
|
||||||
return DI::dba()->processlist();
|
return DI::dba()->processlist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the given table exists
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function tableExists(string $table)
|
||||||
|
{
|
||||||
|
return DI::dba()->tableExists($table);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a database variable
|
* Fetch a database variable
|
||||||
*
|
*
|
||||||
|
|
|
@ -294,6 +294,10 @@ class DBStructure
|
||||||
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')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 = '';
|
$errors = '';
|
||||||
|
|
||||||
Logger::log('updating structure', Logger::DEBUG);
|
Logger::log('updating structure', Logger::DEBUG);
|
||||||
|
@ -640,6 +644,8 @@ class DBStructure
|
||||||
|
|
||||||
View::create(false, $action);
|
View::create(false, $action);
|
||||||
|
|
||||||
|
self::checkInitialValues();
|
||||||
|
|
||||||
if ($action && !$install) {
|
if ($action && !$install) {
|
||||||
DI::config()->set('system', 'maintenance', 0);
|
DI::config()->set('system', 'maintenance', 0);
|
||||||
DI::config()->set('system', 'maintenance_reason', '');
|
DI::config()->set('system', 'maintenance_reason', '');
|
||||||
|
@ -976,4 +982,31 @@ class DBStructure
|
||||||
$stmtColumns = DBA::p("SHOW COLUMNS FROM `" . $table . "`");
|
$stmtColumns = DBA::p("SHOW COLUMNS FROM `" . $table . "`");
|
||||||
return DBA::toArray($stmtColumns);
|
return DBA::toArray($stmtColumns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1660,6 +1660,18 @@ class Database
|
||||||
return (["list" => $statelist, "amount" => $processes]);
|
return (["list" => $statelist, "amount" => $processes]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the given table exists
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function tableExists(string $table)
|
||||||
|
{
|
||||||
|
return $this->exists(['information_schema' => 'tables'],
|
||||||
|
['table_name' => $table, 'table_schema' => $this->databaseName()]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a database variable
|
* Fetch a database variable
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue