e862537a20
* Split the importer module out from the installer module * Cleanup of unused imports * Move updater into separate module #453 * Remove unused imports/formatting * Disable the install and importer modules at the end of the setup * Unused imports; update IJ style * test explicit stage for php+mysql * add more to matrix * Add different MariaDB versions * undo
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Importer\Services\Importers;
|
|
|
|
use App\Models\Airline;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Modules\Importer\Services\BaseImporter;
|
|
|
|
class AirlineImporter extends BaseImporter
|
|
{
|
|
public $table = 'airlines';
|
|
|
|
/**
|
|
* @param int $start
|
|
*/
|
|
public function run($start = 0)
|
|
{
|
|
$this->comment('--- AIRLINE IMPORT ---');
|
|
|
|
$count = 0;
|
|
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));
|
|
|
|
$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');
|
|
}
|
|
}
|