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:
@@ -12,6 +12,13 @@
|
||||
options: ''
|
||||
type: text
|
||||
description: 'Email where system notices, etc are sent'
|
||||
- key: general.auto_airport_lookup
|
||||
name: 'Automatic airport lookup'
|
||||
group: general
|
||||
value: true
|
||||
options:
|
||||
type: boolean
|
||||
description: If an airport isn't added, try to look it up when adding schedules
|
||||
- key: general.check_prerelease_version
|
||||
name: 'Pre-release versions in version check'
|
||||
group: general
|
||||
|
||||
@@ -175,6 +175,7 @@ class FlightController extends Controller
|
||||
|
||||
return redirect(route('admin.flights.edit', $flight->id));
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
Flash::error($e->getMessage());
|
||||
return redirect()->back()->withInput($request->all());
|
||||
}
|
||||
@@ -258,8 +259,8 @@ class FlightController extends Controller
|
||||
|
||||
return redirect(route('admin.flights.index'));
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
Flash::error($e->getMessage());
|
||||
|
||||
return redirect()->back()->withInput($request->all());
|
||||
}
|
||||
}
|
||||
|
||||
29
app/Models/Observers/FlightObserver.php
Normal file
29
app/Models/Observers/FlightObserver.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Observers;
|
||||
|
||||
use App\Models\Flight;
|
||||
|
||||
/**
|
||||
* Make sure that the fields are properly capitalized
|
||||
*/
|
||||
class FlightObserver
|
||||
{
|
||||
/**
|
||||
* @param Flight $flight
|
||||
*/
|
||||
public function creating(Flight $flight): void
|
||||
{
|
||||
$flight->dpt_airport_id = strtoupper(trim($flight->dpt_airport_id));
|
||||
$flight->arr_airport_id = strtoupper(trim($flight->arr_airport_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Flight $flight
|
||||
*/
|
||||
public function updating(Flight $flight): void
|
||||
{
|
||||
$flight->dpt_airport_id = strtoupper(trim($flight->dpt_airport_id));
|
||||
$flight->arr_airport_id = strtoupper(trim($flight->arr_airport_id));
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,14 @@ namespace App\Providers;
|
||||
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Airport;
|
||||
use App\Models\Flight;
|
||||
use App\Models\FlightField;
|
||||
use App\Models\FlightFieldValue;
|
||||
use App\Models\Journal;
|
||||
use App\Models\JournalTransaction;
|
||||
use App\Models\Observers\AircraftObserver;
|
||||
use App\Models\Observers\AirportObserver;
|
||||
use App\Models\Observers\FlightObserver;
|
||||
use App\Models\Observers\JournalObserver;
|
||||
use App\Models\Observers\JournalTransactionObserver;
|
||||
use App\Models\Observers\SettingObserver;
|
||||
@@ -47,6 +49,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
Journal::observe(JournalObserver::class);
|
||||
JournalTransaction::observe(JournalTransactionObserver::class);
|
||||
|
||||
Flight::observe(FlightObserver::class);
|
||||
FlightField::observe(Sluggable::class);
|
||||
FlightFieldValue::observe(Sluggable::class);
|
||||
|
||||
|
||||
@@ -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