Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a team membership migration bug #16

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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