55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Observers;
|
|
|
|
use App\Models\Document;
|
|
use App\Services\SiteRevalidationService;
|
|
|
|
class DocumentObserver
|
|
{
|
|
private const RELEVANT_FIELDS = [
|
|
'title',
|
|
'document_number',
|
|
'description',
|
|
'document_category_id',
|
|
'access_level',
|
|
'status',
|
|
'archived_at',
|
|
'current_version_id',
|
|
'version_count',
|
|
'expires_at',
|
|
'auto_archive_on_expiry',
|
|
'expiry_notice',
|
|
'deleted_at',
|
|
];
|
|
|
|
public function created(Document $document): void
|
|
{
|
|
$this->revalidate($document);
|
|
}
|
|
|
|
public function updated(Document $document): void
|
|
{
|
|
if (! $document->wasChanged(self::RELEVANT_FIELDS)) {
|
|
return;
|
|
}
|
|
|
|
$this->revalidate($document);
|
|
}
|
|
|
|
public function deleted(Document $document): void
|
|
{
|
|
$this->revalidate($document);
|
|
}
|
|
|
|
public function restored(Document $document): void
|
|
{
|
|
$this->revalidate($document);
|
|
}
|
|
|
|
private function revalidate(Document $document): void
|
|
{
|
|
SiteRevalidationService::revalidateDocument($document->public_uuid);
|
|
}
|
|
}
|