diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index 6b730a18..98a4e94f 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -1473,7 +1473,17 @@ public function importFunctionResource(Resource $resource): Resource */ private function importDeployment(Deployment $deployment): Resource { - $functionId = $deployment->getFunction()->getId(); + $function = $deployment->getFunction(); + + // Deployment API always creates a new deployment, so unlike other resources + // there's no duplicate detection. Skip if the parent function wasn't imported successfully. + if ($function->getStatus() !== Resource::STATUS_SUCCESS) { + $deployment->setStatus(Resource::STATUS_SKIPPED, 'Parent function "' . $function->getId() . '" failed to import'); + + return $deployment; + } + + $functionId = $function->getId(); $response = null; @@ -1508,7 +1518,7 @@ private function importDeployment(Deployment $deployment): Resource [ 'functionId' => $functionId, 'code' => new \CURLFile('data://application/gzip;base64,' . base64_encode($deployment->getData()), 'application/gzip', 'deployment.tar.gz'), - 'activate' => $deployment->getActivated(), + 'activate' => $deployment->getActivated() ? 'true' : 'false', 'entrypoint' => $deployment->getEntrypoint(), ] ); @@ -1674,7 +1684,17 @@ public function importSiteResource(Resource $resource): Resource */ private function importSiteDeployment(SiteDeployment $deployment): Resource { - $siteId = $deployment->getSite()->getId(); + $site = $deployment->getSite(); + + // Deployment API always creates a new deployment, so unlike other resources + // there's no duplicate detection. Skip if the parent site wasn't imported successfully. + if ($site->getStatus() !== Resource::STATUS_SUCCESS) { + $deployment->setStatus(Resource::STATUS_SKIPPED, 'Parent site "' . $site->getId() . '" failed to import'); + + return $deployment; + } + + $siteId = $site->getId(); if ($deployment->getSize() <= Transfer::STORAGE_MAX_CHUNK_SIZE) { $response = $this->client->call( @@ -1686,7 +1706,7 @@ private function importSiteDeployment(SiteDeployment $deployment): Resource [ 'siteId' => $siteId, 'code' => new \CURLFile('data://application/gzip;base64,' . base64_encode($deployment->getData()), 'application/gzip', 'deployment.tar.gz'), - 'activate' => $deployment->getActivated(), + 'activate' => $deployment->getActivated() ? 'true' : 'false', ] ); @@ -1710,7 +1730,7 @@ private function importSiteDeployment(SiteDeployment $deployment): Resource [ 'siteId' => $siteId, 'code' => new \CURLFile('data://application/gzip;base64,' . base64_encode($deployment->getData()), 'application/gzip', 'deployment.tar.gz'), - 'activate' => $deployment->getActivated(), + 'activate' => $deployment->getActivated() ? 'true' : 'false', ] ); diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 47a03461..2844bcf1 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -1518,9 +1518,8 @@ protected function exportGroupFunctions(int $batchSize, array $resources): void } try { - if (\in_array(Resource::TYPE_DEPLOYMENT, $resources)) { - $this->exportDeployments($batchSize, true); - } + $exportOnlyActive = !\in_array(Resource::TYPE_DEPLOYMENT, $resources); + $this->exportDeployments($batchSize, $exportOnlyActive); } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_DEPLOYMENT, @@ -1549,9 +1548,8 @@ protected function exportGroupSites(int $batchSize, array $resources): void } try { - if (\in_array(Resource::TYPE_SITE_DEPLOYMENT, $resources)) { - $this->exportSiteDeployments($batchSize, true); - } + $exportOnlyActive = !\in_array(Resource::TYPE_SITE_DEPLOYMENT, $resources); + $this->exportSiteDeployments($batchSize, $exportOnlyActive); } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_SITE_DEPLOYMENT, @@ -1643,8 +1641,13 @@ private function exportDeployments(int $batchSize, bool $exportOnlyActive = fals /** @var Func $func */ $lastDocument = null; - if ($exportOnlyActive && $func->getActiveDeployment()) { - $deployment = $this->functions->getDeployment($func->getId(), $func->getActiveDeployment()); + if ($exportOnlyActive) { + $activeDeploymentId = $func->getActiveDeployment(); + if (empty($activeDeploymentId)) { + continue; // active-only mode: nothing to export for this function + } + + $deployment = $this->functions->getDeployment($func->getId(), $activeDeploymentId); try { $this->exportDeploymentData($func, $deployment); @@ -1865,8 +1868,13 @@ private function exportSiteDeployments(int $batchSize, bool $exportOnlyActive = /** @var Site $site */ $lastDocument = null; - if ($exportOnlyActive && $site->getActiveDeployment()) { - $deployment = $this->sites->getDeployment($site->getId(), $site->getActiveDeployment()); + if ($exportOnlyActive) { + $activeDeploymentId = $site->getActiveDeployment(); + if (empty($activeDeploymentId)) { + continue; // active-only mode: nothing to export for this site + } + + $deployment = $this->sites->getDeployment($site->getId(), $activeDeploymentId); try { $this->exportSiteDeploymentData($site, $deployment);