Fix not account for abuse/audit on project delete
This commit is contained in:
parent
191e1abefa
commit
60179b1790
1 changed files with 21 additions and 16 deletions
|
@ -443,7 +443,7 @@ class Deletes extends Action
|
|||
* @param Document $document
|
||||
* @return void
|
||||
* @throws Authorization
|
||||
* @throws \Utopia\Database\Exception
|
||||
* @throws DatabaseException
|
||||
* @throws Conflict
|
||||
* @throws Restricted
|
||||
* @throws Structure
|
||||
|
@ -471,11 +471,10 @@ class Deletes extends Action
|
|||
* @return void
|
||||
* @throws Exception
|
||||
* @throws Authorization
|
||||
* @throws \Utopia\Database\Exception
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
private function deleteProject(Database $dbForConsole, callable $getProjectDB, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, Document $document): void
|
||||
{
|
||||
$projectId = $document->getId();
|
||||
$projectInternalId = $document->getInternalId();
|
||||
|
||||
try {
|
||||
|
@ -486,24 +485,18 @@ class Deletes extends Action
|
|||
}
|
||||
|
||||
$dbForProject = $getProjectDB($document);
|
||||
$projectCollectionIds = \array_keys(Config::getParam('collections', [])['projects']);
|
||||
|
||||
$projectCollectionIds = [
|
||||
...\array_keys(Config::getParam('collections', [])['projects']),
|
||||
Audit::COLLECTION,
|
||||
TimeLimit::COLLECTION,
|
||||
];
|
||||
|
||||
$limit = \count($projectCollectionIds) + 25;
|
||||
|
||||
while (true) {
|
||||
$collections = $dbForProject->listCollections($limit);
|
||||
|
||||
if ($dsn->getHost() === DATABASE_SHARED_TABLES) {
|
||||
$collectionsIds = \array_map(fn ($collection) => $collection->getId(), $collections);
|
||||
|
||||
if ($collectionsIds == $projectCollectionIds) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (empty($collections)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($collections as $collection) {
|
||||
if ($dsn->getHost() !== DATABASE_SHARED_TABLES || !\in_array($collection->getId(), $projectCollectionIds)) {
|
||||
$dbForProject->deleteCollection($collection->getId());
|
||||
|
@ -511,6 +504,16 @@ class Deletes extends Action
|
|||
$this->deleteByGroup($collection->getId(), [], database: $dbForProject);
|
||||
}
|
||||
}
|
||||
|
||||
if ($dsn->getHost() === DATABASE_SHARED_TABLES) {
|
||||
$collectionsIds = \array_map(fn ($collection) => $collection->getId(), $collections);
|
||||
|
||||
if (empty(\array_diff($collectionsIds, $projectCollectionIds))) {
|
||||
break;
|
||||
}
|
||||
} elseif (empty($collections)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Platforms
|
||||
|
@ -553,6 +556,8 @@ class Deletes extends Action
|
|||
// Delete metadata table
|
||||
if ($dsn->getHost() !== DATABASE_SHARED_TABLES) {
|
||||
$dbForProject->deleteCollection('_metadata');
|
||||
} else {
|
||||
$this->deleteByGroup('_metadata', [], $dbForProject);
|
||||
}
|
||||
|
||||
// Delete all storage directories
|
||||
|
|
Loading…
Reference in a new issue