Newer
Older
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace App\Models;
use CodeIgniter\Model;
class PodcastModel extends Model
{
protected $table = 'podcasts';
protected $primaryKey = 'id';
protected $allowedFields = [
'title',
'name',
'description',
'episode_description_footer',
'language',
'category',
'explicit',
'author_name',
'author_email',
'owner_name',
'owner_email',
'type',
'copyright',
'block',
'complete',
'custom_html_head',
];
protected $returnType = 'App\Entities\Podcast';
protected $useSoftDeletes = true;
protected $useTimestamps = true;

Yassine Doghri
committed
protected $afterInsert = ['clearCache'];
protected $afterUpdate = ['clearCache'];

Yassine Doghri
committed
protected function clearCache(array $data)
{
$podcast = $this->find(
is_array($data['id']) ? $data['id'][0] : $data['id']
);

Yassine Doghri
committed
// delete cache for rss feed and podcast pages

Yassine Doghri
committed
cache()->delete(md5($podcast->feed_url));
cache()->delete(md5($podcast->link));

Yassine Doghri
committed
// TODO: clear cache for every podcast's episode page?
// foreach ($podcast->episodes as $episode) {
// $cache->delete(md5($episode->link));
// }