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\Aircraft;
|
|
|
|
use App\Models\Airline;
|
|
|
|
use App\Models\Subfleet;
|
2019-12-13 04:07:35 +08:00
|
|
|
use Modules\Importer\Services\BaseImporter;
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
class AircraftImporter extends BaseImporter
|
|
|
|
{
|
2020-02-24 08:48:28 +08:00
|
|
|
protected $table = 'aircraft';
|
2019-12-02 22:57:35 +08:00
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
/**
|
|
|
|
* CONSTANTS
|
|
|
|
*/
|
|
|
|
public const SUBFLEET_NAME = 'Imported Aircraft';
|
|
|
|
|
|
|
|
public function run($start = 0)
|
|
|
|
{
|
|
|
|
$this->comment('--- AIRCRAFT IMPORT ---');
|
|
|
|
|
|
|
|
$subfleet = $this->getSubfleet();
|
|
|
|
|
|
|
|
$this->info('Subfleet ID is '.$subfleet->id);
|
|
|
|
|
|
|
|
$count = 0;
|
2020-02-24 08:48:28 +08:00
|
|
|
$rows = $this->db->readRows($this->table, $this->idField, $start);
|
|
|
|
foreach ($rows as $row) {
|
2019-11-27 22:19:20 +08:00
|
|
|
$where = [
|
|
|
|
'name' => $row->fullname,
|
|
|
|
'registration' => $row->registration,
|
|
|
|
];
|
|
|
|
|
|
|
|
$aircraft = Aircraft::firstOrCreate($where, [
|
|
|
|
'icao' => $row->icao,
|
|
|
|
'subfleet_id' => $subfleet->id,
|
|
|
|
'active' => $row->enabled,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->idMapper->addMapping('aircraft', $row->id, $aircraft->id);
|
|
|
|
|
|
|
|
if ($aircraft->wasRecentlyCreated) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->info('Imported '.$count.' aircraft');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the subfleet
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
protected function getSubfleet()
|
|
|
|
{
|
|
|
|
$airline = Airline::first();
|
|
|
|
$subfleet = Subfleet::firstOrCreate([
|
|
|
|
'airline_id' => $airline->id,
|
|
|
|
'name' => self::SUBFLEET_NAME,
|
|
|
|
], ['type' => 'PHPVMS']);
|
|
|
|
|
|
|
|
return $subfleet;
|
|
|
|
}
|
|
|
|
}
|