From 04763af7835aad3eb7b0824ef73db50c92f1aced Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Wed, 9 Oct 2024 17:29:39 +0200 Subject: [PATCH 1/3] BUGFIX: Force direct access on setting node properties in node data similarize --- .../Classes/Domain/Model/NodeData.php | 2 +- .../Tests/Unit/Domain/Model/NodeDataTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Neos.ContentRepository/Classes/Domain/Model/NodeData.php b/Neos.ContentRepository/Classes/Domain/Model/NodeData.php index c80d2c816e1..eec8da9c21e 100644 --- a/Neos.ContentRepository/Classes/Domain/Model/NodeData.php +++ b/Neos.ContentRepository/Classes/Domain/Model/NodeData.php @@ -774,7 +774,7 @@ public function similarize(AbstractNodeData $sourceNode, $isCopy = false) $propertyNames[] = 'removed'; } foreach ($propertyNames as $propertyName) { - ObjectAccess::setProperty($this, $propertyName, ObjectAccess::getProperty($sourceNode, $propertyName)); + ObjectAccess::setProperty($this, $propertyName, ObjectAccess::getProperty($sourceNode, $propertyName), true); } $contentObject = $sourceNode->getContentObject(); diff --git a/Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php b/Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php index ae5851f639f..06bf60c2e95 100644 --- a/Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php +++ b/Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php @@ -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 */ From c82b775b47fc8ed93c864d72098fe386abd21083 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Wed, 9 Oct 2024 18:18:20 +0200 Subject: [PATCH 2/3] BUGFIX: Force direct access on setting node properties in node data similarize --- .../Classes/Domain/Model/NodeData.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Neos.ContentRepository/Classes/Domain/Model/NodeData.php b/Neos.ContentRepository/Classes/Domain/Model/NodeData.php index eec8da9c21e..bb09c06892b 100644 --- a/Neos.ContentRepository/Classes/Domain/Model/NodeData.php +++ b/Neos.ContentRepository/Classes/Domain/Model/NodeData.php @@ -1,4 +1,5 @@ getContentObject(); From d96fbb08709f4a9a5d2c28dd0562cca8a0a4129c Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Fri, 11 Oct 2024 16:40:34 +0200 Subject: [PATCH 3/3] BUGFIX: Force direct access on setting node properties in node data similarize --- Neos.ContentRepository/Classes/Domain/Model/NodeData.php | 3 +-- .../Tests/Unit/Domain/Model/NodeDataTest.php | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Neos.ContentRepository/Classes/Domain/Model/NodeData.php b/Neos.ContentRepository/Classes/Domain/Model/NodeData.php index bb09c06892b..cc21e835f61 100644 --- a/Neos.ContentRepository/Classes/Domain/Model/NodeData.php +++ b/Neos.ContentRepository/Classes/Domain/Model/NodeData.php @@ -768,7 +768,6 @@ public function similarize(AbstractNodeData $sourceNode, $isCopy = false) ]; if (!$isCopy) { $propertyNames[] = 'creationDateTime'; - $propertyNames[] = 'lastModificationDateTime'; } if ($sourceNode instanceof NodeData) { $propertyNames[] = 'index'; @@ -776,7 +775,7 @@ public function similarize(AbstractNodeData $sourceNode, $isCopy = false) } // We need to force direct access for the following properties, as they don't have a setter in AbstractNodeData - $propertyNamesToForceDirectAccess = ['creationDateTime', 'lastModificationDateTime']; + $propertyNamesToForceDirectAccess = ['creationDateTime']; foreach ($propertyNames as $propertyName) { ObjectAccess::setProperty( $this, diff --git a/Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php b/Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php index 06bf60c2e95..2c4599e70e8 100644 --- a/Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php +++ b/Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php @@ -673,19 +673,16 @@ public function similarizeClearsPropertiesBeforeAddingNewOnes() 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()); } /**