2016-07-18 16:39:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = dirname(__DIR__);
|
|
|
|
|
2022-10-11 05:34:05 +00:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/app/vendor/autoload.php';
|
2017-11-25 04:00:00 +00:00
|
|
|
require $_SERVER['DOCUMENT_ROOT'] . '/app/libs/uoj-lib.php';
|
2016-07-18 16:39:37 +00:00
|
|
|
|
|
|
|
// TODO: more beautiful argv parser
|
|
|
|
|
|
|
|
$handlers = [
|
|
|
|
'upgrade:up' => function ($name) {
|
|
|
|
if (func_num_args() != 1) {
|
2023-02-13 12:29:32 +00:00
|
|
|
print("php cli.php upgrade:up <name>\n");
|
|
|
|
exit(1);
|
2016-07-18 16:39:37 +00:00
|
|
|
}
|
2023-02-13 12:29:32 +00:00
|
|
|
Upgrader::transaction(function () use ($name) {
|
2016-07-18 16:39:37 +00:00
|
|
|
Upgrader::up($name);
|
|
|
|
});
|
2023-02-13 12:29:32 +00:00
|
|
|
print("finished!\n");
|
2016-07-18 16:39:37 +00:00
|
|
|
},
|
|
|
|
'upgrade:down' => function ($name) {
|
|
|
|
if (func_num_args() != 1) {
|
2023-02-13 12:29:32 +00:00
|
|
|
print("php cli.php upgrade:down <name>\n");
|
|
|
|
exit(1);
|
2016-07-18 16:39:37 +00:00
|
|
|
}
|
2023-02-13 12:29:32 +00:00
|
|
|
Upgrader::transaction(function () use ($name) {
|
2016-07-18 16:39:37 +00:00
|
|
|
Upgrader::down($name);
|
|
|
|
});
|
2023-02-13 12:29:32 +00:00
|
|
|
print("finished!\n");
|
2016-07-18 16:39:37 +00:00
|
|
|
},
|
|
|
|
'upgrade:refresh' => function ($name) {
|
|
|
|
if (func_num_args() != 1) {
|
2023-02-13 12:29:32 +00:00
|
|
|
print("php cli.php upgrade:refresh <name>\n");
|
|
|
|
exit(1);
|
2016-07-18 16:39:37 +00:00
|
|
|
}
|
2023-02-13 12:29:32 +00:00
|
|
|
Upgrader::transaction(function () use ($name) {
|
2016-07-18 16:39:37 +00:00
|
|
|
Upgrader::refresh($name);
|
|
|
|
});
|
2023-02-13 12:29:32 +00:00
|
|
|
print("finished!\n");
|
2016-07-18 16:39:37 +00:00
|
|
|
},
|
|
|
|
'upgrade:remove' => function ($name) {
|
|
|
|
if (func_num_args() != 1) {
|
2023-02-13 12:29:32 +00:00
|
|
|
print("php cli.php upgrade:remove <name>\n");
|
|
|
|
exit(1);
|
2016-07-18 16:39:37 +00:00
|
|
|
}
|
2023-02-13 12:29:32 +00:00
|
|
|
Upgrader::transaction(function () use ($name) {
|
2016-07-18 16:39:37 +00:00
|
|
|
Upgrader::remove($name);
|
|
|
|
});
|
2023-02-13 12:29:32 +00:00
|
|
|
print("finished!\n");
|
2016-07-18 16:39:37 +00:00
|
|
|
},
|
|
|
|
'upgrade:latest' => function () {
|
|
|
|
if (func_num_args() != 0) {
|
2023-02-13 12:29:32 +00:00
|
|
|
print("php cli.php upgrade:latest\n");
|
|
|
|
exit(1);
|
2016-07-18 16:39:37 +00:00
|
|
|
}
|
2023-02-13 12:29:32 +00:00
|
|
|
Upgrader::transaction(function () {
|
2016-07-18 16:39:37 +00:00
|
|
|
Upgrader::upgradeToLatest();
|
|
|
|
});
|
2023-02-13 12:29:32 +00:00
|
|
|
print("finished!\n");
|
2016-07-18 16:39:37 +00:00
|
|
|
},
|
|
|
|
'upgrade:remove-all' => function () {
|
|
|
|
if (func_num_args() != 0) {
|
2023-02-13 12:29:32 +00:00
|
|
|
print("php cli.php upgrade:remove-all\n");
|
|
|
|
exit(1);
|
2016-07-18 16:39:37 +00:00
|
|
|
}
|
2023-02-13 12:29:32 +00:00
|
|
|
Upgrader::transaction(function () {
|
2016-07-18 16:39:37 +00:00
|
|
|
Upgrader::removeAll();
|
|
|
|
});
|
2023-02-13 12:29:32 +00:00
|
|
|
print("finished!\n");
|
2016-07-18 16:39:37 +00:00
|
|
|
},
|
2023-02-13 12:29:32 +00:00
|
|
|
'email:send-all' => function () {
|
|
|
|
if (func_num_args() != 0) {
|
|
|
|
print("php cli.php email:send-all\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
UOJMail::cronSendEmail();
|
|
|
|
print("finished!\n");
|
|
|
|
},
|
|
|
|
'help' => 'showHelp',
|
2016-07-18 16:39:37 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
function showHelp() {
|
|
|
|
global $handlers;
|
|
|
|
echo "UOJ Command-Line Interface\n";
|
2023-02-13 12:29:32 +00:00
|
|
|
echo "php cli.php <task-name> params1 params2 ...\n";
|
2016-07-18 16:39:37 +00:00
|
|
|
echo "\n";
|
|
|
|
echo "The following tasks are available:\n";
|
|
|
|
foreach ($handlers as $cmd => $handler) {
|
|
|
|
echo "\t$cmd\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($argv) <= 1) {
|
|
|
|
showHelp();
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($handlers[$argv[1]])) {
|
|
|
|
echo "Invalid parameters.\n";
|
|
|
|
showHelp();
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
call_user_func_array($handlers[$argv[1]], array_slice($argv, 2));
|