2020-06-08 20:32:42 +00:00
< ? php
2020-08-04 11:25:22 +00:00
2021-06-08 09:52:11 +00:00
declare ( strict_types = 1 );
2020-06-10 15:00:12 +00:00
/**
2022-02-19 16:06:11 +00:00
* @ copyright 2020 Ad Aures
2020-06-10 15:00:12 +00:00
* @ license https :// www . gnu . org / licenses / agpl - 3.0 . en . html AGPL3
* @ link https :// castopod . org /
*/
2020-06-08 20:32:42 +00:00
namespace App\Models ;
2021-05-06 14:00:48 +00:00
use App\Entities\Episode ;
2023-06-21 10:07:31 +00:00
use CodeIgniter\Database\BaseBuilder ;
2022-06-13 16:30:34 +00:00
use CodeIgniter\Database\BaseResult ;
2022-01-06 16:52:13 +00:00
use CodeIgniter\I18n\Time ;
2023-08-28 13:53:04 +00:00
use Michalsn\Uuid\UuidModel ;
use Ramsey\Uuid\Lazy\LazyUuidFromString ;
2020-06-08 20:32:42 +00:00
2023-08-28 13:53:04 +00:00
class EpisodeModel extends UuidModel
2020-06-08 20:32:42 +00:00
{
2021-05-06 14:00:48 +00:00
/**
2021-05-31 13:32:33 +00:00
* TODO : remove , shouldn ' t be here
*
2021-05-06 14:00:48 +00:00
* @ var array < string , array < string , string >>
*/
public static $themes = [
'light-transparent' => [
2023-06-12 14:47:38 +00:00
'style' => 'background-color: #fff; background-image: linear-gradient(45deg, #ccc 12.5%, transparent 12.5%, transparent 50%, #ccc 50%, #ccc 62.5%, transparent 62.5%, transparent 100%); background-size: 5.66px 5.66px;' ,
2021-05-06 14:00:48 +00:00
'background' => 'transparent' ,
2023-06-12 14:47:38 +00:00
'text' => '#000' ,
'inverted' => '#fff' ,
2021-05-06 14:00:48 +00:00
],
'light' => [
2023-06-12 14:47:38 +00:00
'style' => 'background-color: #fff;' ,
2021-05-06 14:00:48 +00:00
'background' => '#fff' ,
2023-06-12 14:47:38 +00:00
'text' => '#000' ,
'inverted' => '#fff' ,
2021-05-06 14:00:48 +00:00
],
'dark-transparent' => [
2023-06-12 14:47:38 +00:00
'style' => 'background-color: #001f1a; background-image: linear-gradient(45deg, #888 12.5%, transparent 12.5%, transparent 50%, #888 50%, #888 62.5%, transparent 62.5%, transparent 100%); background-size: 5.66px 5.66px;' ,
2021-05-06 14:00:48 +00:00
'background' => 'transparent' ,
2023-06-12 14:47:38 +00:00
'text' => '#fff' ,
'inverted' => '#000' ,
2021-05-06 14:00:48 +00:00
],
'dark' => [
2023-06-12 14:47:38 +00:00
'style' => 'background-color: #001f1a;' ,
2021-08-09 10:28:16 +00:00
'background' => '#313131' ,
2023-06-12 14:47:38 +00:00
'text' => '#fff' ,
'inverted' => '#000' ,
2021-05-06 14:00:48 +00:00
],
];
2021-05-19 16:35:13 +00:00
2023-08-28 13:53:04 +00:00
/**
* @ var string []
*/
protected $uuidFields = [ 'preview_id' ];
2021-05-06 14:00:48 +00:00
/**
* @ var string
*/
2020-06-08 20:32:42 +00:00
protected $table = 'episodes' ;
2021-05-19 16:35:13 +00:00
2021-05-06 14:00:48 +00:00
/**
2024-04-26 09:26:22 +00:00
* @ var list < string >
2021-05-06 14:00:48 +00:00
*/
2020-06-08 20:32:42 +00:00
protected $allowedFields = [
2021-04-02 17:20:02 +00:00
'id' ,
2020-06-10 15:00:12 +00:00
'podcast_id' ,
2023-08-28 13:53:04 +00:00
'preview_id' ,
2020-08-21 08:41:09 +00:00
'guid' ,
2020-06-08 20:32:42 +00:00
'title' ,
2020-06-10 15:00:12 +00:00
'slug' ,
2021-12-17 17:14:37 +00:00
'audio_id' ,
2020-10-29 15:45:19 +00:00
'description_markdown' ,
'description_html' ,
2021-12-14 16:41:10 +00:00
'cover_id' ,
2021-12-17 17:14:37 +00:00
'transcript_id' ,
'transcript_remote_url' ,
'chapters_id' ,
'chapters_remote_url' ,
2020-10-02 15:38:16 +00:00
'parental_advisory' ,
2020-06-12 19:31:10 +00:00
'number' ,
2020-06-08 20:32:42 +00:00
'season_number' ,
'type' ,
2020-10-29 15:45:19 +00:00
'is_blocked' ,
2020-12-23 14:11:38 +00:00
'location_name' ,
'location_geo' ,
2021-05-17 17:11:23 +00:00
'location_osm' ,
2021-03-19 16:12:36 +00:00
'custom_rss' ,
2022-03-15 16:47:35 +00:00
'is_published_on_hubs' ,
2021-08-13 11:07:29 +00:00
'posts_count' ,
'comments_count' ,
2022-09-28 15:02:09 +00:00
'is_premium' ,
2020-08-14 18:27:57 +00:00
'published_at' ,
'created_by' ,
'updated_by' ,
2020-06-08 20:32:42 +00:00
];
2021-05-06 14:00:48 +00:00
/**
* @ var string
*/
protected $returnType = Episode :: class ;
2020-06-08 20:32:42 +00:00
2021-05-06 14:00:48 +00:00
/**
* @ var bool
*/
2020-06-08 20:32:42 +00:00
protected $useTimestamps = true ;
2020-06-30 18:17:41 +02:00
2021-05-06 14:00:48 +00:00
/**
* @ var array < string , string >
*/
2020-07-16 10:08:23 +00:00
protected $validationRules = [
2023-06-12 14:47:38 +00:00
'podcast_id' => 'required' ,
'title' => 'required' ,
'slug' => 'required|regex_match[/^[a-zA-Z0-9\-]{1,128}$/]' ,
'audio_id' => 'required' ,
'description_markdown' => 'required' ,
'number' => 'is_natural_no_zero|permit_empty' ,
'season_number' => 'is_natural_no_zero|permit_empty' ,
'type' => 'required' ,
2022-03-04 14:33:48 +00:00
'transcript_remote_url' => 'valid_url_strict|permit_empty' ,
2023-06-12 14:47:38 +00:00
'chapters_remote_url' => 'valid_url_strict|permit_empty' ,
'published_at' => 'valid_date|permit_empty' ,
'created_by' => 'required' ,
'updated_by' => 'required' ,
2020-07-16 10:08:23 +00:00
];
2021-05-06 14:00:48 +00:00
/**
2024-04-26 09:26:22 +00:00
* @ var list < string >
2021-05-06 14:00:48 +00:00
*/
2020-10-22 17:41:59 +00:00
protected $afterInsert = [ 'writeEnclosureMetadata' , 'clearCache' ];
2021-05-19 16:35:13 +00:00
2021-05-06 14:00:48 +00:00
/**
2024-04-26 09:26:22 +00:00
* @ var list < string >
2021-05-06 14:00:48 +00:00
*/
2021-05-31 13:32:33 +00:00
protected $afterUpdate = [ 'clearCache' , 'writeEnclosureMetadata' ];
2021-02-27 21:21:26 +00:00
2021-04-02 17:20:02 +00:00
/**
2024-04-26 09:26:22 +00:00
* @ var list < string >
2021-04-02 17:20:02 +00:00
*/
2021-05-06 14:00:48 +00:00
protected $beforeDelete = [ 'clearCache' ];
2021-07-26 13:10:46 +00:00
public function getEpisodeBySlug ( string $podcastHandle , string $episodeSlug ) : ? Episode
2021-05-12 14:00:25 +00:00
{
2021-07-26 13:10:46 +00:00
$cacheName = " podcast- { $podcastHandle } _episode- { $episodeSlug } " ;
2021-05-19 16:35:13 +00:00
if ( ! ( $found = cache ( $cacheName ))) {
2021-05-31 13:32:33 +00:00
$found = $this -> select ( 'episodes.*' )
-> join ( 'podcasts' , 'podcasts.id = episodes.podcast_id' )
2021-04-02 17:20:02 +00:00
-> where ( 'slug' , $episodeSlug )
2021-07-26 13:10:46 +00:00
-> where ( 'podcasts.handle' , $podcastHandle )
2022-07-05 16:39:20 +00:00
-> where ( '`' . $this -> db -> getPrefix () . 'episodes`.`published_at` <= UTC_TIMESTAMP()' , null , false )
2021-05-31 13:32:33 +00:00
-> first ();
2020-09-04 09:09:26 +00:00
2021-05-19 16:35:13 +00:00
cache ()
-> save ( $cacheName , $found , DECADE );
2020-09-04 09:09:26 +00:00
}
return $found ;
}
2021-05-14 17:59:35 +00:00
public function getEpisodeById ( int $episodeId ) : ? Episode
2021-02-10 16:20:01 +00:00
{
2021-04-22 17:20:28 +00:00
// TODO: episode id should be a composite key. The cache should include podcast_id.
2021-04-20 13:43:38 +00:00
$cacheName = " podcast_episode# { $episodeId } " ;
2021-05-19 16:35:13 +00:00
if ( ! ( $found = cache ( $cacheName ))) {
2021-04-02 17:20:02 +00:00
$builder = $this -> where ([
2021-02-10 16:20:01 +00:00
'id' => $episodeId ,
2021-04-02 17:20:02 +00:00
]);
2021-02-10 16:20:01 +00:00
2021-04-02 17:20:02 +00:00
$found = $builder -> first ();
2021-05-19 16:35:13 +00:00
cache ()
-> save ( $cacheName , $found , DECADE );
2021-02-10 16:20:01 +00:00
}
return $found ;
}
2021-05-14 17:59:35 +00:00
public function getPublishedEpisodeById ( int $podcastId , int $episodeId ) : ? Episode
2020-10-20 10:31:40 +00:00
{
2021-04-22 17:20:28 +00:00
$cacheName = " podcast# { $podcastId } _episode# { $episodeId } _published " ;
2021-05-19 16:35:13 +00:00
if ( ! ( $found = cache ( $cacheName ))) {
2021-04-22 17:20:28 +00:00
$found = $this -> where ([
2021-04-02 17:20:02 +00:00
'id' => $episodeId ,
2021-04-22 17:20:28 +00:00
])
-> where ( 'podcast_id' , $podcastId )
2022-04-14 14:33:53 +00:00
-> where ( '`published_at` <= UTC_TIMESTAMP()' , null , false )
2021-04-22 17:20:28 +00:00
-> first ();
2020-10-20 10:31:40 +00:00
2021-05-19 16:35:13 +00:00
cache ()
-> save ( $cacheName , $found , DECADE );
2021-04-02 17:20:02 +00:00
}
return $found ;
2020-10-20 10:31:40 +00:00
}
2023-08-28 13:53:04 +00:00
public function getEpisodeByPreviewId ( string $previewId ) : ? Episode
{
$cacheName = " podcast_episode#preview- { $previewId } " ;
if ( ! ( $found = cache ( $cacheName ))) {
$builder = $this -> where ([
'preview_id' => $this -> uuid -> fromString ( $previewId )
-> getBytes (),
]);
$found = $builder -> first ();
cache ()
-> save ( $cacheName , $found , DECADE );
}
return $found ;
}
public function setEpisodePreviewId ( int $episodeId ) : string | false
{
/** @var LazyUuidFromString $uuid */
$uuid = $this -> uuid -> { $this -> uuidVersion }();
if ( ! $this -> update ( $episodeId , [
'preview_id' => $uuid ,
])) {
return false ;
}
return ( string ) $uuid ;
}
2020-07-10 12:20:25 +00:00
/**
2021-05-19 16:35:13 +00:00
* Gets all episodes for a podcast ordered according to podcast type Filtered depending on year or season
2020-07-10 12:20:25 +00:00
*
2021-05-06 14:00:48 +00:00
* @ return Episode []
2020-07-10 12:20:25 +00:00
*/
2020-09-04 09:09:26 +00:00
public function getPodcastEpisodes (
int $podcastId ,
string $podcastType ,
string $year = null ,
string $season = null
) : array {
$cacheName = implode (
'_' ,
2021-05-19 16:35:13 +00:00
array_filter ([ " podcast# { $podcastId } " , $year , $season ? 'season' . $season : null , 'episodes' ]),
2020-09-04 09:09:26 +00:00
);
2021-05-19 16:35:13 +00:00
if ( ! ( $found = cache ( $cacheName ))) {
2020-10-22 17:41:59 +00:00
$where = [
'podcast_id' => $podcastId ,
];
2020-09-04 09:09:26 +00:00
if ( $year ) {
$where [ 'YEAR(published_at)' ] = $year ;
$where [ 'season_number' ] = null ;
}
2022-03-04 14:33:48 +00:00
2020-09-04 09:09:26 +00:00
if ( $season ) {
$where [ 'season_number' ] = $season ;
}
2021-05-19 16:35:13 +00:00
if ( $podcastType === 'serial' ) {
2020-09-04 09:09:26 +00:00
// podcast is serial
$found = $this -> where ( $where )
2022-04-14 14:33:53 +00:00
-> where ( '`published_at` <= UTC_TIMESTAMP()' , null , false )
2020-09-04 09:09:26 +00:00
-> orderBy ( 'season_number DESC, number ASC' )
-> findAll ();
} else {
$found = $this -> where ( $where )
2022-04-14 14:33:53 +00:00
-> where ( '`published_at` <= UTC_TIMESTAMP()' , null , false )
2020-09-04 09:09:26 +00:00
-> orderBy ( 'published_at' , 'DESC' )
-> findAll ();
}
2021-06-08 09:52:11 +00:00
$secondsToNextUnpublishedEpisode = $this -> getSecondsToNextUnpublishedEpisode ( $podcastId );
2020-10-22 17:41:59 +00:00
2021-05-19 16:35:13 +00:00
cache ()
2024-04-26 09:26:22 +00:00
-> save ( $cacheName , $found , $secondsToNextUnpublishedEpisode ? : DECADE );
2020-09-04 09:09:26 +00:00
}
return $found ;
}
2022-05-05 15:48:16 +00:00
/**
* Returns number of episodes of a podcast
*/
public function getPodcastEpisodesCount ( int $podcastId ) : int | string
{
return $this
-> where ([
'podcast_id' => $podcastId ,
])
-> countAllResults ();
}
2020-10-22 17:41:59 +00:00
/**
2021-05-19 16:35:13 +00:00
* Returns the timestamp difference in seconds between the next episode to publish and the current timestamp Returns
* false if there ' s no episode to publish
2020-10-22 17:41:59 +00:00
*
2021-05-31 13:32:33 +00:00
* @ return int | false seconds
2020-10-22 17:41:59 +00:00
*/
2021-05-31 13:32:33 +00:00
public function getSecondsToNextUnpublishedEpisode ( int $podcastId ) : int | false
2020-10-22 17:41:59 +00:00
{
2022-06-13 16:30:34 +00:00
$result = $this -> builder ()
-> select ( 'TIMESTAMPDIFF(SECOND, UTC_TIMESTAMP(), `published_at`) as timestamp_diff' )
2020-10-22 17:41:59 +00:00
-> where ([
'podcast_id' => $podcastId ,
])
2022-04-14 14:33:53 +00:00
-> where ( '`published_at` > UTC_TIMESTAMP()' , null , false )
2020-10-22 17:41:59 +00:00
-> orderBy ( 'published_at' , 'asc' )
-> get ()
-> getResultArray ();
2021-05-31 13:32:33 +00:00
return $result !== []
2021-05-12 14:00:25 +00:00
? ( int ) $result [ 0 ][ 'timestamp_diff' ]
: false ;
2020-10-22 17:41:59 +00:00
}
2022-01-05 16:01:44 +00:00
public function getCurrentSeasonNumber ( int $podcastId ) : ? int
{
2022-06-13 16:30:34 +00:00
$result = $this -> builder ()
2023-06-21 16:17:11 +00:00
-> selectMax ( 'season_number' , 'current_season_number' )
2024-01-25 11:58:39 +00:00
-> where ( 'podcast_id' , $podcastId )
-> where ( '`published_at` <= UTC_TIMESTAMP()' , null , false )
2022-01-05 16:01:44 +00:00
-> get ()
-> getResultArray ();
return $result [ 0 ][ 'current_season_number' ] ? ( int ) $result [ 0 ][ 'current_season_number' ] : null ;
}
public function getNextEpisodeNumber ( int $podcastId , ? int $seasonNumber ) : int
{
2022-06-13 16:30:34 +00:00
$result = $this -> builder ()
2023-06-21 16:17:11 +00:00
-> selectMax ( 'number' , 'next_episode_number' )
2022-01-05 16:01:44 +00:00
-> where ([
2024-01-25 11:58:39 +00:00
'podcast_id' => $podcastId ,
'season_number' => $seasonNumber ,
])
-> where ( '`published_at` <= UTC_TIMESTAMP()' , null , false )
-> get ()
2022-01-05 16:01:44 +00:00
-> getResultArray ();
return ( int ) $result [ 0 ][ 'next_episode_number' ] + 1 ;
}
2022-01-06 16:52:13 +00:00
/**
2022-07-03 16:42:20 +00:00
* @ return array { number_of_seasons : int , number_of_episodes : int , first_published_at ? : Time }
2022-01-06 16:52:13 +00:00
*/
public function getPodcastStats ( int $podcastId ) : array
{
2022-06-13 16:30:34 +00:00
$result = $this -> builder ()
-> select (
'COUNT(DISTINCT season_number) as number_of_seasons, COUNT(*) as number_of_episodes, MIN(published_at) as first_published_at'
)
2024-01-25 11:58:39 +00:00
-> where ( 'podcast_id' , $podcastId )
-> where ( '`published_at` <= UTC_TIMESTAMP()' , null , false )
-> get ()
2022-01-06 16:52:13 +00:00
-> getResultArray ();
$stats = [
2023-06-12 14:47:38 +00:00
'number_of_seasons' => ( int ) $result [ 0 ][ 'number_of_seasons' ],
2022-01-06 16:52:13 +00:00
'number_of_episodes' => ( int ) $result [ 0 ][ 'number_of_episodes' ],
];
if ( $result [ 0 ][ 'first_published_at' ] !== null ) {
$stats [ 'first_published_at' ] = new Time ( $result [ 0 ][ 'first_published_at' ]);
}
return $stats ;
}
2022-01-14 17:42:55 +00:00
public function resetCommentsCount () : int | false
{
2022-07-21 16:21:26 +00:00
$episodeCommentsCount = ( new EpisodeCommentModel ()) -> builder ()
-> select ( 'episode_id, COUNT(*) as `comments_count`' )
2022-01-14 17:42:55 +00:00
-> where ( 'in_reply_to_id' , null )
2022-07-21 16:21:26 +00:00
-> groupBy ( 'episode_id' )
2022-01-14 17:42:55 +00:00
-> getCompiledSelect ();
2022-07-21 16:21:26 +00:00
$episodePostsRepliesCount = ( new PostModel ()) -> builder ()
2023-08-26 13:03:01 +00:00
-> select ( 'fediverse_posts.episode_id as episode_id, COUNT(*) as `comments_count`' )
-> join ( 'fediverse_posts as fp' , 'fediverse_posts.id = fp.in_reply_to_id' )
-> where ( 'fediverse_posts.in_reply_to_id' , null )
2023-11-30 15:46:00 +00:00
-> where ( 'fediverse_posts.episode_id IS NOT' , null )
2023-08-26 13:03:01 +00:00
-> groupBy ( 'fediverse_posts.episode_id' )
2022-01-14 17:42:55 +00:00
-> getCompiledSelect ();
2022-06-13 16:30:34 +00:00
/** @var BaseResult $query */
2022-01-14 17:42:55 +00:00
$query = $this -> db -> query (
2022-07-21 16:21:26 +00:00
'SELECT `episode_id` as `id`, SUM(`comments_count`) as `comments_count` FROM (' . $episodeCommentsCount . ' UNION ALL ' . $episodePostsRepliesCount . ') x GROUP BY `episode_id`'
2022-01-14 17:42:55 +00:00
);
$countsPerEpisodeId = $query -> getResultArray ();
if ( $countsPerEpisodeId !== []) {
2022-07-21 16:21:26 +00:00
return ( new self ()) -> updateBatch ( $countsPerEpisodeId , 'id' );
2022-01-14 17:42:55 +00:00
}
return 0 ;
}
public function resetPostsCount () : int | false
{
2022-06-13 16:30:34 +00:00
$episodePostsCount = $this -> builder ()
-> select ( 'episodes.id, COUNT(*) as `posts_count`' )
2023-08-26 13:03:01 +00:00
-> join ( 'fediverse_posts' , 'episodes.id = fediverse_posts.episode_id' )
2022-01-14 17:42:55 +00:00
-> where ( 'in_reply_to_id' , null )
-> groupBy ( 'episodes.id' )
-> get ()
-> getResultArray ();
if ( $episodePostsCount !== []) {
return $this -> updateBatch ( $episodePostsCount , 'id' );
}
return 0 ;
}
2021-05-06 14:00:48 +00:00
/**
2021-05-14 17:59:35 +00:00
* @ param mixed [] $data
2021-05-19 16:35:13 +00:00
*
2022-03-15 16:47:35 +00:00
* @ return mixed []
2021-05-06 14:00:48 +00:00
*/
2021-05-14 17:59:35 +00:00
public function clearCache ( array $data ) : array
2020-09-04 09:09:26 +00:00
{
2023-04-17 11:18:02 +00:00
/** @var int|null $episodeId */
$episodeId = is_array ( $data [ 'id' ]) ? $data [ 'id' ][ 0 ] : $data [ 'id' ];
if ( $episodeId === null ) {
// Multiple episodes have been updated, do nothing
return $data ;
}
/** @var ?Episode $episode */
$episode = ( new self ()) -> find ( $episodeId );
if ( ! $episode instanceof Episode ) {
return $data ;
}
2020-09-04 09:09:26 +00:00
2021-05-31 13:32:33 +00:00
// delete podcast cache
2021-05-19 16:35:13 +00:00
cache ()
2021-05-31 13:32:33 +00:00
-> deleteMatching ( " podcast# { $episode -> podcast_id } * " );
2021-05-19 16:35:13 +00:00
cache ()
2021-07-26 13:10:46 +00:00
-> deleteMatching ( " podcast- { $episode -> podcast -> handle } * " );
2021-05-19 16:35:13 +00:00
cache ()
-> delete ( " podcast_episode# { $episode -> id } " );
cache ()
2021-05-31 13:32:33 +00:00
-> deleteMatching ( " page_podcast# { $episode -> podcast_id } * " );
2021-05-19 16:35:13 +00:00
cache ()
-> deleteMatching ( 'page_credits_*' );
2021-09-17 15:50:55 +00:00
cache ()
-> delete ( 'episodes_markers' );
2020-10-20 10:31:40 +00:00
return $data ;
2020-09-04 09:09:26 +00:00
}
2021-05-06 14:00:48 +00:00
2022-09-28 15:02:09 +00:00
public function doesPodcastHavePremiumEpisodes ( int $podcastId ) : bool
{
return $this -> builder ()
-> where ([
'podcast_id' => $podcastId ,
'is_premium' => true ,
2023-08-28 14:01:33 +00:00
])
-> where ( '`published_at` <= UTC_TIMESTAMP()' , null , false )
-> countAllResults () > 0 ;
2022-09-28 15:02:09 +00:00
}
2023-06-21 10:07:31 +00:00
public function fullTextSearch ( string $query ) : ? BaseBuilder
{
$prefix = $this -> db -> getPrefix ();
$episodeTable = $prefix . $this -> builder () -> getTable ();
$podcastModel = ( new PodcastModel ());
$podcastTable = $podcastModel -> db -> getPrefix () . $podcastModel -> builder () -> getTable ();
$this -> builder ()
-> select ( '' . $episodeTable . '.*' )
-> select ( '
' . $this->getFullTextMatchClauseForEpisodes($episodeTable, $query) . ' as episodes_score ,
' . $podcastModel->getFullTextMatchClauseForPodcasts($podcastTable, $query) . ' as podcasts_score ,
' )
-> select ( " { $podcastTable } .created_at AS podcast_created_at " )
-> select (
" { $podcastTable } .title as podcast_title, { $podcastTable } .handle as podcast_handle, { $podcastTable } .description_markdown as podcast_description_markdown "
)
-> join ( $podcastTable , " { $podcastTable } on { $podcastTable } .id = { $episodeTable } .podcast_id " )
-> where ( '
( ' .
$this -> getFullTextMatchClauseForEpisodes ( $episodeTable , $query )
. 'OR' .
$podcastModel -> getFullTextMatchClauseForPodcasts ( $podcastTable , $query )
. ' )
' );
return $this -> builder ;
}
2023-06-21 16:17:11 +00:00
public function getFullTextMatchClauseForEpisodes ( string $table , string $value ) : string
{
return '
MATCH (
' . $table . ' . title ,
' . $table . ' . description_markdown ,
' . $table . ' . slug ,
' . $table . ' . location_name
)
AGAINST ( ' . $this->db->escape($value) . ' )
' ;
}
2021-05-06 14:00:48 +00:00
/**
2021-05-14 17:59:35 +00:00
* @ param mixed [] $data
2021-05-19 16:35:13 +00:00
*
2022-03-15 16:47:35 +00:00
* @ return mixed []
2021-05-06 14:00:48 +00:00
*/
protected function writeEnclosureMetadata ( array $data ) : array
{
2023-04-17 11:18:02 +00:00
/** @var int|null $episodeId */
$episodeId = is_array ( $data [ 'id' ]) ? $data [ 'id' ][ 0 ] : $data [ 'id' ];
2021-05-06 14:00:48 +00:00
2023-04-17 11:18:02 +00:00
if ( $episodeId === null ) {
// Multiple episodes have been updated, do nothing
return $data ;
}
/** @var ?Episode $episode */
$episode = ( new self ()) -> find ( $episodeId );
if ( ! $episode instanceof Episode ) {
return $data ;
}
helper ( 'id3' );
2021-05-06 14:00:48 +00:00
write_audio_file_tags ( $episode );
return $data ;
}
2020-06-08 20:32:42 +00:00
}