Issue fixes (#413)
* Auto lookup missing airports closes #404 * Ensure flight ICAOs are capitalized closes #404 * Update htaccess in root closes #412 * Update htaccess in root closes #412 * StyleCI fix
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Contracts\AirportLookup as AirportLookupProvider;
|
||||
use App\Contracts\Metar as MetarProvider;
|
||||
use App\Contracts\Service;
|
||||
use App\Exceptions\AirportNotFound;
|
||||
use App\Models\Airport;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Support\Metar;
|
||||
use App\Support\Units\Distance;
|
||||
@@ -73,6 +74,8 @@ class AirportService extends Service
|
||||
return [];
|
||||
}
|
||||
|
||||
$airport = (array) $airport;
|
||||
|
||||
Cache::add(
|
||||
$key,
|
||||
$airport,
|
||||
@@ -82,6 +85,47 @@ class AirportService extends Service
|
||||
return $airport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup an airport and save it if it hasn't been found
|
||||
*
|
||||
* @param string $icao
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
*/
|
||||
public function lookupAirportIfNotFound($icao)
|
||||
{
|
||||
$icao = strtoupper($icao);
|
||||
$airport = $this->airportRepo->findWithoutFail($icao);
|
||||
if ($airport !== null) {
|
||||
return $airport;
|
||||
}
|
||||
|
||||
// Don't lookup the airport, so just add in something generic
|
||||
if (!setting('general.auto_airport_lookup')) {
|
||||
$airport = new Airport([
|
||||
'id' => $icao,
|
||||
'icao' => $icao,
|
||||
'name' => $icao,
|
||||
'lat' => 0,
|
||||
'lon' => 0,
|
||||
]);
|
||||
|
||||
$airport->save();
|
||||
|
||||
return $airport;
|
||||
}
|
||||
|
||||
$lookup = $this->lookupAirport($icao);
|
||||
if (empty($lookup)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$airport = new Airport($lookup);
|
||||
$airport->save();
|
||||
|
||||
return $airport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the distance from one airport to another
|
||||
*
|
||||
|
||||
@@ -53,11 +53,17 @@ class FlightService extends Service
|
||||
*/
|
||||
public function createFlight($fields)
|
||||
{
|
||||
$fields['dpt_airport_id'] = strtoupper($fields['dpt_airport_id']);
|
||||
$fields['arr_airport_id'] = strtoupper($fields['arr_airport_id']);
|
||||
|
||||
$flightTmp = new Flight($fields);
|
||||
if ($this->isFlightDuplicate($flightTmp)) {
|
||||
throw new DuplicateFlight($flightTmp);
|
||||
}
|
||||
|
||||
$this->airportSvc->lookupAirportIfNotFound($fields['dpt_airport_id']);
|
||||
$this->airportSvc->lookupAirportIfNotFound($fields['arr_airport_id']);
|
||||
|
||||
$fields = $this->transformFlightFields($fields);
|
||||
$flight = $this->flightRepo->create($fields);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Enums\FlightType;
|
||||
use App\Models\Fare;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Subfleet;
|
||||
use App\Services\AirportService;
|
||||
use App\Services\FareService;
|
||||
use App\Services\FlightService;
|
||||
use Log;
|
||||
@@ -47,8 +48,8 @@ class FlightImporter extends ImportExport
|
||||
'fields' => 'nullable',
|
||||
];
|
||||
|
||||
private $airportSvc;
|
||||
private $fareSvc;
|
||||
|
||||
private $flightSvc;
|
||||
|
||||
/**
|
||||
@@ -56,6 +57,7 @@ class FlightImporter extends ImportExport
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->airportSvc = app(AirportService::class);
|
||||
$this->fareSvc = app(FareService::class);
|
||||
$this->flightSvc = app(FlightService::class);
|
||||
}
|
||||
@@ -94,6 +96,9 @@ class FlightImporter extends ImportExport
|
||||
'route_leg' => $row['route_leg'],
|
||||
], $row);
|
||||
|
||||
$row['dpt_airport'] = strtoupper($row['dpt_airport']);
|
||||
$row['arr_airport'] = strtoupper($row['arr_airport']);
|
||||
|
||||
// Airport atttributes
|
||||
$flight->setAttribute('days', $this->setDays($row['days']));
|
||||
$flight->setAttribute('dpt_airport_id', $row['dpt_airport']);
|
||||
@@ -189,9 +194,7 @@ class FlightImporter extends ImportExport
|
||||
*/
|
||||
protected function processAirport($airport)
|
||||
{
|
||||
return Airport::firstOrCreate([
|
||||
'id' => $airport,
|
||||
], ['icao' => $airport, 'name' => $airport]);
|
||||
return $this->airportSvc->lookupAirportIfNotFound($airport);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Services\Installer;
|
||||
use App\Contracts\Service;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
class MigrationService extends Service
|
||||
@@ -37,7 +36,7 @@ class MigrationService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
Log::info('Update - migration paths', $paths);
|
||||
// Log::info('Update - migration paths', $paths);
|
||||
|
||||
return $paths;
|
||||
}
|
||||
@@ -53,7 +52,7 @@ class MigrationService extends Service
|
||||
$files = $migrator->getMigrationFiles(array_values($migration_dirs));
|
||||
$availMigrations = array_diff(array_keys($files), $migrator->getRepository()->getRan());
|
||||
|
||||
Log::info('Migrations available:', $availMigrations);
|
||||
// Log::info('Migrations available:', $availMigrations);
|
||||
|
||||
return $availMigrations;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user