İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\WeldLogTriggers\Triggers;
|
||||
|
||||
use App\Services\WeldLogTriggers\Base\BaseTrigger;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* NDT Calculation Cache Trigger
|
||||
*
|
||||
* Updates the NDT calculation cache when relevant fields are modified.
|
||||
* This ensures the frontend displays up-to-date NDT backlog and status information
|
||||
* without needing to run heavy calculations on every page load.
|
||||
*/
|
||||
class NdtCalculationCacheTrigger extends BaseTrigger
|
||||
{
|
||||
/**
|
||||
* Get trigger name
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'NdtCalculationCacheTrigger';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get trigger execution order
|
||||
* Running as #14 (after all other updates)
|
||||
*/
|
||||
public function getOrder(): int
|
||||
{
|
||||
return 14;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fields that this trigger depends on
|
||||
* Includes all fields used in ndt-calculation-no-cache.blade.php
|
||||
*/
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return [
|
||||
// Identifiers
|
||||
'iso_number',
|
||||
'test_package_no',
|
||||
'welder_1',
|
||||
'welder_2',
|
||||
'type_of_welds',
|
||||
'welding_date',
|
||||
|
||||
// Scopes and Results
|
||||
'rt_scope', 'rt_result', 'rt_test_date', 'rt_request_date',
|
||||
'ut_scope', 'ut_result', 'ut_test_date', 'ut_request_date',
|
||||
'pt_scope', 'pt_result', 'pt_test_date', 'pt_request_date',
|
||||
'mt_scope', 'mt_result', 'mt_test_date', 'mt_request_date',
|
||||
'pmi_scope', 'pmi_result', 'pmi_test_date', 'pmi_request_date',
|
||||
'ferrite_scope', 'ferrite_result', 'ferrite_test_date', 'ferrite_request_date',
|
||||
'ht_scope', 'ht_result', 'ht_test_date', 'ht_request_date',
|
||||
'test_laboratory_ht',
|
||||
'test_laboratory_rt',
|
||||
'test_laboratory_ut',
|
||||
'test_laboratory_pt',
|
||||
'test_laboratory_mt',
|
||||
'test_laboratory_pmi',
|
||||
'test_laboratory_ferrite',
|
||||
'test_laboratory_pwht',
|
||||
'test_laboratory_vt',
|
||||
'ut_request_date',
|
||||
'pt_request_date',
|
||||
'mt_request_date',
|
||||
'pmi_request_date',
|
||||
'ferrite_request_date',
|
||||
'ht_request_date',
|
||||
'rt_request_date',
|
||||
'vt_request_date',
|
||||
'pwht_request_date',
|
||||
|
||||
// PWHT
|
||||
'pwht', 'pwht_date', 'pwht_result'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process trigger logic
|
||||
* Dispatches cache update job for NDT calculation
|
||||
*/
|
||||
protected function process($weldLogData, $beforeData, array $context): array
|
||||
{
|
||||
// Clone işleminde cache hesaplaması yapma
|
||||
if (isset($context['action']) && $context['action'] === 'clone') {
|
||||
Log::info('NdtCalculationCacheTrigger: Skipped due to clone action');
|
||||
return ['skipped' => true, 'reason' => 'clone_action'];
|
||||
}
|
||||
|
||||
$dispatched = false;
|
||||
|
||||
// Using the global helper function to dispatch the cache update
|
||||
// This matches the usage in test2.blade.php provided by the user
|
||||
if (function_exists('dispatchCacheBladeViews')) {
|
||||
dispatchCacheBladeViews([
|
||||
[
|
||||
'view' => 'admin-ajax.request-ndt-no-cache',
|
||||
'cache' => 'request-ndt'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.ndt-order.order-list-no-cache',
|
||||
'cache' => 'ndt-order-list'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.repair-log-no-cache',
|
||||
'cache' => 'repair-log'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.ndt-calculation-no-cache',
|
||||
'cache' => 'ndt-calculation'
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
]);
|
||||
|
||||
$dispatched = true;
|
||||
|
||||
Log::info('NdtCalculationCacheTrigger: Cache update dispatched', [
|
||||
'weld_log_id' => $weldLogData->id,
|
||||
'iso' => $weldLogData->iso_number ?? 'unknown'
|
||||
]);
|
||||
} else {
|
||||
Log::warning('NdtCalculationCacheTrigger: dispatchCacheBladeViews function not found');
|
||||
}
|
||||
|
||||
return [
|
||||
'cache_dispatched' => $dispatched
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow async execution since this is just dispatching another job
|
||||
*/
|
||||
public function isAsync(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user