diff --git a/Neos.ContentRepository/Classes/Domain/Model/Node.php b/Neos.ContentRepository/Classes/Domain/Model/Node.php index 13909e0aebd..6f6b0df8882 100644 --- a/Neos.ContentRepository/Classes/Domain/Model/Node.php +++ b/Neos.ContentRepository/Classes/Domain/Model/Node.php @@ -1743,6 +1743,10 @@ protected function createRecursiveCopy(NodeInterface $referenceNode, string $nod } /** @var $childNode Node */ foreach ($this->getChildNodes() as $childNode) { + // Don't copy removed nodes + if ($childNode->isRemoved()) { + continue; + } // Prevent recursive copy when copying into itself if ($childNode->getIdentifier() !== $copiedNode->getIdentifier()) { $childNode->copyIntoInternal($copiedNode, $childNode->getName(), $detachedCopy); diff --git a/Neos.ContentRepository/Classes/Domain/Model/NodeData.php b/Neos.ContentRepository/Classes/Domain/Model/NodeData.php index ca5d7d581e2..c80d2c816e1 100644 --- a/Neos.ContentRepository/Classes/Domain/Model/NodeData.php +++ b/Neos.ContentRepository/Classes/Domain/Model/NodeData.php @@ -771,6 +771,7 @@ public function similarize(AbstractNodeData $sourceNode, $isCopy = false) } if ($sourceNode instanceof NodeData) { $propertyNames[] = 'index'; + $propertyNames[] = 'removed'; } foreach ($propertyNames as $propertyName) { ObjectAccess::setProperty($this, $propertyName, ObjectAccess::getProperty($sourceNode, $propertyName)); diff --git a/Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php b/Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php index 8c7d3288e85..222ebd27812 100644 --- a/Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php +++ b/Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php @@ -259,6 +259,34 @@ public function removedNodesAreNotCountedAsChildNodes() self::assertFalse($rootNode->hasChildNodes(), 'Third check.'); } + /** + * @test + */ + public function removedChildNodesAreNotCopied() + { + $rootNode = $this->context->getRootNode(); + $parentNode = $rootNode->createNode('parent'); + $parentNode->createNode('child'); + + $context = $this->contextFactory->create([ + 'workspaceName' => 'user-admin', + 'removedContentShown' => true, + ]); + $this->persistenceManager->persistAll(); + + $rootNode = $context->getRootNode(); + $parentNode = $rootNode->getNode('parent'); + self::assertTrue($parentNode->hasChildNodes(), 'Parent node should have child nodes, before they are removed'); + + $parentNode->getNode('child')->remove(); + $this->persistenceManager->persistAll(); + + $parentNode = $rootNode->getNode('parent'); + $parentClone = $parentNode->copyInto($rootNode, 'parent-clone'); + + self::assertFalse($parentClone->hasChildNodes(), 'Copied parent node should not have any child nodes'); + } + /** * @test */