2020-08-18 16:31:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 PageModel extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'pages';
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
|
|
|
protected $allowedFields = ['id', 'title', 'slug', 'content'];
|
|
|
|
|
|
|
|
protected $returnType = \App\Entities\Page::class;
|
|
|
|
protected $useSoftDeletes = true;
|
|
|
|
|
|
|
|
protected $useTimestamps = true;
|
|
|
|
|
|
|
|
protected $validationRules = [
|
|
|
|
'title' => 'required',
|
|
|
|
'slug' =>
|
2021-04-20 13:43:38 +00:00
|
|
|
'required|regex_match[/^[a-zA-Z0-9\-]{1,191}$/]|is_unique[pages.slug,id,{id}]',
|
2020-08-18 16:31:28 +00:00
|
|
|
'content' => 'required',
|
|
|
|
];
|
|
|
|
protected $validationMessages = [];
|
|
|
|
|
2020-10-20 10:31:40 +00:00
|
|
|
// Before update because slug or title might change
|
|
|
|
protected $afterInsert = ['clearCache'];
|
2020-08-18 16:31:28 +00:00
|
|
|
protected $beforeUpdate = ['clearCache'];
|
|
|
|
protected $beforeDelete = ['clearCache'];
|
|
|
|
|
|
|
|
protected function clearCache(array $data)
|
|
|
|
{
|
2021-04-20 13:43:38 +00:00
|
|
|
// Clear the cache of all pages
|
|
|
|
cache()->deleteMatching('page*');
|
2020-08-18 16:31:28 +00:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|