Add importers in console and admin for flights/aircraft/subfleets and airport #194
This commit is contained in:
59
app/Console/Commands/ImportCsv.php
Normal file
59
app/Console/Commands/ImportCsv.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Console\Command;
|
||||
use App\Services\ImporterService;
|
||||
|
||||
/**
|
||||
* Class ImportCsv
|
||||
* @package App\Console\Commands
|
||||
*/
|
||||
class ImportCsv extends Command
|
||||
{
|
||||
protected $signature = 'phpvms:csv-import {type} {file}';
|
||||
protected $description = 'Import from a CSV file';
|
||||
|
||||
private $importer;
|
||||
|
||||
/**
|
||||
* Import constructor.
|
||||
* @param ImporterService $importer
|
||||
*/
|
||||
public function __construct(ImporterService $importer)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->importer = $importer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
* @throws \League\Csv\Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$type = $this->argument('type');
|
||||
$file = $this->argument('file');
|
||||
|
||||
if (\in_array($type, ['flight', 'flights'])) {
|
||||
$status = $this->importer->importFlights($file);
|
||||
} elseif ($type === 'aircraft') {
|
||||
$status = $this->importer->importAircraft($file);
|
||||
} elseif (\in_array($type, ['airport', 'airports'])) {
|
||||
$status = $this->importer->importAirports($file);
|
||||
} elseif ($type === 'subfleet') {
|
||||
$status = $this->importer->importSubfleets($file);
|
||||
}
|
||||
|
||||
foreach($status['success'] as $line) {
|
||||
$this->info($line);
|
||||
}
|
||||
|
||||
foreach ($status['failed'] as $line) {
|
||||
$this->error($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user