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

Open
wants to merge 3 commits into
base: 8.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 5 additions & 18 deletions Classes/Controller/BackendServiceController.php
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()->getCurrentSiteNode()->getPath();
$originalNodePath = $documentNode->getPath();

$userWorkspace->setBaseWorkspace($targetWorkspace);
$this->workspaceRepository->update($userWorkspace);

Expand All @@ -356,25 +359,9 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, NodeInter
$updateWorkspaceInfo->setWorkspace($userWorkspace);
$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 = array_pop($nodesOnPath) ?? $documentNode->getContext()->getCurrentSiteNode();

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