diff --git a/Classes/ContentRepository/Service/NodeService.php b/Classes/ContentRepository/Service/NodeService.php index 5547b239b8..49ccb8492a 100644 --- a/Classes/ContentRepository/Service/NodeService.php +++ b/Classes/ContentRepository/Service/NodeService.php @@ -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; + } } /** diff --git a/Classes/Controller/BackendServiceController.php b/Classes/Controller/BackendServiceController.php index 4d75c29c32..e70d8d1a63 100644 --- a/Classes/Controller/BackendServiceController.php +++ b/Classes/Controller/BackendServiceController.php @@ -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);