Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: document-node is redirected to the nearest parent on workspace change #3734

Merged
merged 3 commits into from
May 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions Classes/Controller/BackendServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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];
c4ll-m3-j4ck marked this conversation as resolved.
Show resolved Hide resolved

// If current document node exists in the base workspace, then reload, else redirect
if ($redirectNode === $documentNode) {
Expand Down
Loading