23eb9dcbda
* 384 Laravel 6 changes * Library versions * Update package versions * Add keyType to models * Remove unused dependencies * StyleCI fixes * Fix models for test * Fix tests output and update test runner * Unused imports * Update exceptions handler * Fix login page
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Console\Command;
|
|
use App\Services\ImportService;
|
|
|
|
class ImportCsv extends Command
|
|
{
|
|
protected $signature = 'phpvms:csv-import {type} {file}';
|
|
protected $description = 'Import from a CSV file';
|
|
|
|
private $importer;
|
|
|
|
/**
|
|
* Import constructor.
|
|
*
|
|
* @param ImportService $importer
|
|
*/
|
|
public function __construct(ImportService $importer)
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->importer = $importer;
|
|
}
|
|
|
|
/**
|
|
* @throws \Illuminate\Validation\ValidationException
|
|
*
|
|
* @return mixed|void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$type = $this->argument('type');
|
|
$file = $this->argument('file');
|
|
|
|
if (\in_array($type, ['flight', 'flights'], true)) {
|
|
$status = $this->importer->importFlights($file);
|
|
} elseif ($type === 'aircraft') {
|
|
$status = $this->importer->importAircraft($file);
|
|
} elseif (\in_array($type, ['airport', 'airports'], true)) {
|
|
$status = $this->importer->importAirports($file);
|
|
} elseif ($type === 'subfleet') {
|
|
$status = $this->importer->importSubfleets($file);
|
|
}
|
|
|
|
foreach ($status['success'] as $line) {
|
|
$this->info($line);
|
|
}
|
|
|
|
foreach ($status['errors'] as $line) {
|
|
$this->error($line);
|
|
}
|
|
}
|
|
}
|