Skip to content

Commit 583145f

Browse files
Normalize pending events before saving them and denormalize them after loading
Fixes #2791.
1 parent 5de560c commit 583145f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

webapp/src/Service/ExternalContestSourceService.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
5151
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
5252
use Symfony\Component\PropertyAccess\PropertyAccess;
53+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
54+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
5355
use Symfony\Component\Serializer\SerializerInterface;
5456
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
5557
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
@@ -107,7 +109,7 @@ public function __construct(
107109
protected readonly EventLogService $eventLog,
108110
protected readonly SubmissionService $submissionService,
109111
protected readonly ScoreboardService $scoreboardService,
110-
protected readonly SerializerInterface $serializer,
112+
protected readonly SerializerInterface&DenormalizerInterface&NormalizerInterface $serializer,
111113
#[Autowire('%domjudge.version%')]
112114
string $domjudgeVersion
113115
) {
@@ -1886,7 +1888,8 @@ protected function addPendingEvent(string $type, string|int $id, Event $event, C
18861888
objectId: $id,
18871889
data: [$data],
18881890
);
1889-
$dependencies[$type . '-' . $id] = ['type' => $type, 'id' => $id, 'event' => $event];
1891+
$normalizedEvent = $this->serializer->normalize($event, Event::class, ['api_version' => $this->getApiVersion()]);
1892+
$dependencies[$type . '-' . $id] = ['type' => $type, 'id' => $id, 'event' => $normalizedEvent];
18901893
$this->addOrUpdateWarning($event, $data->id, ExternalSourceWarning::TYPE_DEPENDENCY_MISSING, [
18911894
'dependencies' => $dependencies,
18921895
]);
@@ -1917,7 +1920,7 @@ protected function loadPendingEvents(): void
19171920

19181921
$type = $dependency['type'];
19191922
$id = $dependency['id'];
1920-
$event = $dependency['event'];
1923+
$event = $this->serializer->denormalize($dependency['event'], Event::class, 'json', ['api_version' => $this->getApiVersion()]);
19211924

19221925
if (!isset($this->pendingEvents[$type][$id])) {
19231926
$this->pendingEvents[$type][$id] = [];

0 commit comments

Comments
 (0)