From 765d68b20c3f79760b18ed7a08dff979d86e9f62 Mon Sep 17 00:00:00 2001 From: pKallert Date: Fri, 29 Nov 2024 10:48:40 +0100 Subject: [PATCH] Task: Move removeWorkspaceRoleAssignment and deleteWorkspaceMetadata to metadataAndRoleRepository --- .../WorkspaceMetadataAndRoleRepository.php | 53 +++++++ .../Domain/Service/WorkspaceService.php | 139 +----------------- 2 files changed, 55 insertions(+), 137 deletions(-) diff --git a/Neos.Neos/Classes/Domain/Repository/WorkspaceMetadataAndRoleRepository.php b/Neos.Neos/Classes/Domain/Repository/WorkspaceMetadataAndRoleRepository.php index ed6c928f6c..6f67bc7cfb 100644 --- a/Neos.Neos/Classes/Domain/Repository/WorkspaceMetadataAndRoleRepository.php +++ b/Neos.Neos/Classes/Domain/Repository/WorkspaceMetadataAndRoleRepository.php @@ -311,4 +311,57 @@ public function findPrimaryWorkspaceNameForUser(ContentRepositoryId $contentRepo ]); return $workspaceName === false ? null : WorkspaceName::fromString($workspaceName); } + + public 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); + } + } + + public 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); + } + } + } diff --git a/Neos.Neos/Classes/Domain/Service/WorkspaceService.php b/Neos.Neos/Classes/Domain/Service/WorkspaceService.php index 9fe8a829c7..cbd4df4785 100644 --- a/Neos.Neos/Classes/Domain/Service/WorkspaceService.php +++ b/Neos.Neos/Classes/Domain/Service/WorkspaceService.php @@ -282,40 +282,11 @@ public function deleteWorkspace(ContentRepositoryId $contentRepositoryId, Worksp ) ); - $this->deleteWorkspaceMetadata($contentRepositoryId, $workspaceName); - $this->deleteWorkspaceRoleAssignments($contentRepositoryId, $workspaceName); + $this->metadataAndRoleRepository->deleteWorkspaceMetadata($contentRepositoryId, $workspaceName); + $this->metadataAndRoleRepository->deleteWorkspaceRoleAssignments($contentRepositoryId, $workspaceName); } // ------------------ - public function removeWorkspaceRoleAssignment(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceRoleSubject $fromString) - { - } - - 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 createWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceName $baseWorkspaceName, UserId|null $ownerId, WorkspaceClassification $classification): void { @@ -330,112 +301,6 @@ private function createWorkspace(ContentRepositoryId $contentRepositoryId, Works $this->metadataAndRoleRepository->addWorkspaceMetadata($contentRepositoryId, $workspaceName, $title, $description, $classification, $ownerId); } - private function addWorkspaceMetadata(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceClassification $classification, UserId|null $ownerUserId): void - { - try { - $this->dbal->insert(self::TABLE_NAME_WORKSPACE_METADATA, [ - 'content_repository_id' => $contentRepositoryId->value, - 'workspace_name' => $workspaceName->value, - 'title' => $title->value, - 'description' => $description->value, - 'classification' => $classification->value, - 'owner_user_id' => $ownerUserId?->value, - ]); - } catch (DbalException $e) { - throw new \RuntimeException(sprintf('Failed to add metadata for workspace "%s" (Content Repository "%s"): %s', $workspaceName->value, $contentRepositoryId->value, $e->getMessage()), 1727084068, $e); - } - } - - private function findPrimaryWorkspaceNameForUser(ContentRepositoryId $contentRepositoryId, UserId $userId): ?WorkspaceName - { - $tableMetadata = self::TABLE_NAME_WORKSPACE_METADATA; - $query = <<dbal->fetchOne($query, [ - 'contentRepositoryId' => $contentRepositoryId->value, - 'personalWorkspaceClassification' => WorkspaceClassification::PERSONAL->value, - 'userId' => $userId->value, - ]); - return $workspaceName === false ? null : WorkspaceName::fromString($workspaceName); - } - - 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); - } - } - - /** - * @param array $userRoles - */ - private function loadWorkspaceRoleOfUser(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, UserId $userId, array $userRoles): ?WorkspaceRole - { - $tableRole = self::TABLE_NAME_WORKSPACE_ROLE; - $query = <<dbal->fetchOne($query, [ - 'contentRepositoryId' => $contentRepositoryId->value, - 'workspaceName' => $workspaceName->value, - 'userSubjectType' => WorkspaceRoleSubjectType::USER->value, - 'userId' => $userId->value, - 'groupSubjectType' => WorkspaceRoleSubjectType::GROUP->value, - 'groupSubjects' => $userRoles, - ], [ - 'groupSubjects' => ArrayParameterType::STRING, - ]); - if ($role === false) { - return null; - } - return WorkspaceRole::from($role); - } - private function requireWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName): Workspace { $workspace = $this->contentRepositoryRegistry