Skip to content

Commit 016e81d

Browse files
For submissions and clarifications, prefix external ID in shadow mode
This is needed to prevent collisions. We can also use this logic to determine if someone submitted in DOMjudge while being shadow (i.e. an analyst instance) to make sure we judge the submission. This fixes the few breaking tests.
1 parent bbdfa25 commit 016e81d

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

webapp/src/Doctrine/ExternalIdAssigner.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use App\Entity\CalculatedExternalIdBasedOnRelatedFieldInterface;
66
use App\Entity\ExternalIdFromInternalIdInterface;
7+
use App\Entity\PrefixedExternalIdInShadowModeInterface;
78
use App\Entity\PrefixedExternalIdInterface;
9+
use App\Service\DOMJudgeService;
810
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
911
use Doctrine\ORM\EntityManagerInterface;
1012
use Doctrine\ORM\Event\PostPersistEventArgs;
@@ -15,6 +17,7 @@ class ExternalIdAssigner
1517
{
1618
public function __construct(
1719
protected readonly EntityManagerInterface $em,
20+
protected readonly DOMJudgeService $dj,
1821
) {}
1922

2023
public function __invoke(PostPersistEventArgs $args): void
@@ -37,6 +40,8 @@ public function __invoke(PostPersistEventArgs $args): void
3740
$externalid = (string)$metadata->getFieldValue($entity, $primaryKeyField);
3841
if ($entity instanceof PrefixedExternalIdInterface) {
3942
$externalid = 'dj-' . $externalid;
43+
} elseif ($this->dj->shadowMode() && $entity instanceof PrefixedExternalIdInShadowModeInterface) {
44+
$externalid = 'dj-' . $externalid;
4045
}
4146
}
4247

webapp/src/Entity/Clarification.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
#[UniqueEntity(fields: 'externalid')]
3434
class Clarification extends BaseApiEntity implements
3535
HasExternalIdInterface,
36-
ExternalIdFromInternalIdInterface
36+
ExternalIdFromInternalIdInterface,
37+
PrefixedExternalIdInShadowModeInterface
3738
{
3839
#[ORM\Id]
3940
#[ORM\GeneratedValue]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\Entity;
4+
5+
/**
6+
* Entities implementing this interface will have their external ID prefixed with 'dj-', but only in shadow mode.
7+
*
8+
* This is used for submissions and clarifications that are added directly in DOMjudge while shadowing.
9+
*
10+
* For submissions this happens for example when analysts use DOMjudge and want to submit something.
11+
*
12+
* For clarifications this should normally not happen, but we still need to handle it.
13+
*/
14+
interface PrefixedExternalIdInShadowModeInterface
15+
{
16+
}

webapp/src/Entity/Submission.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
#[UniqueEntity(fields: 'externalid')]
3939
class Submission extends BaseApiEntity implements
4040
HasExternalIdInterface,
41-
ExternalIdFromInternalIdInterface
41+
ExternalIdFromInternalIdInterface,
42+
PrefixedExternalIdInShadowModeInterface
4243
{
4344
#[ORM\Id]
4445
#[ORM\GeneratedValue]

webapp/src/Service/DOMJudgeService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ private function allowJudge(ContestProblem $problem, Submission $submission, Lan
15611561

15621562
// Special case, we're shadow and someone submits on our side in that case
15631563
// we're not super lazy.
1564-
if ($this->shadowMode() && $submission->getExternalid() === null) {
1564+
if ($this->shadowMode() && $submission->getExternalid() === ('dj-' . $submission->getSubmitid())) {
15651565
$evalOnDemand = false;
15661566
}
15671567
if ($manualRequest) {

webapp/tests/Unit/Controller/Jury/QueueTaskControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function testLazy(bool $shadowMode, int $globalLazy, int $problemLazy): v
144144
$config = self::getContainer()->get(ConfigurationService::class);
145145
$eventLog = self::getContainer()->get(EventLogService::class);
146146
$dj = self::getContainer()->get(DOMJudgeService::class);
147-
$config->saveChanges(['lazy_eval_results'=>$globalLazy], $eventLog, $dj);
147+
$config->saveChanges(['lazy_eval_results'=>$globalLazy], $eventLog, $dj, treatMissingBooleansAsFalse: false);
148148

149149
$this->roles = ['admin'];
150150
$this->logOut();

0 commit comments

Comments
 (0)