error('Nessun amministratore presente: impossibile procedere.'); return self::FAILURE; } $codesFilter = array_values(array_filter(array_map('trim', Arr::wrap($this->option('legacy'))))); $query = GesconImportMapping::query() ->whereNotNull('legacy_code') ->where('legacy_code', '!=', '') ->orderBy('legacy_code'); if (!empty($codesFilter)) { $query->whereIn('legacy_code', $codesFilter); } if ($limit = $this->option('limit')) { $query->limit((int) $limit); } $codes = $query->pluck('legacy_code')->unique()->values(); if ($codes->isEmpty()) { $this->warn('Nessuno stabile con legacy_code disponibile.'); return self::SUCCESS; } $svc = new EssentialImportService(); $path = $this->option('path') ?: null; $dry = (bool) $this->option('dry'); $this->info(sprintf('Import banche per %d stabili %s', $codes->count(), $dry ? '(DRY-RUN)' : '')); $errors = 0; foreach ($codes as $legacyCode) { try { $svc->importBanche($amm, (string) $legacyCode, ['path' => $path, 'dry' => $dry]); $this->line(sprintf('✓ [%s] completato', $legacyCode)); } catch (\Throwable $e) { $errors++; $this->error(sprintf('× [%s] %s', $legacyCode, $e->getMessage())); } } if ($errors > 0) { $this->warn(sprintf('Import concluso con %d errori.', $errors)); return self::FAILURE; } $this->info('Import banche completato con successo.'); return self::SUCCESS; } }