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\Flight;
|
2019-12-13 04:07:35 +08:00
|
|
|
use Modules\Importer\Services\BaseImporter;
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
class FlightImporter extends BaseImporter
|
|
|
|
{
|
2019-12-02 22:57:35 +08:00
|
|
|
protected $table = 'schedules';
|
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
public function run($start = 0)
|
|
|
|
{
|
|
|
|
$this->comment('--- FLIGHT SCHEDULE IMPORT ---');
|
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
$fields = [
|
|
|
|
'id',
|
|
|
|
'code',
|
|
|
|
'flightnum',
|
|
|
|
'depicao',
|
|
|
|
'arricao',
|
|
|
|
'route',
|
|
|
|
'distance',
|
|
|
|
'flightlevel',
|
|
|
|
'deptime',
|
|
|
|
'arrtime',
|
|
|
|
'flightttime',
|
|
|
|
'notes',
|
|
|
|
'enabled',
|
|
|
|
];
|
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
$count = 0;
|
2019-12-02 22:57:35 +08:00
|
|
|
foreach ($this->db->readRows($this->table, $start, $fields) as $row) {
|
2019-11-27 22:19:20 +08:00
|
|
|
$airline_id = $this->idMapper->getMapping('airlines', $row->code);
|
|
|
|
|
|
|
|
$flight_num = trim($row->flightnum);
|
|
|
|
|
|
|
|
$attrs = [
|
|
|
|
'dpt_airport_id' => $row->depicao,
|
|
|
|
'arr_airport_id' => $row->arricao,
|
|
|
|
'route' => $row->route ?: '',
|
|
|
|
'distance' => round($row->distance ?: 0, 2),
|
|
|
|
'level' => $row->flightlevel ?: 0,
|
|
|
|
'dpt_time' => $row->deptime ?: '',
|
|
|
|
'arr_time' => $row->arrtime ?: '',
|
|
|
|
'flight_time' => $this->convertDuration($row->flighttime) ?: '',
|
|
|
|
'notes' => $row->notes ?: '',
|
|
|
|
'active' => $row->enabled ?: true,
|
|
|
|
];
|
|
|
|
|
|
|
|
try {
|
|
|
|
$w = ['airline_id' => $airline_id, 'flight_number' => $flight_num];
|
2019-12-02 22:57:35 +08:00
|
|
|
// $flight = Flight::updateOrCreate($w, $attrs);
|
|
|
|
$flight = Flight::create(array_merge($w, $attrs));
|
2019-11-27 22:19:20 +08:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
//$this->error($e);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->idMapper->addMapping('flights', $row->id, $flight->id);
|
|
|
|
|
|
|
|
// TODO: deserialize route_details into ACARS table
|
|
|
|
|
|
|
|
if ($flight->wasRecentlyCreated) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->info('Imported '.$count.' flights');
|
|
|
|
}
|
|
|
|
}
|