Skip to content
Merged

Dev #3389

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions app/Console/Commands/Excellence.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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}");
}
}
22 changes: 21 additions & 1 deletion app/Console/Commands/SuperOrganisers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}");
}
}
Loading