Skip to content

Commit c7cc63d

Browse files
authored
Merge pull request #3389 from codeeu/dev
Dev
2 parents 5b264fe + 8307eef commit c7cc63d

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

app/Console/Commands/Excellence.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Event;
66
use App\Helpers\ExcellenceWinnersHelper;
7+
use App\Excellence as ExcellenceModel;
78
use Illuminate\Console\Command;
89
use Illuminate\Support\Carbon;
910
use Illuminate\Support\Facades\Log;
@@ -40,9 +41,10 @@ public function __construct()
4041
public function handle(): void
4142
{
4243

43-
$edition = $this->argument('edition');
44+
$edition = (int) $this->argument('edition');
4445

45-
$codeweek4all_codes = ExcellenceWinnersHelper::query(Carbon::now()->year($edition), true)->pluck('codeweek_for_all_participation_code');
46+
$editionDate = Carbon::create($edition, 1, 1, 0, 0, 0);
47+
$codeweek4all_codes = ExcellenceWinnersHelper::query($editionDate, true)->pluck('codeweek_for_all_participation_code');
4648

4749
//Select the winners from the Database
4850
$winners = [];
@@ -55,13 +57,33 @@ public function handle(): void
5557
}
5658
}
5759

58-
//Create an excellence record for each winner
60+
$created = 0;
61+
$existing = 0;
62+
$failed = 0;
63+
64+
// Create or update one excellence record per winner.
5965
foreach ($winners as $user_id) {
6066
try {
61-
create(\App\Excellence::class, ['edition' => $edition, 'user_id' => $user_id]);
67+
$record = ExcellenceModel::updateOrCreate(
68+
[
69+
'edition' => $edition,
70+
'user_id' => (int) $user_id,
71+
'type' => 'Excellence',
72+
],
73+
[]
74+
);
75+
76+
if ($record->wasRecentlyCreated) {
77+
$created++;
78+
} else {
79+
$existing++;
80+
}
6281
} catch (\Exception $ex) {
82+
$failed++;
6383
Log::info($ex->getMessage());
6484
}
6585
}
86+
87+
$this->info("Excellence sync completed. Created: {$created}, Existing: {$existing}, Failed: {$failed}");
6688
}
6789
}

app/Console/Commands/SuperOrganisers.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Console\Commands;
44

5+
use App\Excellence as ExcellenceModel;
56
use App\Queries\SuperOrganiserQuery;
67
use Illuminate\Console\Command;
78
use Illuminate\Support\Facades\Log;
@@ -41,13 +42,32 @@ public function handle(): void
4142

4243
$winners = SuperOrganiserQuery::winners($edition);
4344

45+
$created = 0;
46+
$existing = 0;
47+
$failed = 0;
48+
4449
foreach ($winners as $user_id) {
4550
try {
46-
create(\App\Excellence::class, ['edition' => $edition, 'user_id' => $user_id, 'type' => 'SuperOrganiser']);
51+
$record = ExcellenceModel::updateOrCreate(
52+
[
53+
'edition' => (int) $edition,
54+
'user_id' => (int) $user_id,
55+
'type' => 'SuperOrganiser',
56+
],
57+
[]
58+
);
59+
60+
if ($record->wasRecentlyCreated) {
61+
$created++;
62+
} else {
63+
$existing++;
64+
}
4765
} catch (\Exception $ex) {
66+
$failed++;
4867
Log::info($ex->getMessage());
4968
}
5069
}
5170

71+
$this->info("Super organiser sync completed. Created: {$created}, Existing: {$existing}, Failed: {$failed}");
5272
}
5373
}

0 commit comments

Comments
 (0)