Skip to content

Commit 6f0af9e

Browse files
committed
feat: Enhance writeJsonFile to support appending data
1 parent d176b5b commit 6f0af9e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

emhttp/plugins/dynamix/include/ReplaceKey.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,17 @@ private function installNewKey($key)
147147
$KeyInstaller->installKey($key);
148148
}
149149

150-
private function writeJsonFile($file, $data)
150+
private function writeJsonFile($file, $data, $append = false)
151151
{
152-
if (!is_dir(dirname($file))) { // prevents errors when directory doesn't exist
152+
if (!is_dir(dirname($file))) {
153153
mkdir(dirname($file));
154154
}
155+
156+
if ($append && file_exists($file)) {
157+
$existing = json_decode(file_get_contents($file), true) ?: [];
158+
$data = array_merge_recursive($existing, $data);
159+
}
160+
155161
file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
156162
}
157163

@@ -188,7 +194,9 @@ public function check(bool $forceCheck = false)
188194
'/tmp/ReplaceKey/error.json',
189195
[
190196
'error' => 'Failed to retrieve latest key after getting a `hasNewerKeyfile` in the validation response.',
191-
]
197+
'ts' => time(),
198+
],
199+
true,
192200
);
193201
return;
194202
}

0 commit comments

Comments
 (0)