@@ -912,37 +912,22 @@ public function internalErrorAction(Request $request): ?int
912912 */
913913 protected function giveBackJudging (int $ judgingId , ?Judgehost $ judgehost ): void
914914 {
915+ // Reset the judgings without using Doctrine, it has no support for update queries containing a join.
916+ // Both databases supported by DOMjudge (MariaDB, MySQL) support these types of queries.
915917 $ judging = $ this ->em ->getRepository (Judging::class)->find ($ judgingId );
916918 if ($ judging ) {
917- $ this ->em ->wrapInTransaction (function () use ($ judging , $ judgehost ) {
918- /** @var JudgingRun $run */
919- foreach ($ judging ->getRuns () as $ run ) {
920- if ($ judgehost === null ) {
921- // This is coming from internal errors, reset the whole judging.
922- $ run ->getJudgetask ()
923- ->setValid (false );
924- continue ;
925- }
926-
927- // We do not have to touch any finished runs
928- if ($ run ->getRunresult () !== null ) {
929- continue ;
930- }
931-
932- // For the other runs, we need to reset the judge task if it belongs to the current judgehost.
933- if ($ run ->getJudgetask ()->getJudgehost () && $ run ->getJudgetask ()->getJudgehost ()->getHostname () === $ judgehost ->getHostname ()) {
934- $ run ->getJudgetask ()
935- ->setJudgehost (null )
936- ->setStarttime (null );
937- }
938- }
939-
940- $ this ->em ->flush ();
941- });
942-
943919 if ($ judgehost === null ) {
944920 // Invalidate old judging and create a new one - but without judgetasks yet since this was triggered by
945921 // an internal error.
922+ $ this ->em ->getConnection ()->executeStatement (
923+ 'UPDATE judging_run jr ' .
924+ 'JOIN judgetask jt ON jt.judgetaskid = jr.judgetaskid ' .
925+ 'SET jt.valid = 0 ' .
926+ 'WHERE jr.judgingid = :judgingid ' ,
927+ [
928+ 'judgingid ' => $ judgingId ,
929+ ]);
930+
946931 $ judging ->setValid (false );
947932 $ newJudging = new Judging ();
948933 $ newJudging
@@ -952,6 +937,19 @@ protected function giveBackJudging(int $judgingId, ?Judgehost $judgehost): void
952937 ->setOriginalJudging ($ judging );
953938 $ this ->em ->persist ($ newJudging );
954939 $ this ->em ->flush ();
940+ } else {
941+ // Hand back the non-completed work of this judgehost within this judgetask.
942+ $ this ->em ->getConnection ()->executeStatement (
943+ 'UPDATE judging_run jr ' .
944+ 'JOIN judgetask jt ON jt.judgetaskid = jr.judgetaskid ' .
945+ 'SET jt.judgehostid = null, jt.starttime = null ' .
946+ 'WHERE jr.judgingid = :judgingid ' .
947+ ' AND jr.runresult IS NOT NULL ' .
948+ ' AND jt.judgehostid = :judgehost ' ,
949+ [
950+ 'judgingid ' => $ judgingId ,
951+ 'judgehost ' => $ judgehost ->getJudgehostid (),
952+ ]);
955953 }
956954
957955 $ this ->dj ->auditlog ('judging ' , $ judgingId , 'given back '
0 commit comments