Skip to content
Open
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
58 changes: 51 additions & 7 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand All @@ -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;

Expand Down Expand Up @@ -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(),
]
);
Expand Down Expand Up @@ -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()
);
Expand All @@ -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(
Expand All @@ -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',
]
);

Expand All @@ -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',
]
);

Expand Down
10 changes: 4 additions & 6 deletions src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +1521 to +1522
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

$exportOnlyActive mode can still export all deployments when no active deployment exists.

When Line 1521 / Line 1551 set active-only mode, functions/sites without an active deployment ID currently fall through to paginated listing and export all deployments. That breaks the include-inactive contract for this edge case.

🔧 Proposed fix
--- a/src/Migration/Sources/Appwrite.php
+++ b/src/Migration/Sources/Appwrite.php
@@
-            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);
@@
                 continue;
             }
@@
-            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);
@@
                 continue;
             }

Also applies to: 1551-1552

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Migration/Sources/Appwrite.php` around lines 1521 - 1522,
$exportOnlyActive is being set when Resource::TYPE_DEPLOYMENT is not requested
but currently code falls back to paginated listing and exports all deployments
for resources (functions/sites) that lack an active deployment; change the
callers and exportDeployments logic so that when $exportOnlyActive is true you
only export deployments explicitly referenced by an active deployment ID and
never fall back to the full paginated export: detect resources (functions/sites)
with no activeDeploymentId and skip exporting their deployments (do not call the
paginated listing), and ensure the same change is applied to the second
occurrence around the lines mentioned (the other $exportOnlyActive usage).

} catch (\Throwable $e) {
$this->addError(new Exception(
Resource::TYPE_DEPLOYMENT,
Expand Down Expand Up @@ -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,
Expand Down