27 lines
1.0 KiB
PHP
27 lines
1.0 KiB
PHP
<?php
|
|
|
|
use Illuminate\Foundation\Inspiring;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use App\Support\CardCsvImporter;
|
|
|
|
Artisan::command('inspire', function () {
|
|
$this->comment(Inspiring::quote());
|
|
})->purpose('Display an inspiring quote');
|
|
|
|
// Import cards from CSV via CLI without a custom Console Kernel (Laravel 12 console routes)
|
|
Artisan::command('cards:import {file : Absolute path to the CSV file} {--delimiter=, : CSV delimiter} {--dry-run : Parse without writing}', function (string $file) {
|
|
$delimiter = (string) $this->option('delimiter');
|
|
$dryRun = (bool) $this->option('dry-run');
|
|
|
|
$importer = new CardCsvImporter();
|
|
try {
|
|
[$inserted, $updated, $skipped] = $importer->import($file, $delimiter, $dryRun);
|
|
if ($dryRun) {
|
|
$this->info("Dry run complete.");
|
|
}
|
|
$this->info("Import finished. Inserted: {$inserted}, Updated: {$updated}, Skipped: {$skipped}");
|
|
} catch (\Throwable $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
})->purpose('Import cards from a CSV file (upsert by name).');
|