diff options
Diffstat (limited to 'Digitigrade/Model/FetchableModel.php')
| -rw-r--r-- | Digitigrade/Model/FetchableModel.php | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Digitigrade/Model/FetchableModel.php b/Digitigrade/Model/FetchableModel.php index c6bc291..fff7aeb 100644 --- a/Digitigrade/Model/FetchableModel.php +++ b/Digitigrade/Model/FetchableModel.php @@ -85,6 +85,14 @@ abstract class FetchableModel extends Model implements RemoteFetchable { if (!$obj->validate() || !PolicyManager::getInstance()->check($obj)) { return null; // and don't save } + + if (isset($obj->uri)) { + $isNew = $obj::countWhere('uri = ?', [$obj->uri]) == 0; + if ($isNew) { + $obj->onNewlyDiscovered(); + } + } + if ($autoSave) { $obj->save(); $obj->finaliseAfterSave(); @@ -99,6 +107,9 @@ abstract class FetchableModel extends Model implements RemoteFetchable { protected function finaliseAfterSave() { } + protected function onNewlyDiscovered() { + } + public static function findByUri(string $uri, bool $autoSave = true, bool $forceRefetch = false): ?static { if (!$forceRefetch) { $obj = static::findWhere('uri = ?', [$uri]); |
