diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index dc1775e8b0..435ce56f83 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(); @@ -1391,31 +1391,37 @@ 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); - $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 $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); + } - $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($collection, $document->getId(), $document); + }); + } } /**