Skip to content

Commit

Permalink
Fix same user being set in every team membership resource
Browse files Browse the repository at this point in the history
  • Loading branch information
stnguyen90 committed Sep 8, 2023
1 parent 110b9bf commit 77049ab
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,12 @@ private function exportMemberships(int $batchSize)

// Export Memberships
$cacheTeams = $this->cache->get(Team::getName());
$cacheUsers = $this->cache->get(User::getName());
/** @var array<string, User> - array where key is user ID */
$cacheUsers = [];
foreach ($this->cache->get(User::getName()) as $cacheUser) {
/** @var User $cacheUser */
$cacheUsers[$cacheUser->getId()] = $cacheUser;
}

foreach ($cacheTeams as $team) {
/** @var Team $team */
Expand All @@ -384,20 +389,12 @@ private function exportMemberships(int $batchSize)
break;
}

$user = null;
foreach ($cacheUsers as $cacheUser) {
/** @var User $cacheUser */
if ($cacheUser->getId() === $response['memberships'][0]['userId']) {
$user = $cacheUser;
break;
foreach ($response['memberships'] as $membership) {
$user = $cacheUsers[$membership['userId']] ?? null;
if (! $user) {
throw new \Exception('User not found');
}
}

if (! $user) {
throw new \Exception('User not found');
}

foreach ($response['memberships'] as $membership) {
$memberships[] = new Membership(
$team,
$user,
Expand Down

0 comments on commit 77049ab

Please sign in to comment.