Deduplicate airlines
This commit is contained in:
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user