From 58611a8646afdde613f7586b714fc387c569274c Mon Sep 17 00:00:00 2001 From: Michel Loew Date: Wed, 6 Mar 2024 13:48:43 +0100 Subject: [PATCH 1/3] BUGFIX: document-node is redirected to the nearest parent on workspace-change --- .../Controller/BackendServiceController.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Classes/Controller/BackendServiceController.php b/Classes/Controller/BackendServiceController.php index f78bc2d661..0e64c85774 100644 --- a/Classes/Controller/BackendServiceController.php +++ b/Classes/Controller/BackendServiceController.php @@ -345,6 +345,9 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, NodeInter throw new Exception('Your personal workspace currently contains unpublished changes. In order to switch to a different target workspace you need to either publish or discard pending changes first.', 1582800654); } + $sitePath = $documentNode->getContext()->getRootNode()->getPath(); + $originalNodePath = $documentNode->getPath(); + $userWorkspace->setBaseWorkspace($targetWorkspace); $this->workspaceRepository->update($userWorkspace); @@ -357,24 +360,13 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, NodeInter $this->feedbackCollection->add($updateWorkspaceInfo); // Construct base workspace context - $originalContext = $documentNode->getContext(); $contextProperties = $documentNode->getContext()->getProperties(); $contextProperties['workspaceName'] = $targetWorkspaceName; $contentContext = $this->contextFactory->create($contextProperties); // If current document node doesn't exist in the base workspace, traverse its parents to find the one that exists - $redirectNode = $documentNode; - while (true) { - $redirectNodeInBaseWorkspace = $contentContext->getNodeByIdentifier($redirectNode->getIdentifier()); - if ($redirectNodeInBaseWorkspace) { - break; - } else { - $redirectNode = $redirectNode->getParent(); - if (!$redirectNode) { - throw new Exception(sprintf('Wasn\'t able to locate any valid node in rootline of node %s in the workspace %s.', $documentNode->getContextPath(), $targetWorkspaceName), 1458814469); - } - } - } + $nodesOnPath = $documentNode->getContext()->getNodesOnPath($sitePath, $originalNodePath); + $redirectNode = $nodesOnPath[count($nodesOnPath) - 1]; // If current document node exists in the base workspace, then reload, else redirect if ($redirectNode === $documentNode) { From 817dad603d014d57424b062f4533c2a3102461f8 Mon Sep 17 00:00:00 2001 From: Michel Loew Date: Wed, 6 Mar 2024 14:02:13 +0100 Subject: [PATCH 2/3] TASK: Remove unnecessary contentContext --- Classes/Controller/BackendServiceController.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Classes/Controller/BackendServiceController.php b/Classes/Controller/BackendServiceController.php index 0e64c85774..5d3ffecc96 100644 --- a/Classes/Controller/BackendServiceController.php +++ b/Classes/Controller/BackendServiceController.php @@ -359,11 +359,6 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, NodeInter $updateWorkspaceInfo->setWorkspace($userWorkspace); $this->feedbackCollection->add($updateWorkspaceInfo); - // Construct base workspace context - $contextProperties = $documentNode->getContext()->getProperties(); - $contextProperties['workspaceName'] = $targetWorkspaceName; - $contentContext = $this->contextFactory->create($contextProperties); - // If current document node doesn't exist in the base workspace, traverse its parents to find the one that exists $nodesOnPath = $documentNode->getContext()->getNodesOnPath($sitePath, $originalNodePath); $redirectNode = $nodesOnPath[count($nodesOnPath) - 1]; From 27074c1eb943c539b72df7c7229bc6ccc45900bd Mon Sep 17 00:00:00 2001 From: Michel Loew Date: Wed, 6 Mar 2024 16:05:19 +0100 Subject: [PATCH 3/3] TASK: Definitely fall back to site-node --- Classes/Controller/BackendServiceController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/Controller/BackendServiceController.php b/Classes/Controller/BackendServiceController.php index 5d3ffecc96..cca92a59a1 100644 --- a/Classes/Controller/BackendServiceController.php +++ b/Classes/Controller/BackendServiceController.php @@ -345,7 +345,7 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, NodeInter throw new Exception('Your personal workspace currently contains unpublished changes. In order to switch to a different target workspace you need to either publish or discard pending changes first.', 1582800654); } - $sitePath = $documentNode->getContext()->getRootNode()->getPath(); + $sitePath = $documentNode->getContext()->getCurrentSiteNode()->getPath(); $originalNodePath = $documentNode->getPath(); $userWorkspace->setBaseWorkspace($targetWorkspace); @@ -361,7 +361,7 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, NodeInter // If current document node doesn't exist in the base workspace, traverse its parents to find the one that exists $nodesOnPath = $documentNode->getContext()->getNodesOnPath($sitePath, $originalNodePath); - $redirectNode = $nodesOnPath[count($nodesOnPath) - 1]; + $redirectNode = array_pop($nodesOnPath) ?? $documentNode->getContext()->getCurrentSiteNode(); // If current document node exists in the base workspace, then reload, else redirect if ($redirectNode === $documentNode) {