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

Open
wants to merge 3 commits into
base: 8.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
15 changes: 12 additions & 3 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 @@ -773,8 +774,16 @@ public function similarize(AbstractNodeData $sourceNode, $isCopy = false)
$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', 'lastModificationDateTime'];
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
21 changes: 21 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,27 @@ 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');
$lastModificationDateTime = \DateTime::createFromFormat('Y-m-d', '2002-02-02 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);
$sourceNode->_set('lastModificationDateTime', $lastModificationDateTime);

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

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

/**
* @test
*/
Expand Down
Loading