summaryrefslogtreecommitdiff
path: root/includes/maintenance
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-06-22 23:06:12 +0200
committerRaindropsSys <contact@minteck.org>2023-06-22 23:06:12 +0200
commit23563c7188e089929b60f9e10721c6fc43a220ff (patch)
treeedfe2b009c82900d4ac27db02222d2f68dcad846 /includes/maintenance
parent7a7a49332df7c852abbaa33c7e8e87f93d064d61 (diff)
downloadpluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.tar.gz
pluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.tar.bz2
pluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.zip
Updated 15 files, added includes/maintenance/deleteUnusedAssets.php and deleted 4944 files (automated)
Diffstat (limited to 'includes/maintenance')
-rw-r--r--includes/maintenance/deleteUnusedAssets.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/includes/maintenance/deleteUnusedAssets.php b/includes/maintenance/deleteUnusedAssets.php
new file mode 100644
index 0000000..780c80f
--- /dev/null
+++ b/includes/maintenance/deleteUnusedAssets.php
@@ -0,0 +1,69 @@
+<?php
+
+global $action;
+if (!isset($_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/ynmuc/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/ynmuc/general.json"), true)["uuid"]) . str_replace("-", "", $i["uuid"]);
+ }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/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"); \ No newline at end of file