Properly create/update rows importing #486 (#503)

This commit is contained in:
Nabeel S
2020-01-16 10:40:42 -05:00
committed by GitHub
parent fa01c61677
commit c2f7c5e421
8 changed files with 40 additions and 33 deletions

View File

@@ -69,7 +69,7 @@ class AircraftImporter extends ImportExport
// Set a default status
$row['status'] = trim($row['status']);
if ($row['status'] === null || $row['status'] === '') {
if (empty($row['status'])) {
$row['status'] = AircraftStatus::ACTIVE;
}
@@ -77,12 +77,10 @@ class AircraftImporter extends ImportExport
$row['state'] = AircraftState::PARKED;
// Try to add or update
$aircraft = Aircraft::firstOrNew([
'registration' => $row['registration'],
], $row);
try {
$aircraft->save();
Aircraft::updateOrCreate([
'registration' => $row['registration'],
], $row);
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
return false;