/** * Update problem contents * * @param Request $r * @throws ApiException * @throws InvalidDatabaseOperationException */ public static function apiUpdate(Request $r) { self::authenticateRequest($r); self::validateCreateOrUpdate($r, true); // Validate commit message. Validators::isStringNonEmpty($r['message'], 'message'); // Update the Problem object $valueProperties = array('public', 'title', 'validator' => array('important' => true), 'time_limit' => array('important' => true), 'validator_time_limit' => array('important' => true), 'overall_wall_time_limit' => array('important' => true), 'extra_wall_time' => array('important' => true), 'memory_limit' => array('important' => true), 'output_limit' => array('important' => true), 'stack_limit' => array('important' => true), 'email_clarifications', 'source', 'order', 'languages'); $problem = $r['problem']; $requiresRejudge = self::updateValueProperties($r, $problem, $valueProperties); $r['problem'] = $problem; $response = array('rejudged' => false); $problemDeployer = new ProblemDeployer($problem->alias, ProblemDeployer::UPDATE_CASES); // Insert new problem try { //Begin transaction ProblemsDAO::transBegin(); if (isset($_FILES['problem_contents']) && FileHandler::GetFileUploader()->IsUploadedFile($_FILES['problem_contents']['tmp_name'])) { // DeployProblemZip requires alias => problem_alias $r['alias'] = $r['problem_alias']; $problemDeployer->deploy(); if ($problemDeployer->hasValidator) { $problem->validator = 'custom'; } elseif ($problem->validator == 'custom') { throw new ProblemDeploymentFailedException('problemDeployerValidatorRequired'); } // This must come before the commit in case isSlow throws an exception. $problem->slow = $problemDeployer->isSlow($problem); // Calculate output limit. $output_limit = $problemDeployer->getOutputLimit(); if ($output_limit != -1) { $r['problem']->setOutputLimit($output_limit); } $response['uploaded_files'] = $problemDeployer->filesToUnzip; $problemDeployer->commit($r['message'], $r['current_user']); $requiresRejudge |= $problemDeployer->requiresRejudge; } else { $problem->slow = $problemDeployer->isSlow($problem); } // Save the contest object with data sent by user to the database ProblemsDAO::save($problem); //End transaction ProblemsDAO::transEnd(); } catch (ApiException $e) { // Operation failed in the data layer, rollback transaction ProblemsDAO::transRollback(); throw $e; } catch (Exception $e) { // Operation failed in the data layer, rollback transaction ProblemsDAO::transRollback(); self::$log->error('Failed to update problem'); self::$log->error($e); throw new InvalidDatabaseOperationException($e); } finally { $problemDeployer->cleanup(); } if ($requiresRejudge == true && OMEGAUP_ENABLE_REJUDGE_ON_PROBLEM_UPDATE == true) { self::$log->info('Calling ProblemController::apiRejudge'); try { self::apiRejudge($r); $response['rejudged'] = true; } catch (Exception $e) { self::$log->error('Best efort ProblemController::apiRejudge failed', $e); } } if ($r['redirect'] === true) { header('Location: ' . $_SERVER['HTTP_REFERER']); } // All clear $response['status'] = 'ok'; // Invalidar problem statement cache @todo invalidar todos los lenguajes foreach ($problemDeployer->getUpdatedLanguages() as $lang) { Cache::deleteFromCache(Cache::PROBLEM_STATEMENT, $r['problem']->getAlias() . '-' . $lang . 'html'); Cache::deleteFromCache(Cache::PROBLEM_STATEMENT, $r['problem']->getAlias() . '-' . $lang . 'markdown'); } Cache::deleteFromCache(Cache::PROBLEM_SAMPLE, $r['problem']->getAlias() . '-sample.in'); return $response; }