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
14 changed files with 113 additions and 24 deletions

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
*