From 893a7930f3771b83ae4cef59d866f8028195d74e Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Wed, 19 Mar 2025 19:02:42 -0700 Subject: [PATCH] refactor: restructure ServerState class for update checks - Moved the initialization of `UnraidOsCheck` to a new method `initializeOsCheck()` for better organization. - Ensured that the update check runs before any other operations to guarantee the latest `var.ini` values are used. This change enhances the clarity and maintainability of the `ServerState` class. --- .../dynamix.my.servers/include/state.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php index 838b70f4f..9880b1196 100644 --- a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php +++ b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php @@ -105,15 +105,11 @@ class ServerState */ public function __construct() { - $this->updateOsCheck = new UnraidOsCheck(); /** - * This is positioned here to ensure that if during the UpdateOSCheck, which includes a ReplaceKeyCheck, - * that we get the latest var.ini values before anything else attempts to use them throughout the class. + * Run update check before any other operations to ensure + * var.ini has latest values after potential key replacements */ - $updateCheck = $this->shouldCheckForUpdates(); - if ($updateCheck) { - $this->updateOsCheck->checkForUpdate($updateCheck['forceReplaceKeyCheck']); - } + $this->initializeOsCheck(); /** * @note – necessary evil until full webgui is class based. * @see - getWebguiGlobal() for usage @@ -154,6 +150,16 @@ class ServerState $this->detectActivationCode(); } + private function initializeOsCheck(): void + { + $this->updateOsCheck = new UnraidOsCheck(); + + $updateCheck = $this->shouldCheckForUpdates(); + if ($updateCheck) { + $this->updateOsCheck->checkForUpdate($updateCheck['forceReplaceKeyCheck']); + } + } + /** * Retrieve the value of a webgui global setting. */