do not null EpisodeAction.guid when processing request without guid
This commit is contained in:
parent
a336618ada
commit
ff4798f6da
|
@ -84,13 +84,13 @@ class EpisodeActionSaver
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($episodeActionEntityToUpdate === null && $episodeActionEntity->getGuid() !== null) {
|
if ($episodeActionEntityToUpdate === null && $episodeActionEntity->getGuid() !== null) {
|
||||||
$episodeActionEntityToUpdate = $this->getOldEpisodeActionByEpisodeUrl(
|
$episodeActionEntityToUpdate = $this->getOldEpisodeActionByEpisodeUrl($episodeActionEntity->getEpisode(), $userId);
|
||||||
$episodeActionEntity->getEpisode(), $userId
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$episodeActionEntity->setId($episodeActionEntityToUpdate->getId());
|
$episodeActionEntity->setId($episodeActionEntityToUpdate->getId());
|
||||||
|
|
||||||
|
$this->assertGuidDoesNotGetNulledWithOldData($episodeActionEntityToUpdate, $episodeActionEntity);
|
||||||
|
|
||||||
return $this->episodeActionWriter->update($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 EpisodeAction $episodeAction
|
||||||
* @param string $userId
|
* @param string $userId
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests\Integration;
|
||||||
|
|
||||||
|
use OCA\GPodderSync\Core\EpisodeAction\EpisodeActionSaver;
|
||||||
|
use OCP\AppFramework\App;
|
||||||
|
use Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DB
|
||||||
|
*/
|
||||||
|
class EpisodeActionSaverGuidBackwardCompatbilityTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
private const USER_ID_0 = "testuser0";
|
||||||
|
|
||||||
|
private \OCP\AppFramework\IAppContainer $container;
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
parent::setUp();
|
||||||
|
$app = new App('gpoddersync');
|
||||||
|
$this->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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue