2020-05-31 19:15:52 +00:00
|
|
|
<?php
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
|
|
|
class PodcastModel extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'podcasts';
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
|
|
|
protected $allowedFields = [
|
2020-06-10 15:00:12 +00:00
|
|
|
'id',
|
2020-05-31 19:15:52 +00:00
|
|
|
'title',
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'episode_description_footer',
|
2020-06-26 14:34:52 +00:00
|
|
|
'image_uri',
|
2020-05-31 19:15:52 +00:00
|
|
|
'language',
|
|
|
|
'category',
|
|
|
|
'explicit',
|
2020-06-26 14:34:52 +00:00
|
|
|
'author_name',
|
|
|
|
'author_email',
|
2020-05-31 19:15:52 +00:00
|
|
|
'owner_name',
|
|
|
|
'owner_email',
|
|
|
|
'type',
|
|
|
|
'copyright',
|
|
|
|
'block',
|
|
|
|
'complete',
|
|
|
|
'custom_html_head',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $returnType = 'App\Entities\Podcast';
|
2020-06-30 18:17:41 +02:00
|
|
|
protected $useSoftDeletes = true;
|
2020-05-31 19:15:52 +00:00
|
|
|
|
|
|
|
protected $useTimestamps = true;
|
2020-06-30 18:17:41 +02:00
|
|
|
|
2020-07-02 10:08:32 +00:00
|
|
|
protected $afterInsert = ['clearCache'];
|
|
|
|
protected $afterUpdate = ['clearCache'];
|
2020-06-30 18:17:41 +02:00
|
|
|
|
2020-07-02 10:08:32 +00:00
|
|
|
protected function clearCache(array $data)
|
2020-06-30 18:17:41 +02:00
|
|
|
{
|
|
|
|
$podcast = $this->find(
|
|
|
|
is_array($data['id']) ? $data['id'][0] : $data['id']
|
|
|
|
);
|
|
|
|
|
|
|
|
$cache = \Config\Services::cache();
|
|
|
|
|
2020-07-02 10:08:32 +00:00
|
|
|
// delete cache for rss feed and podcast pages
|
2020-06-30 18:17:41 +02:00
|
|
|
$cache->delete(md5($podcast->feed_url));
|
2020-07-02 10:08:32 +00:00
|
|
|
$cache->delete(md5($podcast->link));
|
|
|
|
// TODO: clear cache for every podcast's episode page?
|
|
|
|
// foreach ($podcast->episodes as $episode) {
|
|
|
|
// $cache->delete(md5($episode->link));
|
|
|
|
// }
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|