diff --git a/bin/MigrationCLI.php b/bin/MigrationCLI.php index 891b92b..def3634 100644 --- a/bin/MigrationCLI.php +++ b/bin/MigrationCLI.php @@ -70,8 +70,6 @@ function (array $resources) { $this->drawFrame(); } ); - - var_dump('Complete'); } } diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index 9ef746b..7db57d1 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -522,19 +522,15 @@ public function importAuthResource(Resource $resource): Resource switch ($resource->getName()) { case Resource::TYPE_USER: /** @var User $resource */ - if (in_array(User::TYPE_PASSWORD, $resource->getTypes())) { + if (! empty($resource->getPasswordHash())) { $this->importPasswordUser($resource); - } elseif (in_array(User::TYPE_OAUTH, $resource->getTypes())) { - $resource->setStatus(Resource::STATUS_WARNING, 'OAuth users cannot be imported.'); - - return $resource; } else { $userService->create( $resource->getId(), $resource->getEmail(), - in_array(User::TYPE_PHONE, $resource->getTypes()) ? $resource->getPhone() : null, + $resource->getPhone(), null, - $resource->getName() + $resource->getUsername() ); } diff --git a/src/Migration/Resources/Auth/User.php b/src/Migration/Resources/Auth/User.php index af87b64..df8430c 100644 --- a/src/Migration/Resources/Auth/User.php +++ b/src/Migration/Resources/Auth/User.php @@ -7,25 +7,13 @@ class User extends Resource { - public const TYPE_PASSWORD = 'password'; + protected ?string $email = null; - public const TYPE_PHONE = 'phone'; - - public const TYPE_ANONYMOUS = 'anonymous'; - - public const TYPE_MAGIC = 'magic'; - - public const TYPE_OAUTH = 'oauth'; - - protected string $email = ''; - - protected string $username = ''; + protected ?string $username = null; protected ?Hash $passwordHash = null; - protected string $phone = ''; - - protected array $types = [self::TYPE_ANONYMOUS]; + protected ?string $phone = null; protected array $labels = []; @@ -41,11 +29,10 @@ class User extends Resource public function __construct( string $id, - string $email = '', - string $username = '', + ?string $email = null, + ?string $username = null, ?Hash $passwordHash = null, - string $phone = '', - array $types = [self::TYPE_ANONYMOUS], + ?string $phone = null, array $labels = [], string $oauthProvider = '', bool $emailVerified = false, @@ -58,7 +45,6 @@ public function __construct( $this->username = $username; $this->passwordHash = $passwordHash; $this->phone = $phone; - $this->types = $types; $this->labels = $labels; $this->oauthProvider = $oauthProvider; $this->emailVerified = $emailVerified; @@ -78,7 +64,7 @@ public static function getName(): string /** * Get Email */ - public function getEmail(): string + public function getEmail(): ?string { return $this->email; } @@ -96,7 +82,7 @@ public function setEmail(string $email): self /** * Get Username */ - public function getUsername(): string + public function getUsername(): ?string { return $this->username; } @@ -132,7 +118,7 @@ public function setPasswordHash(Hash $passwordHash): self /** * Get Phone */ - public function getPhone(): string + public function getPhone(): ?string { return $this->phone; } @@ -147,24 +133,6 @@ public function setPhone(string $phone): self return $this; } - /** - * Get Type - */ - public function getTypes(): array - { - return $this->types; - } - - /** - * Set Types - */ - public function setTypes(string $types): self - { - $this->types = $types; - - return $this; - } - /** * Get Labels */ @@ -289,7 +257,6 @@ public function asArray(): array 'username' => $this->username, 'passwordHash' => $this->passwordHash ? $this->passwordHash->asArray() : null, 'phone' => $this->phone, - 'types' => $this->types, 'oauthProvider' => $this->oauthProvider, 'emailVerified' => $this->emailVerified, 'phoneVerified' => $this->phoneVerified, diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index b44f53b..75a7bbb 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -331,11 +331,10 @@ private function exportUsers(int $batchSize) foreach ($response['users'] as $user) { $users[] = new User( $user['$id'], - $user['email'], - $user['name'], + empty($user['email']) ? null : $user['email'], + empty($user['name']) ? null : $user['name'], $user['password'] ? new Hash($user['password'], algorithm: $user['hash']) : null, - $user['phone'], - $this->calculateTypes($user), + empty($user['phone']) ? null : $user['phone'], $user['labels'] ?? [], '', $user['emailVerification'] ?? false, @@ -943,25 +942,6 @@ private function exportIndexes(int $batchSize) } } - private function calculateTypes(array $user): array - { - if (empty($user['email']) && empty($user['phone'])) { - return [User::TYPE_ANONYMOUS]; - } - - $types = []; - - if (! empty($user['email']) && ! empty($user['password'])) { - $types[] = User::TYPE_PASSWORD; - } - - if (! empty($user['phone'])) { - $types[] = User::TYPE_PHONE; - } - - return $types; - } - protected function exportGroupStorage(int $batchSize, array $resources) { try { diff --git a/src/Migration/Sources/Firebase.php b/src/Migration/Sources/Firebase.php index 3effe6e..18536ff 100644 --- a/src/Migration/Sources/Firebase.php +++ b/src/Migration/Sources/Firebase.php @@ -216,7 +216,6 @@ private function exportUsers(int $batchSize) $user['displayName'] ?? $user['email'] ?? '', new Hash($user['passwordHash'] ?? '', $user['salt'] ?? '', Hash::ALGORITHM_SCRYPT_MODIFIED, $hashConfig['saltSeparator'] ?? '', $hashConfig['signerKey'] ?? ''), $user['phoneNumber'] ?? '', - $this->calculateUserType($user['providerUserInfo'] ?? []), [], '', $user['emailVerified'] ?? false, @@ -233,31 +232,6 @@ private function exportUsers(int $batchSize) } } - private function calculateUserType(array $providerData): array - { - if (count($providerData) === 0) { - return [User::TYPE_ANONYMOUS]; - } - - $types = []; - - foreach ($providerData as $provider) { - switch ($provider['providerId']) { - case 'password': - $types[] = User::TYPE_PASSWORD; - break; - case 'phone': - $types[] = User::TYPE_PHONE; - break; - default: - $types[] = User::TYPE_OAUTH; - break; - } - } - - return $types; - } - protected function exportGroupDatabases(int $batchSize, array $resources) { // Check if Firestore is enabled diff --git a/src/Migration/Sources/NHost.php b/src/Migration/Sources/NHost.php index 2671354..0b87f55 100644 --- a/src/Migration/Sources/NHost.php +++ b/src/Migration/Sources/NHost.php @@ -251,7 +251,6 @@ private function exportUsers(int $batchSize) $user['display_name'] ?? '', new Hash($user['password_hash'], '', Hash::ALGORITHM_BCRYPT), $user['phone_number'] ?? '', - $this->calculateUserTypes($user), [], '', $user['email_verified'] ?? false, @@ -590,25 +589,6 @@ private function convertIndex(array $index, Collection $collection): Index|false } } - private function calculateUserTypes(array $user): array - { - if (empty($user['password_hash']) && empty($user['phone_number'])) { - return [User::TYPE_ANONYMOUS]; - } - - $types = []; - - if (! empty($user['password_hash'])) { - $types[] = User::TYPE_PASSWORD; - } - - if (! empty($user['phone_number'])) { - $types[] = User::TYPE_PHONE; - } - - return $types; - } - protected function exportGroupStorage(int $batchSize, array $resources) { try { diff --git a/src/Migration/Sources/Supabase.php b/src/Migration/Sources/Supabase.php index 32397f1..375c3c6 100644 --- a/src/Migration/Sources/Supabase.php +++ b/src/Migration/Sources/Supabase.php @@ -385,7 +385,6 @@ private function exportUsers(int $batchSize) '', new Hash($user['encrypted_password'], '', Hash::ALGORITHM_BCRYPT), $user['phone'] ?? '', - $this->calculateAuthTypes($user), [], '', ! empty($user['email_confirmed_at']), @@ -410,25 +409,6 @@ private function convertMimes(array $mimes): array return $extensions; } - private function calculateAuthTypes(array $user): array - { - if (empty($user['encrypted_password']) && empty($user['phone'])) { - return [User::TYPE_ANONYMOUS]; - } - - $types = []; - - if (! empty($user['encrypted_password'])) { - $types[] = User::TYPE_PASSWORD; - } - - if (! empty($user['phone'])) { - $types[] = User::TYPE_PHONE; - } - - return $types; - } - protected function exportGroupStorage(int $batchSize, array $resources) { try {