diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 4cb2eb331f..ec3382d78b 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -4,12 +4,12 @@ use Appwrite\Auth\Auth; use Appwrite\Auth\MFA\Type\TOTP; use Appwrite\Auth\Validator\Phone; use Appwrite\Detector\Detector; -use Appwrite\Event\Delete; use Appwrite\Event\Event; use Appwrite\Event\Mail; use Appwrite\Event\Messaging; use Appwrite\Extend\Exception; use Appwrite\Network\Validator\Email; +use Appwrite\Platform\Workers\Deletes; use Appwrite\Template\Template; use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Database\Validator\Queries\Memberships; @@ -338,10 +338,12 @@ App::delete('/v1/teams/:teamId') ->label('sdk.response.model', Response::MODEL_NONE) ->param('teamId', '', new UID(), 'Team ID.') ->inject('response') + ->inject('getProjectDB') ->inject('dbForProject') + ->inject('dbForConsole') ->inject('queueForEvents') - ->inject('queueForDeletes') - ->action(function (string $teamId, Response $response, Database $dbForProject, Event $queueForEvents, Delete $queueForDeletes) { + ->inject('project') + ->action(function (string $teamId, Response $response, callable $getProjectDB, Database $dbForProject, Database $dbForConsole, Event $queueForEvents, Document $project) { $team = $dbForProject->getDocument('teams', $teamId); @@ -353,9 +355,8 @@ App::delete('/v1/teams/:teamId') throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove team from DB'); } - $queueForDeletes - ->setType(DELETE_TYPE_DOCUMENT) - ->setDocument($team); + $deletes = new Deletes(); + $deletes->deleteTeams($dbForConsole, $getProjectDB, $team, $project); $queueForEvents ->setParam('teamId', $team->getId()) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 88fb1197f7..e6046779b6 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -67,6 +67,7 @@ services: - appwrite-config:/storage/config:rw - appwrite-certificates:/storage/certificates:rw - appwrite-functions:/storage/functions:rw + - appwrite-builds:/storage/builds:rw depends_on: - mariadb - redis diff --git a/docker-compose.yml b/docker-compose.yml index 96c1d0007f..22dc9cd673 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -78,6 +78,7 @@ services: - appwrite-config:/storage/config:rw - appwrite-certificates:/storage/certificates:rw - appwrite-functions:/storage/functions:rw + - appwrite-builds:/storage/builds:rw - ./phpunit.xml:/usr/src/code/phpunit.xml - ./tests:/usr/src/code/tests - ./app:/usr/src/code/app diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 189ef6496b..615fa16aff 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -94,10 +94,7 @@ class Deletes extends Action $this->deleteUser($getProjectDB, $document, $project); break; case DELETE_TYPE_TEAMS: - $this->deleteMemberships($getProjectDB, $document, $project); - if ($project->getId() === 'console') { - $this->deleteProjectsByTeam($dbForConsole, $getProjectDB, $deviceForFiles, $deviceForFunctions, $deviceForBuilds, $deviceForCache, $document); - } + $this->deleteTeams($dbForConsole, $getProjectDB, $document, $project); break; case DELETE_TYPE_BUCKETS: $this->deleteBucket($getProjectDB, $deviceForFiles, $document, $project); @@ -445,14 +442,21 @@ class Deletes extends Action * @throws Conflict * @throws Restricted * @throws Structure + * @throws Exception */ - private function deleteProjectsByTeam(Database $dbForConsole, callable $getProjectDB, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, Document $document): void + private function deleteProjectsByTeam(Database $dbForConsole, callable $getProjectDB, Document $document): void { $projects = $dbForConsole->find('projects', [ Query::equal('teamInternalId', [$document->getInternalId()]) ]); + foreach ($projects as $project) { + $deviceForFiles = getDevice(APP_STORAGE_UPLOADS . '/app-' . $project->getId()); + $deviceForFunctions = getDevice(APP_STORAGE_FUNCTIONS . '/app-' . $project->getId()); + $deviceForBuilds = getDevice(APP_STORAGE_BUILDS . '/app-' . $project->getId()); + $deviceForCache = getDevice(APP_STORAGE_CACHE . '/app-' . $project->getId()); + $this->deleteProject($dbForConsole, $getProjectDB, $deviceForFiles, $deviceForFunctions, $deviceForBuilds, $deviceForCache, $project); $dbForConsole->deleteDocument('projects', $project->getId()); } @@ -1125,4 +1129,16 @@ class Deletes extends Action ); } } + + /** + * @throws Exception + * @throws Throwable + */ + public function deleteTeams($dbForConsole, $getProjectDB, $team, $project): void + { + $this->deleteMemberships($getProjectDB, $team, $project); + if ($project->getId() === 'console') { + $this->deleteProjectsByTeam($dbForConsole, $getProjectDB, $team); + } + } }