From a5aef2a63e464632f3941649d455672835989e6c Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Sat, 6 Apr 2024 11:47:49 +0000 Subject: [PATCH] fix(rss): generate podcast guid if empty closes #450 --- app/Helpers/rss_helper.php | 11 +++++++++++ app/Models/PodcastModel.php | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php index a063b5c7..8e378eb9 100644 --- a/app/Helpers/rss_helper.php +++ b/app/Helpers/rss_helper.php @@ -11,6 +11,7 @@ use App\Entities\Category; use App\Entities\Location; use App\Entities\Podcast; use App\Libraries\SimpleRSSElement; +use App\Models\PodcastModel; use CodeIgniter\I18n\Time; use Config\Mimes; use Modules\Media\Entities\Chapters; @@ -69,6 +70,16 @@ if (! function_exists('get_rss_feed')) { $channel->addChild('generator', 'Castopod - https://castopod.org/'); $channel->addChild('docs', 'https://cyber.harvard.edu/rss/rss.html'); + if ($podcast->guid === '') { + // FIXME: guid shouldn't be empty here as it should be filled upon Podcast creation + $uuid = service('uuid'); + // 'ead4c236-bf58-58c6-a2c6-a6b28d128cb6' is the uuid of the podcast namespace + $podcast->guid = $uuid->uuid5('ead4c236-bf58-58c6-a2c6-a6b28d128cb6', $podcast->feed_url) + ->toString(); + + (new PodcastModel())->save($podcast); + } + $channel->addChild('guid', $podcast->guid, $podcastNamespace); $channel->addChild('title', $podcast->title, null, false); $channel->addChildWithCDATA('description', $podcast->description_html); diff --git a/app/Models/PodcastModel.php b/app/Models/PodcastModel.php index 9dd3763a..4372b1f4 100644 --- a/app/Models/PodcastModel.php +++ b/app/Models/PodcastModel.php @@ -351,7 +351,7 @@ class PodcastModel extends Model */ public function clearCache(array $data): array { - $podcast = (new self())->getPodcastById(is_array($data['id']) ? $data['id'][0] : $data['id']); + $podcast = (new self())->getPodcastById((int) (is_array($data['id']) ? $data['id'][0] : $data['id'])); // delete cache for users' podcasts cache() @@ -443,7 +443,7 @@ class PodcastModel extends Model */ protected function setActorAvatar(array $data): array { - $podcast = (new self())->getPodcastById(is_array($data['id']) ? $data['id'][0] : $data['id']); + $podcast = (new self())->getPodcastById((int) (is_array($data['id']) ? $data['id'][0] : $data['id'])); if ($podcast instanceof Podcast) { $podcastActor = (new ActorModel())->find($podcast->actor_id); @@ -468,7 +468,7 @@ class PodcastModel extends Model */ protected function updatePodcastActor(array $data): array { - $podcast = (new self())->getPodcastById(is_array($data['id']) ? $data['id'][0] : $data['id']); + $podcast = (new self())->getPodcastById((int) (is_array($data['id']) ? $data['id'][0] : $data['id'])); if ($podcast instanceof Podcast) { $actorModel = new ActorModel();