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.
This commit is contained in:
Zack Spear
2025-03-19 19:02:42 -07:00
parent d34771a038
commit 893a7930f3

View File

@@ -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.
*/