> */ private array $importers = [ InstitutionImporter::class, ]; public function handle(): int { $dryRun = (bool) $this->option('dry-run'); $only = array_map('strtolower', (array) $this->option('only')); try { DB::connection('legacy')->getPdo(); } catch (Throwable $e) { $this->error('Legacy connection unavailable: '.$e->getMessage()); $this->line('Set DB_LEGACY_* in the environment (see config/database.php → connections.legacy).'); return self::FAILURE; } if ($dryRun) { $this->warn('DRY-RUN: no data will be written.'); } $hadError = false; foreach ($this->importers as $class) { /** @var Importer $importer */ $importer = app($class); if ($only !== [] && ! in_array($importer->key(), $only, true)) { continue; } $this->info("→ {$importer->label()}"); try { $summary = $importer->import($dryRun); } catch (Throwable $e) { $this->error(" {$importer->key()} failed: ".$e->getMessage()); $hadError = true; continue; } foreach ($summary->warnings as $warning) { $this->warn(' ! '.$warning); } $this->line(sprintf( ' %screated %d, updated %d, skipped %d (total %d)', $dryRun ? '[dry-run] ' : '', $summary->created, $summary->updated, $summary->skipped, $summary->total(), )); } return $hadError ? self::FAILURE : self::SUCCESS; } }