From 2391ba07dfb725584dc25c113f4737a029a1a149 Mon Sep 17 00:00:00 2001 From: fogelito Date: Fri, 19 Apr 2024 18:04:54 +0300 Subject: [PATCH] deleteByGroup --- src/Appwrite/Platform/Workers/Databases.php | 31 +++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 0d1ae1489..b305279e7 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -503,6 +503,7 @@ class Databases extends Action * @throws DatabaseException * @throws Restricted * @throws Structure + * @throws Exception */ protected function deleteCollection(Document $database, Document $collection, Document $project, Database $dbForProject): void { @@ -518,20 +519,22 @@ class Databases extends Action /** * Related collections relating to current collection */ - $attributes = $dbForProject->find('attributes', [ - Query::equal('databaseInternalId', [$databaseInternalId]), - Query::equal('type', [Database::VAR_RELATIONSHIP]), - Query::notEqual('collectionInternalId', $collectionInternalId), - Query::contains('options', ['"relatedCollection":"'. $collectionId .'"']), - Query::limit(PHP_INT_MAX) - ]); - - foreach ($attributes as $attribute) { - $dbForProject->deleteDocument('attributes', $attribute->getId()); - Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); - $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); - $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); - } + $this->deleteByGroup( + 'attributes', + [ + Query::equal('databaseInternalId', [$databaseInternalId]), + Query::equal('type', [Database::VAR_RELATIONSHIP]), + Query::notEqual('collectionInternalId', $collectionInternalId), + Query::contains('options', ['"relatedCollection":"'. $collectionId .'"']), + ], + $dbForProject, + function ($attribute) use ($dbForProject, $databaseInternalId) { + $dbForProject->deleteDocument('attributes', $attribute->getId()); + Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); + $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); + $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); + } + ); $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getInternalId());