2019-11-27 22:19:20 +08:00
|
|
|
<?php
|
|
|
|
|
2019-12-13 04:07:35 +08:00
|
|
|
namespace Modules\Importer\Services\Importers;
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
use App\Models\Airline;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-12-13 04:07:35 +08:00
|
|
|
use Modules\Importer\Services\BaseImporter;
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
class AirlineImporter extends BaseImporter
|
|
|
|
{
|
2019-12-02 22:57:35 +08:00
|
|
|
public $table = 'airlines';
|
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
/**
|
|
|
|
* @param int $start
|
|
|
|
*/
|
|
|
|
public function run($start = 0)
|
|
|
|
{
|
|
|
|
$this->comment('--- AIRLINE IMPORT ---');
|
|
|
|
|
|
|
|
$count = 0;
|
2019-12-02 22:57:35 +08:00
|
|
|
foreach ($this->db->readRows($this->table, $start) as $row) {
|
|
|
|
$attrs = [
|
|
|
|
'iata' => $row->code,
|
|
|
|
'name' => $row->name,
|
|
|
|
'active' => $row->enabled,
|
|
|
|
];
|
|
|
|
|
|
|
|
$w = ['icao' => $row->code];
|
|
|
|
|
|
|
|
//$airline = Airline::firstOrCreate($w, $attrs);
|
|
|
|
$airline = Airline::create(array_merge($w, $attrs));
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
$this->idMapper->addMapping('airlines', $row->id, $airline->id);
|
|
|
|
$this->idMapper->addMapping('airlines', $row->code, $airline->id);
|
|
|
|
|
|
|
|
Log::debug('Mapping '.$row->id.'/'.$row->code.' to ID '.$airline->id);
|
|
|
|
|
|
|
|
if ($airline->wasRecentlyCreated) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->info('Imported '.$count.' airlines');
|
|
|
|
}
|
|
|
|
}
|