From 925c30280c853c152f465d64065a6749ec5939fa Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 29 Dec 2022 22:12:02 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Hypolite Petovan --- .../KeyValueStorage/Type/DBKeyValueStorage.php | 4 +--- src/Database/DBStructure.php | 14 +++++++------- src/Module/Admin/Summary.php | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Core/KeyValueStorage/Type/DBKeyValueStorage.php b/src/Core/KeyValueStorage/Type/DBKeyValueStorage.php index 1d7040c04..60e6087e2 100644 --- a/src/Core/KeyValueStorage/Type/DBKeyValueStorage.php +++ b/src/Core/KeyValueStorage/Type/DBKeyValueStorage.php @@ -104,9 +104,7 @@ class DBKeyValueStorage extends AbstractKeyValueStorage public function offsetUnset($offset) { try { - $return = $this->database->delete(self::DB_KEY_VALUE_TABLE, ['k' => $offset]); - - if (!$return) { + if (!$this->database->delete(self::DB_KEY_VALUE_TABLE, ['k' => $offset])) { throw new \Exception(sprintf('database deletion failed: %s', $this->database->errorMessage())); } } catch (\Exception $exception) { diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 83e238394..734046afb 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -53,7 +53,7 @@ class DBStructure 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); } @@ -176,14 +176,14 @@ class DBStructure public static function performUpdate(bool $enable_maintenance_mode = true, bool $verbose = false): string { if ($enable_maintenance_mode) { - DI::keyValue()->set( 'maintenance', 1); + DI::keyValue()->set('maintenance', 1); } $status = self::update($verbose, true); if ($enable_maintenance_mode) { - DI::keyValue()->set( 'maintenance', 0); - DI::keyValue()->set( 'maintenance_reason', ''); + DI::keyValue()->set('maintenance', 0); + DI::keyValue()->set('maintenance_reason', ''); } return $status; @@ -213,7 +213,7 @@ class DBStructure */ 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::keyValue()->get('system', 'maintenance'); if ($action && !$install && self::isUpdating()) { return DI::l10n()->t('Another database update is currently running.'); @@ -494,9 +494,9 @@ class DBStructure 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); } } diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 42098c95c..46f9d440b 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -98,7 +98,7 @@ class Summary extends BaseAdmin $warningtext[] = DI::l10n()->t('The last update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear. (Some of the errors are possibly inside the logfile.)'); } - $last_worker_call = DI::keyValue()->get('last_worker_execution') ?? false; + $last_worker_call = DI::keyValue()->get('last_worker_execution'); if (!$last_worker_call) { $warningtext[] = DI::l10n()->t('The worker was never executed. Please check your database structure!'); } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {