diff options
Diffstat (limited to 'private/hooks.php')
-rw-r--r-- | private/hooks.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/private/hooks.php b/private/hooks.php index 518582e..91521b4 100644 --- a/private/hooks.php +++ b/private/hooks.php @@ -27,4 +27,37 @@ foreach ($profiles as $profile) { } } +$unused = []; + +echo("\nCleaning orphan files..."); +foreach (scandir("./shares") as $sfile) { + if ($sfile !== "." && $sfile !== "..") { + echo("\nProcessing file: " . $sfile); + $fileIsUsed = false; + foreach ($profiles as $profile) { + if ($profile !== "." && $profile !== ".." && $profile !== "_base.json") { + echo("\nProcessing profile: " . $profile); + $staging = json_decode(file_get_contents("./profiles/" . $profile), true); + foreach ($staging['files'] as $index=>$file) { + echo("\nProcessing file: " . $file['id']); + if (trim($file["file"]) === trim($sfile)) { + $fileIsUsed = true; + } + } + } + } + + if (!$fileIsUsed) { + echo("\nNo usage found, marking file as orphan"); + $unused[] = $sfile; + } + } +} + +echo("\nDeleting " . count($unused) . " orphan file(s)..."); +foreach ($unused as $file) { + echo("\n -> " . $file); + unlink("./shares/" . $file); +} + echo("\nDone!\n");
\ No newline at end of file |