From ff4798f6da50e64b2438e6adaaa1dcaba300b536 Mon Sep 17 00:00:00 2001 From: thrillfall Date: Wed, 25 Aug 2021 22:41:15 +0200 Subject: [PATCH] do not null EpisodeAction.guid when processing request without guid --- lib/Core/EpisodeAction/EpisodeActionSaver.php | 14 ++++-- ...ctionSaverGuidBackwardCompatbilityTest.php | 47 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/Integration/EpisodeActionSaverGuidBackwardCompatbilityTest.php diff --git a/lib/Core/EpisodeAction/EpisodeActionSaver.php b/lib/Core/EpisodeAction/EpisodeActionSaver.php index a67f2d8..45e52d6 100644 --- a/lib/Core/EpisodeAction/EpisodeActionSaver.php +++ b/lib/Core/EpisodeAction/EpisodeActionSaver.php @@ -84,13 +84,13 @@ class EpisodeActionSaver ); if ($episodeActionEntityToUpdate === null && $episodeActionEntity->getGuid() !== null) { - $episodeActionEntityToUpdate = $this->getOldEpisodeActionByEpisodeUrl( - $episodeActionEntity->getEpisode(), $userId - ); + $episodeActionEntityToUpdate = $this->getOldEpisodeActionByEpisodeUrl($episodeActionEntity->getEpisode(), $userId); } $episodeActionEntity->setId($episodeActionEntityToUpdate->getId()); + $this->assertGuidDoesNotGetNulledWithOldData($episodeActionEntityToUpdate, $episodeActionEntity); + return $this->episodeActionWriter->update($episodeActionEntity); } @@ -108,6 +108,14 @@ class EpisodeActionSaver ); } + private function assertGuidDoesNotGetNulledWithOldData(EpisodeActionEntity $episodeActionEntityToUpdate, EpisodeActionEntity $episodeActionEntity): void + { + $existingGuid = $episodeActionEntityToUpdate->getGuid(); + if ($existingGuid !== null && $episodeActionEntity->getGuid() == null) { + $episodeActionEntity->setGuid($existingGuid); + } + } + /** * @param EpisodeAction $episodeAction * @param string $userId diff --git a/tests/Integration/EpisodeActionSaverGuidBackwardCompatbilityTest.php b/tests/Integration/EpisodeActionSaverGuidBackwardCompatbilityTest.php new file mode 100644 index 0000000..18d14fc --- /dev/null +++ b/tests/Integration/EpisodeActionSaverGuidBackwardCompatbilityTest.php @@ -0,0 +1,47 @@ +container = $app->getContainer(); + } + + public function testUpdateWithoutGuidDoesNotNullGuid() : void + { + /** @var EpisodeActionSaver $episodeActionSaver */ + $episodeActionSaver = $this->container->get(EpisodeActionSaver::class); + + $episodeUrl = uniqid("test_https://dts.podtrac.com/redirect.mp3/chrt.fm/track"); + $guid = uniqid("test_gid://art19-episode-locator/V0/Ktd"); + + $savedEpisodeActionEntity = $episodeActionSaver->saveEpisodeActions( + "[EpisodeAction{podcast='https://rss.art19.com/dr-death-s3-miracle-man', episode='{$episodeUrl}', guid='{$guid}', action=PLAY, timestamp=Mon Aug 23 01:58:56 GMT+02:00 2021, started=47, position=54, total=2252}]", + self::USER_ID_0 + )[0]; + + $savedEpisodeActionEntityWithoutGuidFromOldDevice = $episodeActionSaver->saveEpisodeActions( + "[EpisodeAction{podcast='https://rss.art19.com/dr-death-s3-miracle-man', episode='{$episodeUrl}', action=PLAY, timestamp=Mon Aug 23 01:58:56 GMT+02:00 2021, started=47, position=54, total=2252}]", + self::USER_ID_0 + )[0]; + + self::assertSame($savedEpisodeActionEntity->getId(), $savedEpisodeActionEntityWithoutGuidFromOldDevice->getId()); + self::assertNotNull($savedEpisodeActionEntityWithoutGuidFromOldDevice->getGuid()); + } +}