Updated scheduled tasks

This commit is contained in:
2026-07-03 15:42:41 +10:00
parent f422a6e38e
commit 16184d9c83
4 changed files with 31 additions and 8 deletions
@@ -78,6 +78,28 @@ class GetAircraftInfoForArrivedFlights extends Command
$this->applyAndNotify($flight, $data, $airlineCode, $flightNumber);
}
protected function splitFlightNumber(UserFlight $flight): array
{
$raw = strtoupper($flight->flight_number);
$airline = $flight->airline;
// Preferred: anchor on the airline's known codes rather than guessing.
foreach (array_filter([$airline?->iata_code, $airline?->icao_code]) as $code) {
$code = strtoupper($code);
if (str_starts_with($raw, $code) && preg_match('/^\d+$/', substr($raw, strlen($code)))) {
return [$code, substr($raw, strlen($code))];
}
}
// Fallback: regex guess.
// Covers: letter+digit (J2), digit+letter (9K, 4U), and 2-3 letter codes (AA, DAL).
if (preg_match('/^([A-Z]\d|\d[A-Z]|[A-Z]{2,3})(\d+)$/', $raw, $matches)) {
return [$matches[1], $matches[2]];
}
return [null, null];
}
protected function notifyLookupFailed(UserFlight $flight, string $airlineCode, string $flightNumber): void
{
Notification::create([