2019-11-27 22:19:20 +08:00
|
|
|
<?php
|
|
|
|
|
2020-10-19 22:10:28 +08:00
|
|
|
namespace App\Services\Importers;
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
use App\Models\Airline;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
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;
|
2020-02-24 08:48:28 +08:00
|
|
|
$rows = $this->db->readRows($this->table, $this->idField, $start);
|
|
|
|
foreach ($rows as $row) {
|
2019-12-02 22:57:35 +08:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
}
|