From 0bf1286c3a6215e61e082d894a9bc778f426e51e Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 29 Mar 2018 11:47:37 -0500 Subject: [PATCH] Fix error in flight importer --- app/Models/Flight.php | 1 - app/Services/ImportExport/FlightImporter.php | 10 ++++++++-- tests/data/flights.csv | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Models/Flight.php b/app/Models/Flight.php index 3f7325ff..c97a7a91 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -62,7 +62,6 @@ class Flight extends Model 'level' => 'integer', 'distance' => 'float', 'flight_time' => 'integer', - 'flight_type' => 'integer', 'has_bid' => 'boolean', 'active' => 'boolean', ]; diff --git a/app/Services/ImportExport/FlightImporter.php b/app/Services/ImportExport/FlightImporter.php index 49df02a2..f5c26562 100644 --- a/app/Services/ImportExport/FlightImporter.php +++ b/app/Services/ImportExport/FlightImporter.php @@ -92,8 +92,14 @@ class FlightImporter extends ImportExport } // Any specific transformations - // Flight type can be set to P - Passenger, C - Cargo, or H - Charter - $flight->setAttribute('flight_type', FlightType::getFromCode($row['flight_type'])); + + // Check for a valid value + $flight_type = $row['flight_type']; + if(!array_key_exists($flight_type, FlightType::labels())) { + $flight_type = 'J'; + } + + $flight->setAttribute('flight_type', $flight_type); $flight->setAttribute('active', get_truth_state($row['active'])); try { diff --git a/tests/data/flights.csv b/tests/data/flights.csv index 2fd3c109..5ccaea93 100644 --- a/tests/data/flights.csv +++ b/tests/data/flights.csv @@ -1,2 +1,2 @@ airline,flight_number,route_code,route_leg,dpt_airport,arr_airport,alt_airport,days,dpt_time,arr_time,level,distance,flight_time,flight_type,route,notes,active,subfleets,fares,fields -VMS,1972,,,KAUS,KJFK,KLGA,15,0810 CST,1235 EST,350,1477,207,P,ILEXY2 ZENZI LFK ELD J29 MEM Q29 JHW J70 STENT J70 MAGIO J70 LVZ LENDY6,"Just a flight",1,A32X,Y?price=300&cost=100&capacity=130;F?price=600&cost=400;B?,Departure Gate=4;Arrival Gate=C41 +VMS,1972,,,KAUS,KJFK,KLGA,15,0810 CST,1235 EST,350,1477,207,J,ILEXY2 ZENZI LFK ELD J29 MEM Q29 JHW J70 STENT J70 MAGIO J70 LVZ LENDY6,"Just a flight",1,A32X,Y?price=300&cost=100&capacity=130;F?price=600&cost=400;B?,Departure Gate=4;Arrival Gate=C41