feat(cms): expose public document api and trigger site revalidation
This commit is contained in:
54
app/Observers/DocumentObserver.php
Normal file
54
app/Observers/DocumentObserver.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user