From 1bddc3e8260827e5a5cdf930986b8a1dad636d8b Mon Sep 17 00:00:00 2001 From: bernardhanna Date: Tue, 24 Feb 2026 10:54:19 +0000 Subject: [PATCH] certs stats --- app/Console/Commands/Excellence.php | 30 ++++++++++++++++++++---- app/Console/Commands/SuperOrganisers.php | 22 ++++++++++++++++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/Excellence.php b/app/Console/Commands/Excellence.php index d564fc037..71083ae7b 100644 --- a/app/Console/Commands/Excellence.php +++ b/app/Console/Commands/Excellence.php @@ -4,6 +4,7 @@ use App\Event; use App\Helpers\ExcellenceWinnersHelper; +use App\Excellence as ExcellenceModel; use Illuminate\Console\Command; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Log; @@ -40,9 +41,10 @@ public function __construct() public function handle(): void { - $edition = $this->argument('edition'); + $edition = (int) $this->argument('edition'); - $codeweek4all_codes = ExcellenceWinnersHelper::query(Carbon::now()->year($edition), true)->pluck('codeweek_for_all_participation_code'); + $editionDate = Carbon::create($edition, 1, 1, 0, 0, 0); + $codeweek4all_codes = ExcellenceWinnersHelper::query($editionDate, true)->pluck('codeweek_for_all_participation_code'); //Select the winners from the Database $winners = []; @@ -55,13 +57,33 @@ public function handle(): void } } - //Create an excellence record for each winner + $created = 0; + $existing = 0; + $failed = 0; + + // Create or update one excellence record per winner. foreach ($winners as $user_id) { try { - create(\App\Excellence::class, ['edition' => $edition, 'user_id' => $user_id]); + $record = ExcellenceModel::updateOrCreate( + [ + 'edition' => $edition, + 'user_id' => (int) $user_id, + 'type' => 'Excellence', + ], + [] + ); + + if ($record->wasRecentlyCreated) { + $created++; + } else { + $existing++; + } } catch (\Exception $ex) { + $failed++; Log::info($ex->getMessage()); } } + + $this->info("Excellence sync completed. Created: {$created}, Existing: {$existing}, Failed: {$failed}"); } } diff --git a/app/Console/Commands/SuperOrganisers.php b/app/Console/Commands/SuperOrganisers.php index f5de72d3c..5026d0cf9 100644 --- a/app/Console/Commands/SuperOrganisers.php +++ b/app/Console/Commands/SuperOrganisers.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Excellence as ExcellenceModel; use App\Queries\SuperOrganiserQuery; use Illuminate\Console\Command; use Illuminate\Support\Facades\Log; @@ -41,13 +42,32 @@ public function handle(): void $winners = SuperOrganiserQuery::winners($edition); + $created = 0; + $existing = 0; + $failed = 0; + foreach ($winners as $user_id) { try { - create(\App\Excellence::class, ['edition' => $edition, 'user_id' => $user_id, 'type' => 'SuperOrganiser']); + $record = ExcellenceModel::updateOrCreate( + [ + 'edition' => (int) $edition, + 'user_id' => (int) $user_id, + 'type' => 'SuperOrganiser', + ], + [] + ); + + if ($record->wasRecentlyCreated) { + $created++; + } else { + $existing++; + } } catch (\Exception $ex) { + $failed++; Log::info($ex->getMessage()); } } + $this->info("Super organiser sync completed. Created: {$created}, Existing: {$existing}, Failed: {$failed}"); } }