Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Don’t copy removed nodes #5186

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a scenatio, where this change made a difference. But I guess it's fine to copy the property here too.

}
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
Loading