Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/npm_and_yarn/postcss-and-tailwindc…
Browse files Browse the repository at this point in the history
…ss-8.4.31
  • Loading branch information
nabeelio authored Oct 3, 2023
2 parents e482acc + d7bd515 commit 08c8e75
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 172 deletions.
1 change: 1 addition & 0 deletions app/Models/Airport.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @property float lat
* @property float lon
* @property int elevation
* @property bool hub
*/
class Airport extends Model
{
Expand Down
2 changes: 1 addition & 1 deletion app/Services/ImportExport/AircraftImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function import(array $row, $index): bool
'registration' => $row['registration'],
], $row);
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
$this->errorLog('Error in row '.($index + 1).': '.$e->getMessage());
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions app/Services/ImportExport/AirportImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public function import(array $row, $index): bool
$row['id'] = $row['icao'];
$row['hub'] = get_truth_state($row['hub']);

if ($row['ground_handling_cost'] === null && $row['ground_handling_cost'] !== 0.0) {
if (!is_numeric($row['ground_handling_cost'])) {
$row['ground_handling_cost'] = (float) setting('airports.default_ground_handling_cost');
} else {
$row['ground_handling_cost'] = (float) $row['ground_handling_cost'];
}

if ($row['fuel_jeta_cost'] === null && $row['fuel_jeta_cost'] !== 0.0) {
if (!is_numeric($row['fuel_jeta_cost'])) {
$row['fuel_jeta_cost'] = (float) setting('airports.default_jet_a_fuel_cost');
} else {
$row['fuel_jeta_cost'] = (float) $row['fuel_jeta_cost'];
Expand All @@ -65,7 +65,7 @@ public function import(array $row, $index): bool
'id' => $row['icao'],
], $row);
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
$this->errorLog('Error in row '.($index + 1).': '.$e->getMessage());
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Services/ImportExport/ExpenseImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function import(array $row, $index): bool
'name' => $row['name'],
], $row);
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
$this->errorLog('Error in row '.($index + 1).': '.$e->getMessage());
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Services/ImportExport/FareImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function import(array $row, $index): bool
'code' => $row['code'],
], $row);
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
$this->errorLog('Error in row '.($index + 1).': '.$e->getMessage());
return false;
}

Expand Down
18 changes: 9 additions & 9 deletions app/Services/ImportExport/FlightImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function import(array $row, $index): bool
try {
$flight->save();
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
$this->errorLog('Error in row '.($index + 1).': '.$e->getMessage());
return false;
}

Expand All @@ -144,7 +144,7 @@ public function import(array $row, $index): bool
$this->processFares($flight, $row['fares']);
$this->processFields($flight, $row['fields']);

$this->log('Imported row '.$index);
$this->log('Imported row '.($index + 1));
return true;
}

Expand All @@ -162,31 +162,31 @@ protected function setDays($day_str)
}

$days = [];
if (strpos($day_str, '1') !== false) {
if (str_contains($day_str, '1')) {
$days[] = Days::MONDAY;
}

if (strpos($day_str, '2') !== false) {
if (str_contains($day_str, '2')) {
$days[] = Days::TUESDAY;
}

if (strpos($day_str, '3') !== false) {
if (str_contains($day_str, '3')) {
$days[] = Days::WEDNESDAY;
}

if (strpos($day_str, '4') !== false) {
if (str_contains($day_str, '4')) {
$days[] = Days::THURSDAY;
}

if (strpos($day_str, '5') !== false) {
if (str_contains($day_str, '5')) {
$days[] = Days::FRIDAY;
}

if (strpos($day_str, '6') !== false) {
if (str_contains($day_str, '6')) {
$days[] = Days::SATURDAY;
}

if (strpos($day_str, '7') !== false) {
if (str_contains($day_str, '7')) {
$days[] = Days::SUNDAY;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Services/ImportExport/SubfleetImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function import(array $row, $index): bool
'type' => $row['type'],
], $row);
} catch (\Exception $e) {
$this->errorLog('Error in row '.$index.': '.$e->getMessage());
$this->errorLog('Error in row '.($index + 1).': '.$e->getMessage());
return false;
}

Expand Down
30 changes: 6 additions & 24 deletions app/Services/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ protected function throwError($error, \Exception $e = null): void
public function openCsv($csv_file)
{
try {
$reader = Reader::createFromPath($csv_file);
$reader = Reader::createFromPath($csv_file, 'r');
$reader->setDelimiter(',');
$reader->setHeaderOffset(0);
$reader->setEnclosure('"');
$reader->setEscape('\\');
return $reader;
} catch (Exception $e) {
$this->throwError('Error opening CSV: '.$e->getMessage(), $e);
Expand All @@ -94,33 +96,13 @@ protected function runImport($file_path, ImportExport $importer): array
$first_header = $cols[0];

$first = true;
$records = $reader->getRecords($cols);
$header_rows = $reader->getHeader();
$records = $reader->getRecords($header_rows);
foreach ($records as $offset => $row) {
// check if the first row being read is the header
if ($first) {
$first = false;

if ($row[$first_header] !== $first_header) {
$this->throwError('CSV file doesn\'t seem to match import type');
}

continue;
}

// Do a sanity check on the number of columns first
if (!$importer->checkColumns($row)) {
$importer->errorLog('Number of columns in row doesn\'t match');
continue;
}

// turn it into a collection and run some filtering
$row = collect($row)->map(function ($val, $index) {
$val = trim($val);
if ($val === '') {
return;
}

return $val;
return str_ireplace(['\\n', '\\r'], '', $val);
})->toArray();

// Try to validate
Expand Down
2 changes: 1 addition & 1 deletion composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"symfony/http-client": "^6.2",
"symfony/yaml": "~6.2",
"psr/container": "1.1.1",
"composer/composer": "~2.3.0",
"composer/composer": "~2.6.4",
"composer/installers": "~1.12.0",
"laravel/framework": "~v10.0",
"arrilot/laravel-widgets": "~3.13.0",
Expand Down
Loading

0 comments on commit 08c8e75

Please sign in to comment.