From 9b2b607608a3d35bc9551ccd6752310e1cf322ae Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:54:39 +0200 Subject: [PATCH] TASK: Reimplement _creationDateTime, _lastModificationDateTime and _lastPublicationDateTime support for `sort` --- .../FlowQueryOperations/SortOperation.php | 16 +++++++--------- .../Behavior/Features/Fusion/FlowQuery.feature | 3 +++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/SortOperation.php b/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/SortOperation.php index 38464a0ab02..c6ab31737ae 100644 --- a/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/SortOperation.php +++ b/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/SortOperation.php @@ -46,9 +46,7 @@ public function canEvaluate($context) } /** - * {@inheritdoc} - * - * First argument is the node property to sort by. Works with internal arguments (_xyz) as well. + * First argument is the node property to sort by. To sort by time _creationDateTime, _lastModificationDateTime or _lastPublicationDateTime can be used. * Second argument is the sort direction (ASC or DESC). * Third optional argument are the sort options (see https://www.php.net/manual/en/function.sort): * - 'SORT_REGULAR' @@ -113,12 +111,12 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) // Determine the property value to sort by foreach ($nodes as $node) { - $propertyValue = $node->getProperty($sortProperty); - - // todo how to sort by creation date in Neos 9?? Something like node.timestamps.originalCreated - if ($propertyValue instanceof \DateTime) { - $propertyValue = $propertyValue->getTimestamp(); - } + $propertyValue = match($sortProperty) { + '_creationDateTime' => $node->timestamps->created->getTimestamp(), + '_lastModificationDateTime' => $node->timestamps->lastModified?->getTimestamp(), + '_lastPublicationDateTime' => $node->timestamps->originalLastModified?->getTimestamp(), + default => $node->getProperty($sortProperty) + }; $sortSequence[$node->aggregateId->value] = $propertyValue; $nodesByIdentifier[$node->aggregateId->value] = $node; diff --git a/Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature b/Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature index 5be1c0baea3..75c316d6684 100644 --- a/Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature +++ b/Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature @@ -409,6 +409,8 @@ Feature: Tests for the "Neos.ContentRepository" Flow Query methods. unsorted = ${q([a1a3, a1a4, a1a1, a1a2]).get()} sortByTitleAsc = ${q([a1a3, a1a4, a1a1, a1a2]).sort("title", "ASC").get()} sortByUriDesc = ${q([a1a3, a1a4, a1a1, a1a2]).sort("uriPathSegment", "DESC").get()} + # todo find out how to test time related logic + sortByDateAsc = ${q([a1a1]).sort("_creationDateTime", "ASC").get()} @process.render = Neos.Neos:Test.RenderNodesDataStructure } """ @@ -417,6 +419,7 @@ Feature: Tests for the "Neos.ContentRepository" Flow Query methods. unsorted: a1a3,a1a4,a1a1,a1a2 sortByTitleAsc: a1a1,a1a2,a1a3,a1a4 sortByUriDesc: a1a4,a1a3,a1a2,a1a1 + sortByDateAsc: a1a1 """ Scenario: Node accessors (final Node access operations)