Skip to content

Commit

Permalink
WJPC: Sync only non-connected players
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMikes committed Sep 19, 2024
1 parent aacb6f4 commit 07a08de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ConsoleCommands/SyncWjpcRemotePlayersConsoleCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($participantId === null) {
$connectedParticipants = $this->getWjpcParticipants->getConnectedParticipants();
$notSyncedParticipants = $this->getWjpcParticipants->getConnectedParticipantsWithoutRemoteId();

foreach ($connectedParticipants as $participant) {
foreach ($notSyncedParticipants as $participantId) {
$this->messageBus->dispatch(
new UpdateWjpcPlayerId($participant->participantId),
new UpdateWjpcPlayerId($participantId),
);
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/Query/GetWjpcParticipants.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ public function mappingToPlayers(): array
return $results;
}

/**
* @return array<string>
*/
public function getConnectedParticipantsWithoutRemoteId(): array
{
$query = <<<SQL
SELECT
wjpc_participant.id AS participant_id
FROM
wjpc_participant
INNER JOIN
player ON player.id = wjpc_participant.player_id
WHERE
wjpc_participant.player_id IS NOT NULL AND wjpc_participant.remote_id IS NULL
SQL;

/** @var array<string> $participants */
$participants = $this->database
->executeQuery($query)
->fetchFirstColumn();

return $participants;
}

/**
* @return array<ConnectedWjpcParticipant>
*/
Expand Down

0 comments on commit 07a08de

Please sign in to comment.