X] records * @param array $requestData Cached request data */ public function __construct(string $tableName, array $ids, array $requestData, array $changedColumns = []) { $this->tableName = $tableName; $this->ids = $ids; $this->requestData = $requestData; $this->changedColumns = $changedColumns; $this->onQueue('save-trigger'); } public function uniqueId() { // Chunk'taki tüm ID'lerin hash'ini kullan (chunk çakışmasını önle) $idList = array_map(fn($item) => $item['id'] ?? 0, $this->ids); sort($idList); return $this->tableName . '_' . md5(implode(',', $idList)); } public function handle(): void { $startTime = microtime(true); $totalIds = count($this->ids); Log::info("=== ExecuteBatchExcelTriggersJob STARTED ===", [ 'table_name' => $this->tableName, 'total_ids' => $totalIds, ]); if (!\Illuminate\Support\Facades\Schema::hasTable($this->tableName)) { Log::critical("ExecuteBatchExcelTriggersJob FATAL ERROR: Table '{$this->tableName}' does not exist. ExecuteBatchExcelTriggersJob cannot proceed.", [ 'table_name' => $this->tableName, 'ids_count' => count($this->ids) ]); return; } $isLogTestType = in_array($this->tableName, log_test_types()); $isWeldLogs = ($this->tableName == "weld_logs"); foreach ($this->ids as $index => $recordIdData) { try { $recordId = (int) ($recordIdData['id'] ?? 0); if ($recordId <= 0) { Log::warning("ExecuteBatchExcelTriggersJob: Invalid record ID", ['data' => $recordIdData]); continue; } Log::info("ExecuteBatchExcelTriggersJob: Start processing ID: {$recordId}"); $recordData = db($this->tableName)->where('id', $recordId)->first(); if (!$recordData) { Log::info("ExecuteBatchExcelTriggersJob: ID {$recordId} not found in table '{$this->tableName}', skipping."); continue; } // 1. log_test_types: logToWeldlogUpdate + logToWPQUpdate if ($isLogTestType) { Log::info("ExecuteBatchExcelTriggersJob: Running logToWeldlogUpdate..."); $triggerData = (array) $recordData; if (function_exists('logToWeldlogUpdate')) { logToWeldlogUpdate($triggerData); } Log::info("ExecuteBatchExcelTriggersJob: Running logToWPQUpdate..."); if (function_exists('logToWPQUpdate')) { logToWPQUpdate($triggerData, $this->tableName); } } // 2. weld_logs: materialGroupUpdater if ($isWeldLogs && function_exists('materialGroupUpdater')) { Log::info("ExecuteBatchExcelTriggersJob: Running materialGroupUpdater..."); materialGroupUpdater($recordId); } // 3. SaveTrigger dosyasını çalıştır Log::info("ExecuteBatchExcelTriggersJob: Running SaveTrigger ({$this->tableName})..."); // include edilen dosya kendi global state'ini bozmasın diye taze bir scope kuralım (anonim fonksiyon ile de yapılabilirdi ama require/include olduğu için değişkenleri manuel veriyoruz) $tableName = $this->tableName; $request = is_array($this->requestData) ? $this->requestData : []; $request['key'] = $recordIdData; $key = $recordIdData; $values = null; $beforeData = null; // Batch Excel'de gerçek beforeData yok $changedColumns = $this->changedColumns; // Hangi sütunlar Excel'den güncellendi $action = "update"; $path = app_path("Http/Controllers/SaveTrigger/{$this->tableName}.php"); if (file_exists($path)) { include($path); } Log::info("ExecuteBatchExcelTriggersJob: SaveTrigger done."); } catch (\Throwable $th) { Log::error("ExecuteBatchExcelTriggersJob loop error", [ 'table_name' => $this->tableName, 'record_id' => $recordIdData['id'] ?? null, 'error' => $th->getMessage(), 'trace' => $th->getTraceAsString(), ]); // Diğer kayıtlara devam et continue; } } $executionTime = microtime(true) - $startTime; Log::info("=== ExecuteBatchExcelTriggersJob COMPLETED ===", [ 'table_name' => $this->tableName, 'total_ids' => $totalIds, 'execution_time_seconds' => round($executionTime, 2), ]); } public function tags(): array { $tableName = $this->tableName ?? 'unknown'; $idsCount = is_array($this->ids) ? count($this->ids) : 0; return [ "BatchExcelTriggers:{$tableName}", "Count:{$idsCount}", ]; } }