Deduplicate airlines

This commit is contained in:
2026-04-17 00:02:47 +10:00
parent a535521834
commit 5066052013
5 changed files with 321 additions and 9 deletions
+31 -3
View File
@@ -8,16 +8,32 @@ use Illuminate\Support\Facades\Storage;
class LogoController extends Controller
{
public function getAirlineLogo(?Airline $airline){
const array CONDOR_LOGOS = ['BEACH', 'ISLAND', 'PASSION', 'SEA', 'SUNSHINE'];
public function getAirlineLogo(?Airline $airline)
{
$logoFile = $airline?->logo ?? 'blank.png';
$cacheLimit = 60 * 60 * 24;
if ($airline?->internal_name == 'condor') {
$logoKey = array_rand(self::CONDOR_LOGOS);
$logoFile = 'DE_' . self::CONDOR_LOGOS[$logoKey] . '.png';
$cacheLimit = 1;
}
$path = 'images/logos/tail/' . $logoFile;
if (!Storage::disk('local')->exists($path)) {
$path = 'images/logos/tail/blank.png';
}
return response()->file(Storage::disk('local')->path($path), [
'Content-Type' => 'image/png',
$fullPath = Storage::disk('local')->path($path);
$lastModified = filemtime($fullPath);
return response()->file($fullPath, [
'Content-Type' => 'image/png',
'Cache-Control' => 'public, max-age='.$cacheLimit, // 24 hours
'Last-Modified' => gmdate('D, d M Y H:i:s', $lastModified) . ' GMT',
'ETag' => md5($path . $lastModified),
]);
}
@@ -67,6 +83,18 @@ class LogoController extends Controller
return;
}
$existing = Airline::whereIn('internal_name', $correctInternalNames)
->pluck('internal_name')
->toArray();
$missing = array_diff($correctInternalNames, $existing);
if (!empty($missing)) {
throw new \InvalidArgumentException(
'The following internal names do not exist in the database: ' . implode(', ', $missing)
);
}
$nulled = Airline::where('logo', $logo)
->whereNotIn('internal_name', $correctInternalNames)
->get(['name', 'internal_name']);
+10 -3
View File
@@ -14,9 +14,16 @@ class SearchController extends Controller
return Airline::orderByDesc('active')
->where(function ($query) use ($q) {
$query->where('name', 'ilike', "%{$q}%")
->orWhere('IATA_code', 'ilike', "%{$q}%")
->orWhere('ICAO_code', 'ilike', "%{$q}%");
$len = strlen($q);
if ($len === 2) {
$query->where('IATA_code', 'ilike', $q);
} elseif ($len === 3) {
$query->where('ICAO_code', 'ilike', $q);
} else {
$query->where('name', 'ilike', "%{$q}%")
->orWhere('IATA_code', 'ilike', "%{$q}%")
->orWhere('ICAO_code', 'ilike', "%{$q}%");
}
})
->limit(50)
->get(['id', 'name', 'IATA_code', 'ICAO_code', 'logo'])