From 583145fd8fa9096672039d94a2c1d78bff76cede Mon Sep 17 00:00:00 2001 From: Nicky Gerritsen Date: Sun, 24 Nov 2024 14:43:34 +0100 Subject: [PATCH] Normalize pending events before saving them and denormalize them after loading Fixes #2791. --- webapp/src/Service/ExternalContestSourceService.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/webapp/src/Service/ExternalContestSourceService.php b/webapp/src/Service/ExternalContestSourceService.php index 3d0212d523..bad3824ab9 100644 --- a/webapp/src/Service/ExternalContestSourceService.php +++ b/webapp/src/Service/ExternalContestSourceService.php @@ -50,6 +50,8 @@ use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException; use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException; use Symfony\Component\PropertyAccess\PropertyAccess; +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; @@ -107,7 +109,7 @@ public function __construct( protected readonly EventLogService $eventLog, protected readonly SubmissionService $submissionService, protected readonly ScoreboardService $scoreboardService, - protected readonly SerializerInterface $serializer, + protected readonly SerializerInterface&DenormalizerInterface&NormalizerInterface $serializer, #[Autowire('%domjudge.version%')] string $domjudgeVersion ) { @@ -1886,7 +1888,8 @@ protected function addPendingEvent(string $type, string|int $id, Event $event, C objectId: $id, data: [$data], ); - $dependencies[$type . '-' . $id] = ['type' => $type, 'id' => $id, 'event' => $event]; + $normalizedEvent = $this->serializer->normalize($event, Event::class, ['api_version' => $this->getApiVersion()]); + $dependencies[$type . '-' . $id] = ['type' => $type, 'id' => $id, 'event' => $normalizedEvent]; $this->addOrUpdateWarning($event, $data->id, ExternalSourceWarning::TYPE_DEPENDENCY_MISSING, [ 'dependencies' => $dependencies, ]); @@ -1917,7 +1920,7 @@ protected function loadPendingEvents(): void $type = $dependency['type']; $id = $dependency['id']; - $event = $dependency['event']; + $event = $this->serializer->denormalize($dependency['event'], Event::class, 'json', ['api_version' => $this->getApiVersion()]); if (!isset($this->pendingEvents[$type][$id])) { $this->pendingEvents[$type][$id] = [];