93 lines
2.4 KiB
PHP
93 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\WeldLogTriggers\Triggers;
|
|
|
|
use App\Services\WeldLogTriggers\Base\BaseTrigger;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
* Register Creator Cache Trigger
|
|
*
|
|
* Updates the Register Creator cache when relevant fields are modified.
|
|
* This ensures the frontend displays up-to-date information in the register creator view.
|
|
*/
|
|
class RegisterCreatorCacheTrigger extends BaseTrigger
|
|
{
|
|
/**
|
|
* Get trigger name
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return 'RegisterCreatorCacheTrigger';
|
|
}
|
|
|
|
/**
|
|
* Get trigger execution order
|
|
* Running as #15 (after all other updates)
|
|
*/
|
|
public function getOrder(): int
|
|
{
|
|
return 15;
|
|
}
|
|
|
|
/**
|
|
* Get fields that this trigger depends on
|
|
*/
|
|
public function getDependentFields(): array
|
|
{
|
|
return [
|
|
'nps_1',
|
|
'welding_date',
|
|
'test_package_no',
|
|
'date_test',
|
|
'line_number',
|
|
'iso_number'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Process trigger logic
|
|
* Dispatches cache update job for Register Creator
|
|
*/
|
|
protected function process($weldLogData, $beforeData, array $context): array
|
|
{
|
|
// Skip for clone action
|
|
if (isset($context['action']) && $context['action'] === 'clone') {
|
|
Log::info('RegisterCreatorCacheTrigger: Skipped due to clone action');
|
|
return ['skipped' => true, 'reason' => 'clone_action'];
|
|
}
|
|
|
|
$dispatched = false;
|
|
|
|
if (function_exists('dispatchCacheBladeViews')) {
|
|
dispatchCacheBladeViews([
|
|
[
|
|
'view' => 'admin-ajax.register-no-cache',
|
|
'cache' => 'register-creator'
|
|
]
|
|
]);
|
|
|
|
$dispatched = true;
|
|
|
|
Log::info('RegisterCreatorCacheTrigger: Cache update dispatched', [
|
|
'weld_log_id' => $weldLogData->id,
|
|
'iso' => $weldLogData->iso_number ?? 'unknown'
|
|
]);
|
|
} else {
|
|
Log::warning('RegisterCreatorCacheTrigger: dispatchCacheBladeViews function not found');
|
|
}
|
|
|
|
return [
|
|
'cache_dispatched' => $dispatched
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Allow async execution since this is just dispatching another job
|
|
*/
|
|
public function isAsync(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|