/**
  * Rejudge problem
  *
  * @param Request $r
  * @throws ApiException
  * @throws InvalidDatabaseOperationException
  */
 public static function apiRejudge(Request $r)
 {
     self::authenticateRequest($r);
     self::validateRejudge($r);
     // We need to rejudge runs after an update, let's initialize the grader
     self::initializeGrader();
     // Call Grader
     $runs = array();
     try {
         $runs = RunsDAO::search(new Runs(array('problem_id' => $r['problem']->getProblemId())));
         $guids = array();
         foreach ($runs as $run) {
             $guids[] = $run->guid;
             $run->setStatus('new');
             $run->setVerdict('JE');
             $run->setScore(0);
             $run->setContestScore(0);
             RunsDAO::save($run);
             // Expire details of the run
             RunController::invalidateCacheOnRejudge($run);
         }
         self::$grader->Grade($guids, true, false);
     } catch (Exception $e) {
         self::$log->error('Failed to rejudge runs after problem update');
         self::$log->error($e);
         throw new InvalidDatabaseOperationException($e);
     }
     $response = array();
     // All clear
     $response['status'] = 'ok';
     return $response;
 }