mirror of
https://github.com/unraid/webgui.git
synced 2026-01-08 02:29:51 -06:00
refactor: Simplify writeJsonFile method and adjust forceCheck logic in ReplaceKey
* Removed appending functionality from writeJsonFile for cleaner implementation. * Inverted condition for forceCheck to improve logic clarity.
This commit is contained in:
@@ -147,17 +147,12 @@ class ReplaceKey
|
||||
$KeyInstaller->installKey($key);
|
||||
}
|
||||
|
||||
private function writeJsonFile($file, $data, $append = false)
|
||||
private function writeJsonFile($file, $data)
|
||||
{
|
||||
if (!is_dir(dirname($file))) {
|
||||
mkdir(dirname($file));
|
||||
}
|
||||
|
||||
if ($append && file_exists($file)) {
|
||||
$existing = json_decode(file_get_contents($file), true) ?: [];
|
||||
$data = array_merge_recursive($existing, $data);
|
||||
}
|
||||
|
||||
file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
@@ -175,7 +170,7 @@ class ReplaceKey
|
||||
|
||||
$isWithinWindow = ($now >= $sevenDaysBefore && $now <= $sevenDaysAfter);
|
||||
|
||||
if ($forceCheck || $isWithinWindow) {
|
||||
if (!$forceCheck && !$isWithinWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -195,8 +190,7 @@ class ReplaceKey
|
||||
[
|
||||
'error' => 'Failed to retrieve latest key after getting a `hasNewerKeyfile` in the validation response.',
|
||||
'ts' => time(),
|
||||
],
|
||||
true,
|
||||
]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user