Skip to content

Commit

Permalink
Merge pull request #16 from utopia-php/fix-create-team-membership
Browse files Browse the repository at this point in the history
Fix a team membership migration bug
  • Loading branch information
abnegate authored Sep 12, 2023
2 parents 45bd831 + 60db4c3 commit 3f6e6df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
"format": "./vendor/bin/pint"
},
"require": {
"php": ">=8.0",
"utopia-php/cli": "^0.15.0",
"appwrite/appwrite": "^8.0"
"php": "8.*",
"utopia-php/cli": "0.*",
"appwrite/appwrite": "10.0.*"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
"vlucas/phpdotenv": "^5.5",
"laravel/pint": "^1.10"
"phpunit/phpunit": "9.*",
"vlucas/phpdotenv": "5.*",
"laravel/pint": "1.*"
}
}
6 changes: 1 addition & 5 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,7 @@ public function importAuthResource(Resource $resource): Resource
$teamService->createMembership(
$resource->getTeam()->getId(),
$resource->getRoles(),
'',
$user->getEmail(),
$user->getId(),
$user->getPhone(),
$user->getName()
userId: $user->getId(),
);
break;
}
Expand Down
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 === null) {
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 3f6e6df

Please sign in to comment.