From 80869a032cea028628aa7865059e482107058158 Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Thu, 20 Mar 2025 12:31:04 -0700 Subject: [PATCH] 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. --- emhttp/plugins/dynamix/include/ReplaceKey.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/emhttp/plugins/dynamix/include/ReplaceKey.php b/emhttp/plugins/dynamix/include/ReplaceKey.php index 4071c6b33..b6d7439ab 100644 --- a/emhttp/plugins/dynamix/include/ReplaceKey.php +++ b/emhttp/plugins/dynamix/include/ReplaceKey.php @@ -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; }