startTime = microtime(true); $this->context = $context; Log::info("WeldLog Trigger [{$this->getOrder()}/14] {$this->getName()} - STARTED", [ 'weld_log_id' => $weldLogData->id, 'process' => $this->getName() ]); try { $result = $this->process($weldLogData, $beforeData, $context); $this->logCompletion($weldLogData->id, 'success', $result); return $result; } catch (\Throwable $th) { $this->logCompletion($weldLogData->id, 'error', [ 'error' => $th->getMessage(), 'file' => $th->getFile(), 'line' => $th->getLine() ]); throw $th; } } /** * Determine if trigger should run based on changed fields * * @param array $changedFields List of changed field names * @param bool $isNewRecord Whether this is a new record * @return bool */ public function shouldRun(array $changedFields, bool $isNewRecord): bool { if ($isNewRecord) { return true; } $dependentFields = $this->getDependentFields(); // If no dependent fields defined, always run if (empty($dependentFields)) { return true; } // Check if any changed field is in dependent fields return !empty(array_intersect($changedFields, $dependentFields)); } /** * Check if trigger is async (default: false) * Override in child classes if needed * * @return bool */ public function isAsync(): bool { return false; } /** * Log trigger completion with performance metrics * * @param int $weldLogId Weld log ID * @param string $status Execution status (success/error) * @param array $additionalData Additional log data */ protected function logCompletion($weldLogId, string $status, array $additionalData = []) { $duration = round((microtime(true) - $this->startTime) * 1000, 2); $logLevel = $status === 'error' ? 'error' : 'info'; Log::$logLevel("WeldLog Trigger [{$this->getOrder()}/14] {$this->getName()} - COMPLETED", array_merge([ 'weld_log_id' => $weldLogId, 'process' => $this->getName(), 'status' => $status, 'duration_ms' => $duration, 'duration_sec' => round($duration / 1000, 3) ], $additionalData)); } }