From eb20a18fdbad9d4b314b560a1cd7290bcc03d455 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Tue, 6 Aug 2024 09:18:51 -0700 Subject: [PATCH] PHP cs fixes --- Maintenance/Maintenance.php | 5 ++-- Maintenance/Migration/MigrationBase.php | 6 ++--- Maintenance/Migration/v2_1/CreateAlerts.php | 1 - Maintenance/Tools/Upgrade.php | 30 ++++++++++----------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Maintenance/Maintenance.php b/Maintenance/Maintenance.php index 34cb9615d5..2c9a1b028b 100644 --- a/Maintenance/Maintenance.php +++ b/Maintenance/Maintenance.php @@ -766,6 +766,7 @@ public static function jsonResponse(mixed $data, bool $success = true): void // TODO: Improve this, move debug to the root. $debug_data = []; + if (Maintenance::$tool->isDebug()) { $debug_data = $data['debug']; } @@ -774,7 +775,7 @@ public static function jsonResponse(mixed $data, bool $success = true): void echo json_encode([ 'success' => $success, 'data' => $data, - 'debug' => $debug_data + 'debug' => $debug_data, ]); die; @@ -862,7 +863,7 @@ protected static function setThemeData(): void Config::$modSettings['theme_dir'] = empty(self::$theme_dir) ? Config::$boarddir . '/Themes/default' : self::$theme_dir; Config::$modSettings['theme_url'] = empty(self::$theme_url) ? 'Themes/default' : self::$theme_url; Config::$modSettings['images_url'] = empty(self::$images_url) ? 'Themes/default/images' : self::$images_url; - } + } } } diff --git a/Maintenance/Migration/MigrationBase.php b/Maintenance/Migration/MigrationBase.php index f4b7383174..c8fdc99f22 100644 --- a/Maintenance/Migration/MigrationBase.php +++ b/Maintenance/Migration/MigrationBase.php @@ -15,7 +15,6 @@ namespace SMF\Maintenance\Migration; -use Exception; use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Lang; @@ -139,15 +138,16 @@ protected function query(string $identifier, string $db_string, array $db_values } // If this is JSON, we can throw it, modern code will catch this. - else if (Maintenance::isJson()) { + if (Maintenance::isJson()) { $file = null; $line = null; + foreach (debug_backtrace() as $step) { $file = $step['file']; $line = $step['line']; break; } - + throw new \ErrorException($db_error_message, 0, E_USER_ERROR, $file, $line); } diff --git a/Maintenance/Migration/v2_1/CreateAlerts.php b/Maintenance/Migration/v2_1/CreateAlerts.php index 8d6dfc2ab0..b1af746d4d 100644 --- a/Maintenance/Migration/v2_1/CreateAlerts.php +++ b/Maintenance/Migration/v2_1/CreateAlerts.php @@ -15,7 +15,6 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Maintenance\Maintenance; use SMF\Maintenance\Migration\MigrationBase; diff --git a/Maintenance/Tools/Upgrade.php b/Maintenance/Tools/Upgrade.php index d40541b6b6..bab072b7db 100644 --- a/Maintenance/Tools/Upgrade.php +++ b/Maintenance/Tools/Upgrade.php @@ -1034,14 +1034,13 @@ public function migrations(): bool 'total' => Maintenance::$total_substeps, 'debug' => [ 'call' => basename($migrationFile), - ] + ], ], ); continue; } - } - catch (Exception $ex) { + } catch (Exception $ex) { Maintenance::jsonResponse( [ 'name' => $migration->name, @@ -1054,7 +1053,7 @@ public function migrations(): bool 'msg' => $ex->getMessage(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), - ] + ], ], ); @@ -1067,10 +1066,10 @@ public function migrations(): bool } $res = false; + try { $res = $migration->execute(); - } - catch (Exception $ex) { + } catch (Exception $ex) { Maintenance::jsonResponse( [ 'name' => $migration->name, @@ -1083,7 +1082,7 @@ public function migrations(): bool 'msg' => $ex->getMessage(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), - ] + ], ], ); @@ -1100,8 +1099,8 @@ public function migrations(): bool 'start' => Maintenance::getCurrentStart(), 'total' => Maintenance::$total_substeps, 'debug' => [ - 'call' => basename($migrationFile) - ] + 'call' => basename($migrationFile), + ], ], ); @@ -1127,8 +1126,8 @@ public function migrations(): bool 'start' => Maintenance::getCurrentStart(), 'total' => Maintenance::$total_substeps, 'debug' => [ - 'call' => basename($migrationFile) - ] + 'call' => basename($migrationFile), + ], ], ); } @@ -1231,10 +1230,11 @@ private function getUpgradeData(): void $defined_vars = Config::getCurrentSettings(); $data = []; + try { $data = isset($defined_vars['upgradeData']) ? Utils::jsonDecode(base64_decode($defined_vars['upgradeData']), true) : []; + } catch (Exception) { } - catch (Exception) {} $this->time_started = isset($data['started']) ? (int) $data['started'] : time(); $this->time_updated = isset($data['updated']) ? (int) $data['updated'] : time(); @@ -1412,7 +1412,7 @@ private function toggleSmStats(array &$settings): void /** * Get the name of the next migration, if any. - * + * * @param int $substep Substep we are looking for * @param array $files All files that we are running. */ @@ -1425,9 +1425,9 @@ private function getNextMigrationName(int $substep, array $files): string $migrationFile = $files[$substep]; $migration = new $migrationFile(); + return $migration->name; - } - catch (Exception) { + } catch (Exception) { return ''; } }