Skip to content

Commit

Permalink
BUGFIX: Properly update node info after node move changes have been d…
Browse files Browse the repository at this point in the history
…iscarded
  • Loading branch information
grebaldi committed May 23, 2023
1 parent 5e6c01e commit c4bad62
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Classes/ContentRepository/Service/NodeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,28 @@ public function getNodeFromContextPath($contextPath, Site $site = null, Domain $
* @return boolean
*/
public function nodeExistsInWorkspace(NodeInterface $node, Workspace $workspace)
{
return $this->getNodeInWorkspace($node, $workspace) !== null;
}

/**
* Get the variant of the given node in the given workspace
*
* @param NodeInterface $node
* @param Workspace $workspace
* @return NodeInterface|null
*/
public function getNodeInWorkspace(NodeInterface $node, Workspace $workspace): ?NodeInterface
{
$context = ['workspaceName' => $workspace->getName()];
$flowQuery = new FlowQuery([$node]);

return $flowQuery->context($context)->count() > 0;
$result = $flowQuery->context($context);
if ($result->count() > 0) {
return $result->get(0);
} else {
return null;
}
}

/**
Expand Down
14 changes: 13 additions & 1 deletion Classes/Controller/BackendServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,19 @@ public function discardAction(array $nodeContextPaths): void
$reloadDocument = new ReloadDocument();
$this->feedbackCollection->add($reloadDocument);
}
} elseif (!$this->nodeService->nodeExistsInWorkspace($node, $node->getWorkSpace()->getBaseWorkspace())) {
} elseif ($nodeInBaseWorkspace = $this->nodeService->getNodeInWorkspace($node, $node->getWorkSpace()->getBaseWorkspace())) {
$nodeHasBeenMoved = $node->getPath() !== $nodeInBaseWorkspace->getPath();
if ($nodeHasBeenMoved) {
$removeNode = new RemoveNode();
$removeNode->setNode($node);
$this->feedbackCollection->add($removeNode);

$updateNodeInfo = new UpdateNodeInfo();
$updateNodeInfo->setNode($nodeInBaseWorkspace);
$updateNodeInfo->recursive();
$this->feedbackCollection->add($updateNodeInfo);
}
} else {
// If the node doesn't exist in the target workspace, tell the UI to remove it
$removeNode = new RemoveNode();
$removeNode->setNode($node);
Expand Down

0 comments on commit c4bad62

Please sign in to comment.