feat: Add housekeeping bin + slight restructure of cron jobs

This commit is contained in:
overflowerror 2024-08-05 21:07:08 +02:00
parent d8efb0c2cd
commit 3ade121615
6 changed files with 45 additions and 1 deletions

5
bin/cron/daily.php Normal file
View file

@ -0,0 +1,5 @@
<?php
require_once __DIR__ . '/updateCache.php';
require_once __DIR__ . '/housekeeping.php';

12
bin/cron/housekeeping.php Normal file
View file

@ -0,0 +1,12 @@
<?php
require_once __DIR__ . "/../../core.php";
require_once __DIR__ . "/../../lib/housekeeping.php";
echo "Removing old session IDs from match table...";
removeOldSessionIDs();
echo "Removing old audit logs...";
removeOldAuditLogs();
echo "Housekeeping done.";

View file

@ -3,4 +3,7 @@
require_once __DIR__ . "/../../core.php";
require_once __DIR__ . "/../../lib/updateCache.php";
echo "Updating rating cache...";
updateCache();
echo "Done.";

View file

@ -46,4 +46,6 @@ echo "Adding to database...\n";
foreach ($mobs as &$mob) {
echo " ... " . $mob["name"] . "\n";
addOrUpdateMob($mob["name"], $mob["filename"]);
}
}
echo "Done.";

3
bin/cron/weekly.php Normal file
View file

@ -0,0 +1,3 @@
<?php
require_once __DIR__ . "/updateData.php";

19
lib/housekeeping.php Normal file
View file

@ -0,0 +1,19 @@
<?php
function removeOldAuditLogs() {
global $pdo;
$pdo->exec("DELETE FROM mm_audit_log WHERE time < (CURRENT_TIMESTAMP - INTERVAL '6 months')");
}
function removeOldSessionIDs() {
global $pdo;
$pdo->exec(<<<EOF
UPDATE mm_matches
SET session = NULL
WHERE
created < (CURRENT_TIMESTAMP - INTERVAL '6 months')
AND session IS NOT NULL
EOF
);
}