<?php const __ROOT__ = __DIR__ . "/.."; require_once __ROOT__ . "/vendor/autoload.php"; require_once __ROOT__ . "/application/i18n.php"; require_once __ROOT__ . "/application/common.php"; function print_error(string $msg): void { file_put_contents("php://stderr", $msg); } function check_sapi(): void { if (PHP_SAPI !== "cli") { http_response_code(500); echo "Error: Can only be called via command line\n"; exit(1); } } check_sapi(); $job = $argv[1] ?? null; if ($job === null) { print_error("Error: No job specified\nUsage: php cron.php <job>\n"); exit(1); } $jobsDir = __DIR__ . "/jobs"; $availableJobs = array_map(fn($i) => pathinfo($i, PATHINFO_FILENAME), array_values(array_filter(scandir($jobsDir), fn($i) => is_file($jobsDir . "/" . $i) && $i[0] !== "." && pathinfo($i, PATHINFO_EXTENSION) === "php"))); if (!in_array($job, $availableJobs)) { print_error("Error: Invalid job specified\nAvailable jobs are:\n" . implode("", array_map(fn($i) => " $i\n", $availableJobs))); exit(1); } $jobFile = $jobsDir . "/" . $job . ".php"; include $jobFile;