mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 16:38:32 +00:00
Merge pull request #11253 from appwrite/ser-1033
Cleanup functions & sites attribute when installation is deleted
This commit is contained in:
commit
cb81939604
1 changed files with 25 additions and 19 deletions
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue