public function ajaxSubmitAction() { // 获取参数 $language = (int) Request::getPOST('language'); $code = Request::getPOST('code', '', true); $problemHash = Request::getPOST('problem-hash'); $userId = $this->loginUserInfo['id']; $globalId = array_search($problemHash, $this->contestInfo['problem_hash']); if (empty($globalId)) { $this->renderError('竞赛中无此题!'); } // 校验 if (strlen($code) < 50 || strlen($code) > 65535) { $this->renderError('代码长度超出范围,请限制为50-65535(BYTE)!'); } $problemInfo = OjProblemInterface::getById(array('id' => $globalId)); if (empty($problemInfo) || $problemInfo['hidden']) { $this->renderError('题目不存在!'); } if (!array_key_exists($language, StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) { $this->renderError('编译器不支持!'); } if (OjSolutionInterface::submitAlready(array('user_id' => $userId))) { $this->renderError('提交频繁!'); } // 非法字符判断 if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) { if (false === iconv('UTF-8', 'GBK', $code)) { $this->renderError('代码中存在非法字符!'); } } OjSolutionInterface::save(array('global_id' => $globalId, 'user_id' => $userId, 'language' => $language, 'source' => $code, 'contest_id' => $this->contestInfo['id'])); $this->renderAjax(0); }
public function ajaxHelpAction() { // 获取参数 $solutionId = Request::getPOST('solution-id'); $solutionInfo = OjSolutionInterface::getById(array('id' => $solutionId)); if (empty($solutionInfo)) { $this->renderError('solution不存在!'); } // 权限 if (!$this->isOjAdmin && $solutionInfo['user_id'] != Arr::get('id', $this->loginUserInfo, 0)) { $this->renderError('你没有权限操作!'); } $data = array('id' => $solutionId, 'share' => 1 - $solutionInfo['share']); OjSolutionInterface::save($data); $this->renderAjax(0); }
/** * 同步数据到oj_solution * * @throws Exception */ public function sync() { $solutionInfo = OjSolutionInterface::getById(array('id' => $this->solutionId)); if (empty($solutionInfo)) { Logger::error('judge', "SOLUTION_ID:{$this->solutionId},Solution不存在!"); throw new Exception("SOLUTION_ID:{$this->solutionId},Solution不存在!"); } if ($solutionInfo['remote'] != StatusVars::REMOTE_POJ) { Logger::error('judge', "SOLUTION_ID:{$this->solutionId},必须是POJ的Solution!"); throw new Exception("SOLUTION_ID:{$this->solutionId},必须是POJ的Solution!"); } if (empty($solutionInfo['run_id'])) { Logger::error('judge', "RUN_ID为0!"); throw new Exception("SOLUTION_ID:{$this->solutionId},RUN_ID为0!"); } if ($solutionInfo['remote_uid'] != -1 && $solutionInfo['remote_uid'] != $this->uid) { Logger::error('judge', "SOLUTION_ID:{$this->solutionId},当前uid不等于remote_uid,无法获取其他用户的状态!"); throw new Exception("SOLUTION_ID:{$this->solutionId},当前uid不等于remote_uid,无法获取其他用户的状态!"); } // 尝试多次获取结果 $rowInfo = array(); $i = 1; while ($i <= 10) { $rowInfo = $this->getResult($solutionInfo['run_id']); if (false === $rowInfo || in_array($rowInfo['result'], StatusVars::$pojResultMap)) { break; } $i > 5 ? sleep(2) : usleep(500000); $i++; } // 获取获取结果超时 if (false === $rowInfo) { Logger::info('judge', "SOLUTION_ID:{$this->solutionId},获取结果失败2,写入TIME_OUT"); $data = array('id' => $this->solutionId, 'result' => StatusVars::TIME_OUT, 'time_cost' => 0, 'memory_cost' => 0); OjSolutionInterface::save($data); } else { Logger::info('judge', "SOLUTION_ID:{$this->solutionId},POJ远程judge成功!尝试次数:{$i}"); $trans = new Trans(DbConfig::$SERVER_TRANS); $trans->begin(); $data = array('trans' => $trans, 'id' => $this->solutionId, 'result' => $rowInfo['result'], 'time_cost' => $rowInfo['time_cost'], 'memory_cost' => $rowInfo['memory_cost']); OjSolutionInterface::save($data); // 保存Log $dataLog = array('trans' => $trans, 'solution_id' => $this->solutionId, 'ce' => Arr::get('ce', $rowInfo['judge_log'], ''), 're' => Arr::get('re', $rowInfo['judge_log'], '')); OjSolutionLogInterface::save($dataLog); $trans->commit(); } }
$solutionId = $argv[1]; if (empty($solutionId)) { Logger::error('judge', '缺少参数:$solutionId'); exit(1); } // 从评判队列中获取该条信息 $queueInfo = OjJudgeInterface::getRow(array('where' => array(array('solution_id', '=', $solutionId)))); if (empty($queueInfo)) { Logger::error('judge', "评判队列中不存在Solution!solutionId={$solutionId}"); exit(1); } $trans = new Trans(DbConfig::$SERVER_TRANS); $trans->begin(); // 保存result try { OjSolutionInterface::save(array('id' => $solutionId, 'time_cost' => $queueInfo['time_cost'], 'memory_cost' => $queueInfo['memory_cost'], 'judge_time' => $queueInfo['judge_time'], 'run_id' => $queueInfo['id'], 'result' => $queueInfo['result'], 'trans' => $trans)); } catch (Exception $e) { Logger::error('judge', "solutionId={$solutionId},保存solution失败," . $e->getMessage()); $trans->rollback(); throw $e; } // 保存log try { OjSolutionLogInterface::save(array('trans' => $trans, 'solution_id' => $solutionId, 'ce' => $queueInfo['ce'], 're' => $queueInfo['re'], 'detail' => $queueInfo['detail'])); } catch (Exception $e) { Logger::error('judge', "solutionId={$solutionId},保存log失败," . $e->getMessage()); $trans->rollback(); throw $e; } $trans->commit(); exit(0);