diff --git a/app/Console/Commands/UpdateAtcHours.php b/app/Console/Commands/UpdateAtcHours.php index 72b2a9a07..f2aa42350 100644 --- a/app/Console/Commands/UpdateAtcHours.php +++ b/app/Console/Commands/UpdateAtcHours.php @@ -75,7 +75,7 @@ private function updateMemberATCHours(Collection $members) $this->info("Fetching seen ATC positions..."); $divisionCallsignPrefixes = collect(DB::select( DB::raw('SELECT DISTINCT LEFT(callsign, 4) as prefix FROM positions;') - )); + ))->pluck('prefix'); $this->info("Updating member ATC hours..."); @@ -89,8 +89,6 @@ private function updateMemberATCHours(Collection $members) } $response = $this->makeHttpGetRequest($client, $url); - $this->info("Checking " . $member->id); - if ($response == null) { Log::error('updateMemberATCHours: Failed to fetch GuzzleHttp Response, url: ' . $url); continue; @@ -122,16 +120,8 @@ private function updateHoursForMember(User $member, Collection $sessions, Collec { $this->info("Updating ATC hours for member: " . $member->id); - $isDivisionCallsign = function ($session) use ($divisionCallsignPrefixes) { - try { - isDivisionCallsign($session->callsign, $divisionCallsignPrefixes); - } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { - return false; - } - return true; - }; $hoursActiveInDivision = $sessions - ->filter($isDivisionCallsign) + ->filter(fn($session) => isDivisionCallsign($session->callsign, $divisionCallsignPrefixes)) ->map(function ($session) { return floatval($session->minutes_on_callsign); }) diff --git a/app/Helpers/Vatsim.php b/app/Helpers/Vatsim.php index f09bff9e9..449d56da2 100644 --- a/app/Helpers/Vatsim.php +++ b/app/Helpers/Vatsim.php @@ -32,8 +32,7 @@ function isDivisionCallsign(string $callsign, Collection $divisionCallsignPrefix } // PREFIX - - if ($divisionCallsignPrefixes->value(substr($callsign, 4))) { + if ($divisionCallsignPrefixes->contains(substr($callsign, 0, 4))) { return true; }