public function ajaxSubmitAction()
 {
     // 获取参数
     $globalId = Request::getPOST('global-id');
     $language = Request::getPOST('language');
     $code = Request::getPOST('code', '', true);
     // 校验
     if (strlen($code) < 50 || strlen($code) > 65535) {
         $this->renderError('代码长度超出范围,请限制为50-65535(BYTE)!');
     }
     $problemInfo = OjProblemInterface::getById(array('id' => $globalId));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     if (!array_key_exists($language, StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) {
         $this->renderError('编译器不支持!');
     }
     // 非法字符判断
     if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) {
         if (false === iconv('UTF-8', 'GBK', $code)) {
             $this->renderError('代码中存在非法字符!');
         }
     }
     OjJudgeInterface::save(array('problem_id' => $problemInfo['problem_id'], 'language' => $language, 'source' => $code, 'user_id' => $this->loginUserInfo['id']));
     // judge
     $this->renderAjax(0);
 }
 public function iframeShowAction()
 {
     $judgeId = (int) Request::getGET('judge-id');
     // 获取judgeInfo
     $judgeInfo = OjJudgeInterface::getRow(array('id' => $judgeId));
     if (empty($judgeInfo)) {
         $this->renderError();
     }
     $this->renderIframe(array('judgeInfo' => $judgeInfo), 'problem/iframe/judge_log.php');
 }
 public function iframeShowAction()
 {
     $judgeId = (int) Request::getGET('judge-id');
     // 获取judgeInfo
     $where = array(array('id', '=', $judgeId), array('solution_id', '=', 0), array('user_id', '=', $this->loginUserInfo['id']));
     $judgeInfo = OjJudgeInterface::getRow(array('where' => $where));
     if (empty($judgeInfo)) {
         $this->renderError();
     }
     $this->renderIframe(array('judgeInfo' => $judgeInfo), 'setup/problem/iframe/judge_log.php');
 }
 public function ajaxRejudgeAction()
 {
     // 获取参数
     $judgeId = Request::getPOST('judge-id');
     // 只能重判自己的solution
     $judgeInfo = OjJudgeInterface::getById(array('id' => $judgeId));
     if (empty($judgeInfo)) {
         $this->renderError('judgeInfo不存在!');
     }
     // rejudge
     OjJudgeInterface::rejudge(array('id' => $judgeId));
     $this->renderAjax(0);
 }
 public function defaultAction()
 {
     $judgeId = (int) Request::getGET('judge-id');
     if (empty($judgeId)) {
         $this->renderError();
     }
     // 获取judgeInfo
     $where = array(array('id', '=', $judgeId), array('solution_id', '=', 0), array('user_id', '=', $this->loginUserInfo['id']));
     $judgeInfo = OjJudgeInterface::getRow(array('where' => $where));
     if (empty($judgeInfo)) {
         $this->renderError();
     }
     // 格式化
     $text = StatusVars::$RESULT_FORMAT[$judgeInfo['result']];
     $class = StatusVars::$RESULT_CLASS[$judgeInfo['result']];
     $judgeInfo['result_html'] = sprintf('<span class="%s">%s</span>', $class, $text);
     $judgeInfo['source_format'] = htmlspecialchars($judgeInfo['source'], ENT_COMPAT, 'UTF-8');
     $this->renderFramework(array('judgeInfo' => $judgeInfo), 'setup/problem/code.php');
 }
 public function ajaxRejudgeAction()
 {
     // 获取参数
     $judgeId = Request::getPOST('judge-id');
     // 只能重判自己的solution
     $judgeInfo = OjJudgeInterface::getById(array('id' => $judgeId));
     if (empty($judgeInfo)) {
         $this->renderError('judgeInfo不存在!');
     }
     if ($judgeInfo['solution_id'] > 0 || $judgeInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('你没有权限重判!');
     }
     // 获取题目
     $problemInfo = OjProblemInterface::getDetail(array('remote' => StatusVars::REMOTE_HQU, 'problem_id' => $judgeInfo['problem_id']));
     if ($problemInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('你没有权限重判他人的题目!');
     }
     // rejudge
     OjJudgeInterface::rejudge(array('id' => $judgeId));
     $this->renderAjax(0);
 }
<?php

/**
 * 同步当前的solution
 */
require_once __DIR__ . '/../../../bootstrap.php';
// 获取命令行参数
$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']));
 public static function rejudge($id)
 {
     $solutionInfo = self::getById($id);
     if (empty($solutionInfo)) {
         throw new InterfaceException('solution不存在!');
     }
     $trans = new Trans(DbConfig::$SERVER_TRANS);
     $trans->begin();
     $solutionModel = new OjSolutionModel($trans);
     $solutionModel->updateById($id, array('time_cost' => 0, 'memory_cost' => 0));
     $affects = self::updateResult($id, StatusVars::REJUDGE, $trans);
     // 调用HQOJ重判接口
     if ($solutionInfo['remote'] == StatusVars::REMOTE_HQU) {
         OjJudgeInterface::rejudge(array('trans' => $trans, 'id' => $solutionInfo['run_id']));
     }
     $trans->commit();
     return $affects;
 }