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: Force direct access on setting node properties in node data similarize #5281

Merged
merged 3 commits into from
Jan 20, 2025
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
16 changes: 12 additions & 4 deletions Neos.ContentRepository/Classes/Domain/Model/NodeData.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Neos\ContentRepository\Domain\Model;

/*
Expand Down Expand Up @@ -475,9 +476,9 @@ public function createNodeData($name, NodeType $nodeType = null, $identifier = n
* @param string $identifier The identifier of the node, unique within the workspace, optional(!)
* @param Workspace $workspace
* @param array $dimensions An array of dimension name to dimension values
* @throws NodeExistsException if a node with this path already exists.
* @throws \InvalidArgumentException if the node name is not accepted.
* @return NodeData
* @throws \InvalidArgumentException if the node name is not accepted.
* @throws NodeExistsException if a node with this path already exists.
*/
public function createSingleNodeData($name, NodeType $nodeType = null, $identifier = null, Workspace $workspace = null, array $dimensions = null)
{
Expand Down Expand Up @@ -767,14 +768,21 @@ public function similarize(AbstractNodeData $sourceNode, $isCopy = false)
];
if (!$isCopy) {
$propertyNames[] = 'creationDateTime';
$propertyNames[] = 'lastModificationDateTime';
}
if ($sourceNode instanceof NodeData) {
$propertyNames[] = 'index';
$propertyNames[] = 'removed';
}

// We need to force direct access for the following properties, as they don't have a setter in AbstractNodeData
$propertyNamesToForceDirectAccess = ['creationDateTime'];
foreach ($propertyNames as $propertyName) {
ObjectAccess::setProperty($this, $propertyName, ObjectAccess::getProperty($sourceNode, $propertyName));
ObjectAccess::setProperty(
$this,
$propertyName,
ObjectAccess::getProperty($sourceNode, $propertyName),
in_array($propertyName, $propertyNamesToForceDirectAccess)
);
}

$contentObject = $sourceNode->getContentObject();
Expand Down
18 changes: 18 additions & 0 deletions Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,24 @@ public function similarizeClearsPropertiesBeforeAddingNewOnes()
self::assertEquals($expectedProperties, $this->nodeData->getProperties());
}

/**
* @test
*/
public function similarizeCopiesCreationAndLastModificationDateTimes()
{
$creationDateTime = \DateTime::createFromFormat('Y-m-d', '2000-01-01 12:00:00');

/** @var $sourceNode NodeData */
$sourceNode = $this->getAccessibleMock(NodeData::class, ['addOrUpdate'], ['/foo/bar', $this->mockWorkspace]);
$this->inject($sourceNode, 'nodeTypeManager', $this->mockNodeTypeManager);
$sourceNode->_set('nodeDataRepository', $this->createMock(RepositoryInterface::class));
$sourceNode->_set('creationDateTime', $creationDateTime);

$this->nodeData->similarize($sourceNode);

self::assertSame($creationDateTime, $this->nodeData->getCreationDateTime());
}

/**
* @test
*/
Expand Down
Loading