From 78b925daa68c6c914df5e61636dfe0e398458dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Sun, 15 Feb 2026 12:55:48 +0100 Subject: [PATCH] fix: backward compatibility for new session format --- src/Form/Model/BookingDto.php | 15 ++++++++----- tests/Form/Model/BookingDtoTest.php | 35 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/Form/Model/BookingDto.php b/src/Form/Model/BookingDto.php index eb38201..05eadbc 100644 --- a/src/Form/Model/BookingDto.php +++ b/src/Form/Model/BookingDto.php @@ -377,10 +377,15 @@ class BookingDto $this->$key = $value; } - // Create a skeleton Travel with only the ID; BookingService::hydrate() - // replaces this with the full object from cache - $travel = new Travel(); - $travel->id = $travelId; - $this->travel = $travel; + // Old sessions (before c373a989) still carry a full Travel object; + // new sessions carry only the int ID. Handle both formats. + // TODO: Remove Travel instance branch once all pre-deploy sessions have expired + if ($travelId instanceof Travel) { + $this->travel = $travelId; + } else { + $travel = new Travel(); + $travel->id = $travelId; + $this->travel = $travel; + } } } diff --git a/tests/Form/Model/BookingDtoTest.php b/tests/Form/Model/BookingDtoTest.php index 7980817..f599b4a 100644 --- a/tests/Form/Model/BookingDtoTest.php +++ b/tests/Form/Model/BookingDtoTest.php @@ -28,4 +28,39 @@ class BookingDtoTest extends TestCase $this->assertSame($travel, $bookingDto->travel); $this->assertSame(BookingDto::MODE_CREATE, $bookingDto->getMode()); } + + public function testUnserializeHandlesIntTravelId(): void + { + $travel = new Travel(); + $travel->id = 42; + $travel->dateFrom = new \DateTimeImmutable('2025-06-01'); + $travel->dateTo = new \DateTimeImmutable('2025-06-08'); + + $dto = new BookingDto($travel, 1); + $serialized = serialize($dto); + $restored = unserialize($serialized); + + $this->assertInstanceOf(BookingDto::class, $restored); + $this->assertSame(42, $restored->travel->id); + } + + public function testUnserializeHandlesLegacyTravelObject(): void + { + $travel = new Travel(); + $travel->id = 42; + $travel->dateFrom = new \DateTimeImmutable('2025-06-01'); + $travel->dateTo = new \DateTimeImmutable('2025-06-08'); + + // Simulate old session format where 'travel' is a full Travel object + $data = [ + 'travel' => $travel, + 'hotelId' => 1, + ]; + + $dto = new BookingDto(new Travel(), 1); + $dto->__unserialize($data); + + $this->assertSame($travel, $dto->travel); + $this->assertSame(42, $dto->travel->id); + } }