diff --git a/src/Migration/Destinations/Local.php b/src/Migration/Destinations/Local.php index 11156d8..457ea90 100644 --- a/src/Migration/Destinations/Local.php +++ b/src/Migration/Destinations/Local.php @@ -104,7 +104,7 @@ protected function import(array $resources, callable $callback): void case Resource::TYPE_DEPLOYMENT: /** @var Deployment $resource */ if ($resource->getStart() === 0) { - $this->data[$resource->getGroup()][$resource->getName()][$resource->getInternalId()] = $resource->asArray(); + $this->data[$resource->getGroup()][$resource->getName()][] = $resource->asArray(); } file_put_contents($this->path.'deployments/'.$resource->getId().'.tar.gz', $resource->getData(), FILE_APPEND); @@ -135,7 +135,7 @@ protected function import(array $resources, callable $callback): void $resource->setData(''); break; default: - $this->data[$resource->getGroup()][$resource->getName()][$resource->getInternalId()] = $resource->asArray(); + $this->data[$resource->getGroup()][$resource->getName()][] = $resource->asArray(); break; } diff --git a/src/Migration/Sources/Firebase.php b/src/Migration/Sources/Firebase.php index c7a9b9e..718952e 100644 --- a/src/Migration/Sources/Firebase.php +++ b/src/Migration/Sources/Firebase.php @@ -207,7 +207,7 @@ private function exportUsers(int $batchSize) $user['localId'] ?? '', $user['email'] ?? '', $user['displayName'] ?? $user['email'] ?? '', - new Hash($user['passwordHash'] ?? '', $user['salt'] ?? '', Hash::ALGORITHM_SCRYPT_MODIFIED, $hashConfig['saltSeparator'], $hashConfig['signerKey']), + new Hash($user['passwordHash'] ?? '', $user['salt'] ?? '', Hash::ALGORITHM_SCRYPT_MODIFIED, $hashConfig['saltSeparator'] ?? '', $hashConfig['signerKey'] ?? ''), $user['phoneNumber'] ?? '', $this->calculateUserType($user['providerUserInfo'] ?? []), '', @@ -394,6 +394,7 @@ private function exportCollection(Collection $collection, int $batchSize, bool $ $nextPageToken = null; $documentSchema = []; + $createdSchema = []; // Transfer Documents and Calculate Schemas while (true) { @@ -426,7 +427,23 @@ private function exportCollection(Collection $collection, int $batchSize, bool $ // Transfer Documents if ($transferDocuments) { - $this->callback(array_values($documentSchema)); + $cachedAtrributes = $this->cache->get(Attribute::getName()); + + $attributesToCreate = $documentSchema; + + foreach ($documentSchema as $key => $attribute) { + foreach ($cachedAtrributes as $cachedAttribute) { + /** @var Attribute $cachedAttribute */ + if ($cachedAttribute->getKey() == $attribute->getKey() && $cachedAttribute->getCollection()->getId() == $attribute->getCollection()->getId()) { + unset($attributesToCreate[$key]); + } + } + } + + if (count($attributesToCreate) > 0) { + $this->callback(array_values($attributesToCreate)); + } + $this->callback($documents); }