diff options
Diffstat (limited to 'includes/maintenance/deleteUnusedAssets.php')
-rw-r--r-- | includes/maintenance/deleteUnusedAssets.php | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/includes/maintenance/deleteUnusedAssets.php b/includes/maintenance/deleteUnusedAssets.php deleted file mode 100644 index 0c195a2..0000000 --- a/includes/maintenance/deleteUnusedAssets.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -global $action; -if (!isset($_SERVER['DOCUMENT_ROOT']) || $_SERVER['DOCUMENT_ROOT'] === "") $_SERVER['DOCUMENT_ROOT'] = "../.."; -if (!isset($action)) $action = "list"; - -if (isset($_SERVER["argv"][1])) { - if ($_SERVER['argv'][1] === "archive") { - $action = "archive"; - } elseif ($_SERVER['argv'][1] === "delete") { - $action = "delete"; - } -} - -$list = [ - str_replace("-", "", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/general.json"), true)["uuid"]), - str_replace("-", "", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/hrbom/general.json"), true)["uuid"]), - str_replace("-", "", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/general.json"), true)["uuid"]), - ...array_map(function ($i) { - return str_replace("-", "", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/general.json"), true)["uuid"]) . str_replace("-", "", $i["uuid"]); - }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true)), - ...array_map(function ($i) { - return str_replace("-", "", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/hrbom/general.json"), true)["uuid"]) . str_replace("-", "", $i["uuid"]); - }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/hrbom/members.json"), true)), - ...array_map(function ($i) { - return str_replace("-", "", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/general.json"), true)["uuid"]) . str_replace("-", "", $i["uuid"]); - }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/members.json"), true)) -]; - -$count = 0; -$left = 0; - -$list = [ - ...array_map(function ($i) { - return $i . ".webp"; - }, $list), - ...array_map(function ($i) { - return $i . ".png"; - }, $list) -]; - -if ($action === "archive") { - if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/archive")) mkdir($_SERVER["DOCUMENT_ROOT"] . "/assets/archive"); - if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/archive/heads")) mkdir($_SERVER["DOCUMENT_ROOT"] . "/assets/archive/heads"); - if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/archive/bodies")) mkdir($_SERVER["DOCUMENT_ROOT"] . "/assets/archive/bodies"); - if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/archive/banners")) mkdir($_SERVER["DOCUMENT_ROOT"] . "/assets/archive/banners"); - if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/archive/avatars")) mkdir($_SERVER["DOCUMENT_ROOT"] . "/assets/archive/avatars"); -} - -foreach (["heads", "bodies", "banners", "avatars"] as $t) { - foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/assets/$t"), function ($i) { - return !str_starts_with($i, "."); - }) as $file) { - if (!in_array($file, $list)) { - echo($file . "\n"); - $count++; - - if ($action === "archive") { - rename($_SERVER['DOCUMENT_ROOT'] . "/assets/$t/" . $file, $_SERVER['DOCUMENT_ROOT'] . "/assets/archive/$t/" . $file); - } elseif ($action === "delete") { - unlink($_SERVER['DOCUMENT_ROOT'] . "/assets/$t/" . $file); - } - } else { - $left++; - } - } -} - -echo($count . " file(s), leaving " . $left . " file(s), action: " . $action . "\n"); |