diff --git a/web/app/controllers/new_remote_problem.php b/web/app/controllers/new_remote_problem.php
index 3ab1497e..7e71a000 100644
--- a/web/app/controllers/new_remote_problem.php
+++ b/web/app/controllers/new_remote_problem.php
@@ -91,7 +91,7 @@
'time_limit' => $data['time_limit'],
'memory_limit' => $data['memory_limit'],
];
- $enc_extra_config = json_encode($extra_config);
+ $enc_extra_config = json_encode($extra_config, JSON_FORCE_OBJECT);
DB::insert([
"insert into problems",
diff --git a/web/app/controllers/problem.php b/web/app/controllers/problem.php
index 9d1c3555..5920a7a2 100644
--- a/web/app/controllers/problem.php
+++ b/web/app/controllers/problem.php
@@ -259,8 +259,6 @@ function(response_text) {
$answer_form->runAtServer();
}
-$conf = UOJProblem::cur()->getProblemConf();
-
if (UOJContest::cur()) {
$pageTitle = UOJProblem::cur()->getTitle(['with' => 'letter', 'simplify' => true]);
} else {
@@ -291,13 +289,8 @@ function(response_text) {
getVal('time_limit', 1) : null;
- $memory_limit = $conf instanceof UOJProblemConf ? $conf->getVal('memory_limit', 256) : null;
- } else if (UOJProblem::info('type') == 'remote') {
- $time_limit = UOJProblem::cur()->getExtraConfig('time_limit');
- $memory_limit = UOJProblem::cur()->getExtraConfig('memory_limit');
- }
+ $time_limit = UOJProblem::cur()->getExtraConfig('time_limit');
+ $memory_limit = UOJProblem::cur()->getExtraConfig('memory_limit');
?>
时间限制: = $time_limit ? "$time_limit s" : "N/A" ?>
diff --git a/web/app/controllers/problem_data_manage.php b/web/app/controllers/problem_data_manage.php
index 56a26328..2653a848 100644
--- a/web/app/controllers/problem_data_manage.php
+++ b/web/app/controllers/problem_data_manage.php
@@ -167,7 +167,7 @@ function echoFilePre($file_name) {
if ($extra_config === null) {
return '不是合法的JSON';
}
- $vdata['extra_config'] = json_encode($extra_config);
+ $vdata['extra_config'] = json_encode($extra_config, JSON_FORCE_OBJECT);
},
]);
$info_form->handle = function (&$vdata) use ($problem) {
@@ -392,8 +392,8 @@ function getDataDisplayer() {
$data_form->runAtServer();
$clear_data_form = new UOJForm('clear_data');
-$clear_data_form->handle = function () use ($problem) {
- dataClearProblemData($problem);
+$clear_data_form->handle = function () {
+ dataClearProblemData(UOJProblem::cur());
};
$clear_data_form->config['submit_container']['class'] = '';
$clear_data_form->config['submit_button']['class'] = 'btn btn-danger d-block w-100';
diff --git a/web/app/controllers/problem_statement_manage.php b/web/app/controllers/problem_statement_manage.php
index 88849b48..2de60370 100644
--- a/web/app/controllers/problem_statement_manage.php
+++ b/web/app/controllers/problem_statement_manage.php
@@ -142,7 +142,7 @@
'time_limit' => $data['time_limit'],
'memory_limit' => $data['memory_limit'],
];
- $enc_extra_config = json_encode($extra_config);
+ $enc_extra_config = json_encode($extra_config, JSON_FORCE_OBJECT);
DB::update([
"update problems",
diff --git a/web/app/libs/uoj-data-lib.php b/web/app/libs/uoj-data-lib.php
index aad2fb78..b101629c 100644
--- a/web/app/libs/uoj-data-lib.php
+++ b/web/app/libs/uoj-data-lib.php
@@ -14,18 +14,36 @@ function dataNewProblem($id) {
]);
}
-function dataClearProblemData($problem) {
- $id = $problem['id'];
+function dataClearProblemData(UOJProblem $problem) {
+ $id = $problem->info['id'];
if (!validateUInt($id)) {
UOJLog::error("dataClearProblemData: hacker detected");
return "invalid problem id";
}
- UOJLocalRun::exec(['rm', "/var/uoj_data/$id", '-r']);
- UOJLocalRun::exec(['rm', "/var/uoj_data/upload/$id", '-r']);
+ UOJLocalRun::exec(['rm', $problem->getDataFolderPath(), '-r']);
+ UOJLocalRun::exec(['rm', $problem->getUploadFolderPath(), '-r']);
+ dataUpdateProblemLimits($problem, null, null);
dataNewProblem($id);
}
+function dataUpdateProblemLimits(UOJProblem $problem, $time_limit, $memory_limit) {
+ $extra_config = $problem->getExtraConfig();
+
+ $extra_config['time_limit'] = $time_limit;
+ $extra_config['memory_limit'] = $memory_limit;
+
+ DB::update([
+ "update problems",
+ "set", [
+ 'extra_config' => json_encode($extra_config, JSON_FORCE_OBJECT),
+ ],
+ "where", [
+ "id" => $problem->info['id'],
+ ],
+ ]);
+}
+
class SyncProblemDataHandler {
private UOJProblem $problem;
private $user;
@@ -302,13 +320,15 @@ private function _sync() {
}
$this->requirement = [];
- $this->problem_extra_config = $this->problem->getExtraConfig();;
+ $this->problem_extra_config = $this->problem->getExtraConfig();
+
if (!is_file("{$this->upload_dir}/problem.conf")) {
throw new UOJFileNotFoundException("problem.conf");
}
$this->problem_conf = getUOJConf("{$this->upload_dir}/problem.conf");
$this->final_problem_conf = $this->problem_conf;
+
if ($this->problem_conf === -1) {
throw new UOJFileNotFoundException("problem.conf");
} elseif ($this->problem_conf === -2) {
@@ -482,6 +502,12 @@ private function _sync() {
['mv', "{$this->id}.next.zip", "{$this->id}.zip", '-f'],
]);
+ dataUpdateProblemLimits(
+ $this->problem,
+ $this->final_problem_conf['time_limit'] ? (float)$this->final_problem_conf['time_limit'] : 1,
+ $this->final_problem_conf['memory_limit'] ? (int)$this->final_problem_conf['memory_limit'] : 256
+ );
+
return '';
}
diff --git a/web/app/libs/uoj-lib.php b/web/app/libs/uoj-lib.php
index d43a11bc..afea464d 100644
--- a/web/app/libs/uoj-lib.php
+++ b/web/app/libs/uoj-lib.php
@@ -13,7 +13,7 @@ function requireLib($name) { // html lib
$REQUIRE_LIB[$name] = '';
}
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');
diff --git a/web/app/upgrade/20_problem_difficulty/upgrade.php b/web/app/upgrade/20_problem_difficulty/upgrade.php
index ab1635cc..55e0dfb6 100644
--- a/web/app/upgrade/20_problem_difficulty/upgrade.php
+++ b/web/app/upgrade/20_problem_difficulty/upgrade.php
@@ -32,7 +32,7 @@
DB::update([
"update problems",
"set", [
- "extra_config" => json_encode($extra_config),
+ "extra_config" => json_encode($extra_config, JSON_FORCE_OBJECT),
],
"where", [
"id" => $problem->info['id'],
diff --git a/web/app/upgrade/39_limits_in_extra_config/upgrade.php b/web/app/upgrade/39_limits_in_extra_config/upgrade.php
new file mode 100644
index 00000000..04fc26e5
--- /dev/null
+++ b/web/app/upgrade/39_limits_in_extra_config/upgrade.php
@@ -0,0 +1,37 @@
+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";
+ }
+ }
+};