Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/app/controllers/new_remote_problem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 2 additions & 9 deletions web/app/controllers/problem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -291,13 +289,8 @@ function(response_text) {
</h1>

<?php
if (UOJProblem::info('type') == 'local') {
$time_limit = $conf instanceof UOJProblemConf ? $conf->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');
?>
<div class="text-center small">
时间限制: <?= $time_limit ? "$time_limit s" : "N/A" ?>
Expand Down
6 changes: 3 additions & 3 deletions web/app/controllers/problem_data_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion web/app/controllers/problem_statement_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 31 additions & 5 deletions web/app/libs/uoj-data-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 '';
}

Expand Down
2 changes: 1 addition & 1 deletion web/app/libs/uoj-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion web/app/upgrade/20_problem_difficulty/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
37 changes: 37 additions & 0 deletions web/app/upgrade/39_limits_in_extra_config/upgrade.php
Original file line number Diff line number Diff line change
@@ -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";
}
}
};