SpreadQuiz/cli_actions.php

40 lines
954 B
PHP

<?php
require_once "class/TestMgr.php";
const longopts = [
"action:", // execute some CLI action
"tick" // tick timed objects (e.g. timed tests)
];
$options = getopt("", longopts);
// CLI actions
if (isset($options["action"])) {
$action = $options["action"];
switch ($action) {
case "upgrade_tests":
{
printf("Upgrading tests...");
$testMgr = new TestMgr();
$testMgr->upgradeTests();
printf("OK!\n");
}
break;
case "get_timed_tests":
{
$testMgr = new TestMgr();
printf("Expired timed tests: %s\n", join(", ", $testMgr->extractExpiredTimedTestIds()));
}
break;
}
}
// Tick tests
if (isset($options["tick"])) {
$testMgr = new TestMgr();
$timedTestIDs = $testMgr->extractExpiredTimedTestIds();
$testMgr->upgradeTests($timedTestIDs);
}