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:
Nabeel S 2019-10-23 12:01:31 -04:00 committed by GitHub
parent 97baf98d04
commit 7a34756188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 113 additions and 24 deletions

View File

@ -4,8 +4,8 @@ Options -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Deny all these files/folders
RedirectMatch 403 ^/.git/.*?$
@ -35,11 +35,4 @@ RedirectMatch 403 ^/phpunit.xml
RedirectMatch 403 ^/webpack.mix.js
RedirectMatch 403 ^/yarn.lock
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ public/$1 [L]

View File

@ -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

View File

@ -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());
}
}

View 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));
}
}

View File

@ -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);

View File

@ -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
*

View File

@ -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);

View File

@ -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);
}
/**

View File

@ -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;
}

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "60c8d4678763253ee0fa8711dce01cfb",
"content-hash": "65a0339b4ba756f5d21382236bdcc42b",
"packages": [
{
"name": "akaunting/money",

View File

@ -10,7 +10,10 @@ require $path_to_phpvms_folder.'/bootstrap/autoload.php';
$app = require_once $path_to_phpvms_folder.'/bootstrap/app.php';
$app->setPublicPath(__DIR__.'/public');
$app->setPublicUrlPath(env('APP_PUBLIC_URL', '/public'));
$app->setPublicUrlPath(env('APP_PUBLIC_URL', '/'));
// Uncomment this line if you're having issues with the redirecting not working properly
//$app->setPublicUrlPath(env('APP_PUBLIC_URL', '/public'));
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

View File

@ -8,8 +8,9 @@ Options -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization}
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d

View File

@ -82,7 +82,7 @@
class="required">*</span>
{{ Form::select('arr_airport_id', $airports, null , [
'id' => 'arr_airport_id',
'class' => 'form-control select2'
'class' => 'form-control select2 select2'
]) }}
<p class="text-danger">{{ $errors->first('arr_airport_id') }}</p>
</div>

View File

@ -76,7 +76,7 @@
@endability
@ability('admin', 'maintenance')
<li><a href="{{ url('/admin/maintenance') }}"><i class="pe-7s-config"></i>maintenance</a></li>
<li><a href="{{ url('/admin/maintenance') }}"><i class="pe-7s-tools"></i>maintenance</a></li>
@endability
</ul>
</div>