Skip to content

Commit

Permalink
Merge pull request #5186 from neos/bugfix/copy-removed-nodes
Browse files Browse the repository at this point in the history
BUGFIX: Don’t copy removed nodes
  • Loading branch information
bwaidelich authored Aug 14, 2024
2 parents e8cd515 + 6936b7b commit 2fe0915
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Neos.ContentRepository/Classes/Domain/Model/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Neos.ContentRepository/Classes/Domain/Model/NodeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
28 changes: 28 additions & 0 deletions Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 2fe0915

Please sign in to comment.