` (`table`, `connection`, `map`). */ class ImportCommand extends Command { protected $signature = 'manager:import {target : posts, pages or reviews} {--table= : Table to read (default: config manager.import..table)} {--connection= : Database connection of that table (default: the default one)} {--map=* : package_column=source_column, repeat for each column that is named differently} {--limit= : Only the first rows} {--dry-run : Count what would happen and write nothing}'; protected $description = 'Copy the existing posts, pages or reviews of the site into the package tables'; public function handle(Importer $importer): int { $target = (string) $this->argument('target'); $config = (array) config('manager.import.'.$target, []); $table = $this->option('table') ?: ($config['table'] ?? null); if (! is_string($table) || $table === '') { $this->error('Which table? Give --table=... or set manager.import.'.$target.'.table.'); return self::FAILURE; } $map = (array) ($config['map'] ?? []); foreach ((array) $this->option('map') as $pair) { if (! str_contains((string) $pair, '=')) { $this->error("--map wants package_column=source_column, got {$pair}"); return self::FAILURE; } [$to, $from] = explode('=', (string) $pair, 2); $map[trim($to)] = trim($from); } try { $connection = DB::connection($this->option('connection') ?: ($config['connection'] ?? null)); $result = $importer->run($target, $connection, $table, $map, (bool) $this->option('dry-run'), $this->option('limit') !== null ? (int) $this->option('limit') : null); } catch (InvalidArgumentException $e) { $this->error($e->getMessage()); return self::FAILURE; } foreach ($result['problems'] as $problem) { $this->warn($problem); } $this->info(($this->option('dry-run') ? 'Dry run: ' : '')."{$result['created']} created, {$result['updated']} updated, {$result['skipped']} skipped."); return self::SUCCESS; } }