diff options
Diffstat (limited to 'includes/jobs/CleanupDocs.php')
-rw-r--r-- | includes/jobs/CleanupDocs.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/includes/jobs/CleanupDocs.php b/includes/jobs/CleanupDocs.php new file mode 100644 index 0000000..70f37b9 --- /dev/null +++ b/includes/jobs/CleanupDocs.php @@ -0,0 +1,25 @@ +<?php + +$options = json_decode($argv[1], true); +$_SERVER['DOCUMENT_ROOT'] = "../.."; +require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php'; +use ColorThief\ColorThief; + +$documents = array_map(function ($i) { + return [ + "id" => substr($i, 0, -5), + ...(json_decode(file_get_contents("./data/docs/" . $i), true) ?? []) + ]; +}, array_filter(scandir("./data/docs"), function ($i) { + return !str_starts_with($i, ".") && str_ends_with($i, ".json"); +})); + +$deletable = array_values(array_filter($documents, function ($i) { + return str_starts_with(strip_tags($i["contents"]), "/delete"); +})); + +foreach ($deletable as $item) { + if (time() - $item["last"]["date"] > 86400) { + unlink("./data/docs/" . $item["id"] . ".json"); + } +}
\ No newline at end of file |