Skip to content

Commit

Permalink
BUGFIX: Don’t copy removed nodes
Browse files Browse the repository at this point in the history
With this change, removed nodes are not copied anymore
in the recursive copy actions. Also the removed state is kept
when a node is similarisied to prevent unpublished removed
nodes from popping up again inadvertendly.

Resolves: #5185
  • Loading branch information
Sebobo committed Aug 14, 2024
1 parent 606e5e0 commit 6936b7b
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 6936b7b

Please sign in to comment.