From 497229039e8d8f1a57ed5441ae837c1ce66151aa Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 2 Jan 2018 21:16:35 -0600 Subject: [PATCH] Assign the first airline found to the newly created subfleet #114 --- app/Console/Services/Importer.php | 59 +++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/app/Console/Services/Importer.php b/app/Console/Services/Importer.php index ddb28a11..6dcef14e 100644 --- a/app/Console/Services/Importer.php +++ b/app/Console/Services/Importer.php @@ -48,9 +48,14 @@ class Importer /** * CONSTANTS */ - const BATCH_READ_ROWS = 500; - const SUBFLEET_NAME = 'Imported Aicraft'; + const BATCH_READ_ROWS = 500; + const SUBFLEET_NAME = 'Imported Aircraft'; + + /** + * Importer constructor. + * @param $db_creds + */ public function __construct($db_creds) { // Setup the logger @@ -218,6 +223,31 @@ class Importer } } + /** + * Return the subfleet + * @return mixed + */ + protected function getSubfleet() + { + $subfleet = Subfleet::where('name', self::SUBFLEET_NAME) + ->first(); + + if ($subfleet === null) + { + $this->info('Subfleet not found, inserting'); + $airline = Airline::first(); + $subfleet = new Subfleet([ + 'airline_id' => $airline->id, + 'name' => self::SUBFLEET_NAME, + 'type' => 'PHPVMS' + ]); + + $this->saveModel($subfleet); + } + + return $subfleet; + } + /** * * All the individual importers, done on a per-table basis @@ -288,16 +318,7 @@ class Importer { $this->comment('--- AIRCRAFT IMPORT ---'); - $subfleet = Subfleet::where('name', self::SUBFLEET_NAME) - ->first(); - - if($subfleet === null) { - $this->info('Subfleet not found, inserting'); - $this->saveModel(new Subfleet([ - 'name' => self::SUBFLEET_NAME, - 'type' => 'PHPVMS' - ])); - } + $subfleet = $this->getSubfleet(); $this->info('Subfleet ID is '.$subfleet->id); @@ -355,7 +376,7 @@ class Importer */ protected function importFlights() { - $this->comment('--- FLIGHT SCHEDULE IMPORT ---'); + /*$this->comment('--- FLIGHT SCHEDULE IMPORT ---'); $count = 0; foreach ($this->readRows('schedules') as $row) @@ -363,7 +384,7 @@ class Importer } - $this->info('Imported ' . $count . ' flights'); + $this->info('Imported ' . $count . ' flights');*/ } /** @@ -371,7 +392,7 @@ class Importer */ protected function importPireps() { - $this->comment('--- PIREP IMPORT ---'); + /*$this->comment('--- PIREP IMPORT ---'); $count = 0; foreach ($this->readRows('pireps') as $row) @@ -379,12 +400,12 @@ class Importer } - $this->info('Imported ' . $count . ' pireps'); + $this->info('Imported ' . $count . ' pireps');*/ } protected function importUsers() { - $this->comment('--- USER IMPORT ---'); + /*$this->comment('--- USER IMPORT ---'); $count = 0; foreach ($this->readRows('pilots') as $row) @@ -392,7 +413,7 @@ class Importer } - $this->info('Imported ' . $count . ' users'); + $this->info('Imported ' . $count . ' users');*/ } /** @@ -400,6 +421,6 @@ class Importer */ protected function recalculateRanks() { - $this->comment('--- RECALCULATING RANKS ---'); + /*$this->comment('--- RECALCULATING RANKS ---');*/ } }