From 4aaa3bfd9fbd6560cc6b9214913c9ed61c45a869 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Thu, 5 Feb 2026 13:27:06 +0530 Subject: [PATCH 1/2] Cleanup functions & sites attribute when installation is deleted --- src/Appwrite/Platform/Workers/Deletes.php | 37 ++++++++++++----------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index dc1775e8b0..a3662e91e6 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -974,7 +974,7 @@ class Deletes extends Action $deploymentIds = []; $this->deleteByGroup('deployments', [ Query::equal('resourceInternalId', [$siteInternalId]), - Query::equal('resourceType', ['site']), + Query::equal('resourceType', ['sites']), Query::orderAsc() ], $dbForProject, function (Document $document) use ($project, $certificates, $deviceForSites, $deviceForBuilds, $deviceForFiles, $dbForPlatform, &$deploymentInternalIds) { $deploymentInternalIds[] = $document->getSequence(); @@ -1062,7 +1062,7 @@ class Deletes extends Action $deploymentInternalIds = []; $this->deleteByGroup('deployments', [ Query::equal('resourceInternalId', [$functionInternalId]), - Query::equal('resourceType', ['function']), + Query::equal('resourceType', ['functions']), Query::orderAsc() ], $dbForProject, function (Document $document) use ($dbForPlatform, $project, $certificates, $deviceForFunctions, $deviceForBuilds, &$deploymentInternalIds) { $deploymentInternalIds[] = $document->getSequence(); @@ -1400,22 +1400,25 @@ class Deletes extends Action { $dbForProject = $getProjectDB($project); - $this->listByGroup('functions', [ - Query::equal('installationInternalId', [$document->getSequence()]) - ], $dbForProject, function ($function) use ($dbForProject, $dbForPlatform) { - $dbForPlatform->deleteDocument('repositories', $function->getAttribute('repositoryId')); + // Cleanup sites and functions + foreach (['sites', 'functions'] as $resource) { + $this->listByGroup($resource, [ + Query::equal('installationInternalId', [$document->getSequence()]) + ], $dbForProject, function ($document) use ($resource, $dbForProject, $dbForPlatform) { + $dbForPlatform->deleteDocument('repositories', $document->getAttribute('repositoryId')); - $function = $function - ->setAttribute('installationId', '') - ->setAttribute('installationInternalId', '') - ->setAttribute('providerRepositoryId', '') - ->setAttribute('providerBranch', '') - ->setAttribute('providerSilentMode', false) - ->setAttribute('providerRootDirectory', '') - ->setAttribute('repositoryId', '') - ->setAttribute('repositoryInternalId', ''); - $dbForProject->updateDocument('functions', $function->getId(), $function); - }); + $document = $document + ->setAttribute('installationId', '') + ->setAttribute('installationInternalId', '') + ->setAttribute('providerRepositoryId', '') + ->setAttribute('providerBranch', '') + ->setAttribute('providerSilentMode', false) + ->setAttribute('providerRootDirectory', '') + ->setAttribute('repositoryId', '') + ->setAttribute('repositoryInternalId', ''); + $dbForProject->updateDocument($resource, $document->getId(), $document); + }); + } } /** From aa30db213639b79bfff3f27b6076b2d300383e6f Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Thu, 5 Feb 2026 13:51:32 +0530 Subject: [PATCH 2/2] refactor --- src/Appwrite/Platform/Workers/Deletes.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index a3662e91e6..435ce56f83 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -1391,21 +1391,24 @@ class Deletes extends Action /** * @param Database $dbForPlatform * @param callable $getProjectDB - * @param Document $document + * @param Document $installation * @param Document $project * @return void * @throws Exception */ - private function deleteInstallation(Database $dbForPlatform, callable $getProjectDB, Document $document, Document $project): void + private function deleteInstallation(Database $dbForPlatform, callable $getProjectDB, Document $installation, Document $project): void { $dbForProject = $getProjectDB($project); // Cleanup sites and functions - foreach (['sites', 'functions'] as $resource) { - $this->listByGroup($resource, [ - Query::equal('installationInternalId', [$document->getSequence()]) - ], $dbForProject, function ($document) use ($resource, $dbForProject, $dbForPlatform) { - $dbForPlatform->deleteDocument('repositories', $document->getAttribute('repositoryId')); + foreach (['sites', 'functions'] as $collection) { + $this->listByGroup($collection, [ + Query::equal('installationInternalId', [$installation->getSequence()]) + ], $dbForProject, function ($document) use ($collection, $dbForProject, $dbForPlatform) { + $repositoryId = $document->getAttribute('repositoryId', ''); + if (!empty($repositoryId)) { + $dbForPlatform->deleteDocument('repositories', $repositoryId); + } $document = $document ->setAttribute('installationId', '') @@ -1416,7 +1419,7 @@ class Deletes extends Action ->setAttribute('providerRootDirectory', '') ->setAttribute('repositoryId', '') ->setAttribute('repositoryInternalId', ''); - $dbForProject->updateDocument($resource, $document->getId(), $document); + $dbForProject->updateDocument($collection, $document->getId(), $document); }); } }