Skip to content

Commit

Permalink
fix: stop existing members on Gander roster being overwritten by Gand…
Browse files Browse the repository at this point in the history
…er sync
  • Loading branch information
AxonC committed Sep 5, 2024
1 parent e2f6223 commit 3d3d64d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions app/Console/Commands/Roster/UpdateRosterGanderControllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@ class UpdateRosterGanderControllers extends Command

public function handle()
{
$gander = Http::get('https://ganderoceanic.ca/api/roster')
$ganderValidatedAccountIds = Http::get('https://ganderoceanic.ca/api/roster')
->collect()
->where('active', true)
->pluck('cid');

DB::transaction(function () use ($gander) {
DB::transaction(function () use ($ganderValidatedAccountIds) {
/**
* Ensure each account on the Gander roster exists in the database
* in the event they do not, create them with default values.
* These accounts have not signed into our system before
* and because we don't have their name, we'll use 'Unknown'
* When they sign in, we will receive their name and update it
* from VATSIM Connect.
**/
$ganderValidatedAccountIds->each(function ($accountCid) {
Account::firstOrCreate(['id' => $accountCid], [
'name_first' => 'Unknown',
'name_last' => 'Unknown',
]);
});

Account::upsert(
$gander->map(fn ($value) => [
$ganderValidatedAccountIds->map(fn ($value) => [
'id' => $value,
'name_first' => 'Unknown',
'name_last' => 'Unknown',
Expand All @@ -34,13 +49,13 @@ public function handle()
);

Roster::upsert(
$gander->map(fn ($value) => ['account_id' => $value])->toArray(),
$ganderValidatedAccountIds->map(fn ($value) => ['account_id' => $value])->toArray(),
['account_id']
);

$positionGroup = PositionGroup::where('name', 'Shanwick Oceanic (EGGX)')->firstOrFail();

$gander->reject(function ($value) use ($positionGroup) {
$ganderValidatedAccountIds->reject(function ($value) use ($positionGroup) {
return Endorsement::where([
'account_id' => $value,
'endorsable_id' => $positionGroup->id,
Expand Down

0 comments on commit 3d3d64d

Please sign in to comment.