fix(rss): generate podcast guid if empty

closes #450
This commit is contained in:
Yassine Doghri 2024-04-06 11:47:49 +00:00
parent 13db54ccce
commit a5aef2a63e
2 changed files with 14 additions and 3 deletions

View File

@ -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);

View File

@ -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();