log("⚡ Procesando por lotes..."); $this->startProgress(); foreach ($parser->parseInChunks($path) as $chunk) { foreach ($chunk as $row) { $this->processSingleRow($row); $this->advanceProgress(); } } $this->finishProgress(); } /** * Procesa una sola fila dentro de un chunk. * * @param array $row * @return void */ protected function processSingleRow(array $row): void { try { $sanitized = $this->sanitizeRow($row); $modelClass = $this->getModelClass(); $uniqueBy = $this->getUniqueBy(); $modelClass::updateOrCreate( is_array($uniqueBy) ? array_intersect_key($sanitized, array_flip($uniqueBy)) : [$uniqueBy => $sanitized[$uniqueBy] ?? null], $sanitized ); $this->processedCount++; } catch (\Exception $e) { $this->log("⚠️ Error en fila: " . json_encode($row) . " - " . $e->getMessage()); } } }