From 74dd00b25de72d27a3ab72084f7f796863df36f0 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:27:40 +0100 Subject: [PATCH] TASK: Introduce `WorkspaceService::deleteWorkspace` to also removed assigned metadata and roles --- .../Command/WorkspaceCommandController.php | 7 +- .../Domain/Service/WorkspaceService.php | 69 +++++++++++++++++++ .../Controller/WorkspaceController.php | 7 +- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/Neos.Neos/Classes/Command/WorkspaceCommandController.php b/Neos.Neos/Classes/Command/WorkspaceCommandController.php index 2fdd87931c2..c250240d9d6 100644 --- a/Neos.Neos/Classes/Command/WorkspaceCommandController.php +++ b/Neos.Neos/Classes/Command/WorkspaceCommandController.php @@ -15,7 +15,6 @@ namespace Neos\Neos\Command; use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Exception\WorkspaceAlreadyExists; -use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\DeleteWorkspace; use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Dto\RebaseErrorHandlingStrategy; use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Exception\WorkspaceRebaseFailed; use Neos\ContentRepository\Core\Service\WorkspaceMaintenanceServiceFactory; @@ -416,11 +415,7 @@ public function deleteCommand(string $workspace, bool $force = false, string $co $this->workspacePublishingService->discardAllWorkspaceChanges($contentRepositoryId, $workspaceName); } - $contentRepositoryInstance->handle( - DeleteWorkspace::create( - $workspaceName - ) - ); + $this->workspaceService->deleteWorkspace($contentRepositoryId, $workspaceName); $this->outputLine('Deleted workspace "%s"', [$workspaceName->value]); } diff --git a/Neos.Neos/Classes/Domain/Service/WorkspaceService.php b/Neos.Neos/Classes/Domain/Service/WorkspaceService.php index 97a9d697aeb..8d7e11d2e4f 100644 --- a/Neos.Neos/Classes/Domain/Service/WorkspaceService.php +++ b/Neos.Neos/Classes/Domain/Service/WorkspaceService.php @@ -21,6 +21,7 @@ use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateRootWorkspace; use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateWorkspace; use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Exception\WorkspaceAlreadyExists; +use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\DeleteWorkspace; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; @@ -195,6 +196,21 @@ public function createPersonalWorkspaceForUserIfMissing(ContentRepositoryId $con ); } + public function deleteWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName): void + { + $contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId); + $this->requireWorkspace($contentRepositoryId, $workspaceName); + + $contentRepository->handle( + DeleteWorkspace::create( + $workspaceName, + ) + ); + + $this->deleteWorkspaceMetadata($contentRepositoryId, $workspaceName); + $this->deleteWorkspaceRoleAssignments($contentRepositoryId, $workspaceName); + } + /** * Assign a workspace role to the given user/user group * @@ -515,6 +531,59 @@ private function loadWorkspaceRoleOfUser(ContentRepositoryId $contentRepositoryI return WorkspaceRole::from($role); } + private function deleteWorkspaceMetadata(ContentRepositoryId $contentRepositoryId, $workspaceName): void + { + $table = self::TABLE_NAME_WORKSPACE_METADATA; + $query = <<dbal->executeStatement($query, [ + 'contentRepositoryId' => $contentRepositoryId->value, + 'workspaceName' => $workspaceName->value, + ]); + } catch (DbalException $e) { + throw new \RuntimeException(sprintf( + 'Failed to delete metadata for workspace "%s" (Content Repository "%s"): %s', + $workspaceName->value, + $contentRepositoryId->value, + $e->getMessage() + ), 1726821159, $e); + } + } + + + private function deleteWorkspaceRoleAssignments(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName): void + { + $table = self::TABLE_NAME_WORKSPACE_ROLE; + $query = <<dbal->executeStatement($query, [ + 'contentRepositoryId' => $contentRepositoryId->value, + 'workspaceName' => $workspaceName->value, + ]); + } catch (DbalException $e) { + throw new \RuntimeException(sprintf( + 'Failed to delete role assignments for workspace "%s" (Content Repository "%s"): %s', + $workspaceName->value, + $contentRepositoryId->value, + $e->getMessage() + ), 1726821159, $e); + } + } + private function requireWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName): Workspace { $workspace = $this->contentRepositoryRegistry diff --git a/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php b/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php index 61ed35b2493..a78ac450a82 100644 --- a/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php +++ b/Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php @@ -18,7 +18,6 @@ use Neos\ContentRepository\Core\ContentRepository; use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint; use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Exception\WorkspaceAlreadyExists; -use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\DeleteWorkspace; use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\DiscardIndividualNodesFromWorkspace; use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\PublishIndividualNodesFromWorkspace; use Neos\ContentRepository\Core\Feature\WorkspacePublication\Dto\NodeIdsToPublishOrDiscard; @@ -405,11 +404,7 @@ public function deleteAction(WorkspaceName $workspaceName): void $this->redirect('index'); } - $contentRepository->handle( - DeleteWorkspace::create( - $workspaceName, - ) - ); + $this->workspaceService->deleteWorkspace($contentRepositoryId, $workspaceName); $this->addFlashMessage($this->translator->translateById( 'workspaces.workspaceHasBeenRemoved',