Files
citrus-cms/app/Observers/NaksCertificateObserver.php
T
2026-04-28 21:14:25 +03:00

43 lines
1.6 KiB
PHP

<?php
namespace App\Observers;
use App\Models\NaksCertificate;
use App\Jobs\TriggerNaksSyncJob;
use Illuminate\Support\Facades\Log;
class NaksCertificateObserver
{
/**
* Handle the NaksCertificate "updated" event.
*
* @param \App\Models\NaksCertificate $naksCertificate
* @return void
*/
public function updated(NaksCertificate $naksCertificate)
{
// Check if source_project was changed
if ($naksCertificate->wasChanged('source_project')) {
$newSource = $naksCertificate->source_project;
// If the source_project is now empty (NULL or ''), it means this project effectively
// took ownership or created a new version that should be treated as master.
// Or if we specifically want to propagate ANY change to source_project.
// The user said: "When I make 'Viksa' empty, it is saved with this project's name
// and triggers others".
// Assuming the "saved with this project's name" is logic handled elsewhere or implied
// by it being empty (Empty = This Project).
// We trigger the sync job.
Log::info("NaksCertificate updated: source_project changed to '{$newSource}'. Dispatching TriggerNaksSyncJob.");
TriggerNaksSyncJob::dispatch([
'module' => 'technology', // naks_certificates corresponds to technology module
'source_project' => config('app.name', 'Unknown Project'),
]);
}
}
}