chore: add upgrader for #39.

This commit is contained in:
Baoshuo Ren 2023-02-13 07:56:44 +08:00
parent 83da060ec6
commit be6dd872b7
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
2 changed files with 38 additions and 1 deletions

View File

@ -13,7 +13,7 @@ function requireLib($name) { // html lib
$REQUIRE_LIB[$name] = ''; $REQUIRE_LIB[$name] = '';
} }
function requirePHPLib($name) { // uoj php lib function requirePHPLib($name) { // uoj php lib
require $_SERVER['DOCUMENT_ROOT'] . '/app/libs/uoj-' . $name . '-lib.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/app/libs/uoj-' . $name . '-lib.php';
} }
requirePHPLib('expection'); requirePHPLib('expection');

View File

@ -0,0 +1,37 @@
<?php
requirePHPLib('data');
return function ($type) {
if ($type == 'up') {
DB::init();
$problems = DB::selectAll("select * from problems");
foreach ($problems as $info) {
$problem = new UOJProblem($info);
$extra_config = $problem->getExtraConfig();
$problem_conf = $problem->getProblemConf();
if (!($problem_conf instanceof UOJProblemConf)) {
continue;
}
$extra_config['time_limit'] = (float)$problem_conf->getVal('time_limit', 1);
$extra_config['memory_limit'] = (int)$problem_conf->getVal('memory_limit', 256);
DB::update([
"update problems",
"set", [
"extra_config" => json_encode($extra_config, JSON_FORCE_OBJECT),
],
"where", [
"id" => $problem->info['id'],
],
]);
echo "Problem {$problem->info['id']} upgraded.\n";
}
}
};