<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
throw new \Asika\SimpleConsole\CommandArgsException('The version number must be numeric');
}
- DI::keyValue()->set( 'build', $version);
+ DI::keyValue()->set('build', $version);
echo DI::l10n()->t('The database version had been set to %s.', $version);
}
+ /**
+ * Drops a specific table
+ *
+ * @param string $table the table name
+ *
+ * @return bool true if possible, otherwise false
+ */
+ public static function dropTable(string $table): bool
+ {
+ return DBA::isResult(DBA::e('DROP TABLE ' . DBA::quoteIdentifier($table) . ';'));
+ }
+
/**
* Drop unused tables
*
$old_tables = ['fserver', 'gcign', 'gcontact', 'gcontact-relation', 'gfollower' ,'glink', 'item-delivery-data',
'item-activity', 'item-content', 'item_id', 'participation', 'poll', 'poll_result', 'queue', 'retriever_rule',
'deliverq', 'dsprphotoq', 'ffinder', 'sign', 'spam', 'term', 'user-item', 'thread', 'item', 'challenge',
- 'auth_codes', 'tokens', 'clients', 'profile_check', 'host', 'conversation', 'fcontact'];
+ 'auth_codes', 'tokens', 'clients', 'profile_check', 'host', 'conversation', 'fcontact', 'addon'];
$tables = DBA::selectToArray('INFORMATION_SCHEMA.TABLES', ['TABLE_NAME'],
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);
$sql = 'DROP TABLE ' . DBA::quoteIdentifier($table) . ';';
echo $sql . "\n";
- $result = DBA::e($sql);
- if (!DBA::isResult($result)) {
+ if (!static::dropTable($table)) {
self::printUpdateError($sql);
}
} else {
public static function performUpdate(bool $enable_maintenance_mode = true, bool $verbose = false): string
{
if ($enable_maintenance_mode) {
- DI::keyValue()->set( 'maintenance', 1);
+ DI::config()->set('system', 'maintenance', true);
}
$status = self::update($verbose, true);
if ($enable_maintenance_mode) {
- DI::keyValue()->set( 'maintenance', 0);
- DI::keyValue()->set( 'maintenance_reason', '');
+ DI::config()->beginTransaction()
+ ->set('system', 'maintenance', false)
+ ->delete('system', 'maintenance_reason')
+ ->commit();
}
return $status;
*/
private static function update(bool $verbose, bool $action, bool $install = false, array $tables = null, array $definition = null): string
{
- $in_maintenance_mode = DI::keyValue()->get('system', 'maintenance');
+ $in_maintenance_mode = DI::config()->get('system', 'maintenance');
if ($action && !$install && self::isUpdating()) {
return DI::l10n()->t('Another database update is currently running.');
if ($action && !$install) {
if ($errors) {
- DI::config()->set('system', 'dbupdate', self::UPDATE_FAILED);
+ DI::config()->set('system', 'dbupdate', self::UPDATE_FAILED);
} else {
- DI::config()->set( 'system', 'dbupdate', self::UPDATE_SUCCESSFUL);
+ DI::config()->set('system', 'dbupdate', self::UPDATE_SUCCESSFUL);
}
}
}
if (!DBA::exists('verb', ['id' => 0])) {
- DBA::insert('verb', ['name' => '']);
+ DBA::insert('verb', ['name' => ''], Database::INSERT_IGNORE);
$lastid = DBA::lastInsertId();
if ($lastid != 0) {
DBA::update('verb', ['id' => 0], ['id' => $lastid]);
}
if (self::existsTable('contact') && !DBA::exists('contact', ['id' => 0])) {
- DBA::insert('contact', ['nurl' => '']);
+ DBA::insert('contact', ['nurl' => ''], Database::INSERT_IGNORE);
$lastid = DBA::lastInsertId();
if ($lastid != 0) {
DBA::update('contact', ['id' => 0], ['id' => $lastid]);
}
if (self::existsTable('tag') && !DBA::exists('tag', ['id' => 0])) {
- DBA::insert('tag', ['name' => '']);
+ DBA::insert('tag', ['name' => ''], Database::INSERT_IGNORE);
$lastid = DBA::lastInsertId();
if ($lastid != 0) {
DBA::update('tag', ['id' => 0], ['id' => $lastid]);
if (self::existsTable('permissionset')) {
if (!DBA::exists('permissionset', ['id' => 0])) {
- DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
+ DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''], Database::INSERT_IGNORE);
$lastid = DBA::lastInsertId();
if ($lastid != 0) {
DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
}
$fields = ['id' => $set['psid'], 'uid' => $set['uid'], 'allow_cid' => $permission,
'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''];
- DBA::insert('permissionset', $fields);
+ DBA::insert('permissionset', $fields, Database::INSERT_IGNORE);
}
DBA::close($sets);
}