diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index 6b730a18..b9a25272 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -1451,8 +1451,19 @@ public function importFunctionResource(Resource $resource): Resource break; case Resource::TYPE_ENVIRONMENT_VARIABLE: /** @var EnvVar $resource */ + $function = $resource->getFunc(); + + if ($function->getStatus() === Resource::STATUS_ERROR) { + throw new Exception( + resourceName: $resource->getName(), + resourceGroup: $resource->getGroup(), + resourceId: $resource->getId(), + message: 'Parent function "' . $function->getId() . '" failed to import', + ); + } + $this->functions->createVariable( - $resource->getFunc()->getId(), + $function->getId(), $resource->getKey(), $resource->getValue() ); @@ -1473,7 +1484,18 @@ public function importFunctionResource(Resource $resource): Resource */ private function importDeployment(Deployment $deployment): Resource { - $functionId = $deployment->getFunction()->getId(); + $function = $deployment->getFunction(); + + if ($function->getStatus() === Resource::STATUS_ERROR) { + throw new Exception( + resourceName: $deployment->getName(), + resourceGroup: $deployment->getGroup(), + resourceId: $deployment->getId(), + message: 'Parent function "' . $function->getId() . '" failed to import', + ); + } + + $functionId = $function->getId(); $response = null; @@ -1508,7 +1530,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(), ] ); @@ -1652,8 +1674,19 @@ public function importSiteResource(Resource $resource): Resource break; case Resource::TYPE_SITE_VARIABLE: /** @var SiteEnvVar $resource */ + $site = $resource->getSite(); + + if ($site->getStatus() === Resource::STATUS_ERROR) { + throw new Exception( + resourceName: $resource->getName(), + resourceGroup: $resource->getGroup(), + resourceId: $resource->getId(), + message: 'Parent site "' . $site->getId() . '" failed to import', + ); + } + $this->sites->createVariable( - $resource->getSite()->getId(), + $site->getId(), $resource->getKey(), $resource->getValue() ); @@ -1674,7 +1707,18 @@ public function importSiteResource(Resource $resource): Resource */ private function importSiteDeployment(SiteDeployment $deployment): Resource { - $siteId = $deployment->getSite()->getId(); + $site = $deployment->getSite(); + + if ($site->getStatus() === Resource::STATUS_ERROR) { + throw new Exception( + resourceName: $deployment->getName(), + resourceGroup: $deployment->getGroup(), + resourceId: $deployment->getId(), + message: 'Parent site "' . $site->getId() . '" failed to import', + ); + } + + $siteId = $site->getId(); if ($deployment->getSize() <= Transfer::STORAGE_MAX_CHUNK_SIZE) { $response = $this->client->call( @@ -1686,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', ] ); @@ -1710,7 +1754,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..a2edd3a2 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,