From 1132599567a3d9f050a10d2156895b12446036fc Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 25 Jun 2024 10:26:13 +0200 Subject: [PATCH] [BUGFIX] Fix integrity sorting in page with nested containers Relates: #458 --- Classes/Domain/Service/ContainerService.php | 18 +++++++++++++----- Classes/Integrity/SortingInPage.php | 2 +- ...er_with_nested_changed_children_sorting.csv | 10 ++++++++++ .../Functional/Integrity/SortingInPageTest.php | 13 +++++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 Tests/Functional/Integrity/Fixtures/SortingInPage/container_is_sorted_before_child_of_previous_container_with_nested_changed_children_sorting.csv diff --git a/Classes/Domain/Service/ContainerService.php b/Classes/Domain/Service/ContainerService.php index 58687908..1256cb34 100644 --- a/Classes/Domain/Service/ContainerService.php +++ b/Classes/Domain/Service/ContainerService.php @@ -53,18 +53,26 @@ public function getNewContentElementAtTopTargetInColumn(Container $container, in return $target; } - public function getAfterContainerElementTarget(Container $container): int + public function getAfterContainerRecord(Container $container): array { - $target = -$container->getUid(); $childRecords = $container->getChildRecords(); if (empty($childRecords)) { - return $target; + return $container->getContainerRecord(); } + $lastChild = array_pop($childRecords); if (!$this->tcaRegistry->isContainerElement($lastChild['CType'])) { - return -(int)$lastChild['uid']; + return $lastChild; } + $container = $this->containerFactory->buildContainer((int)$lastChild['uid']); - return $this->getAfterContainerElementTarget($container); + return $this->getAfterContainerRecord($container); + } + + public function getAfterContainerElementTarget(Container $container): int + { + $target = $this->getAfterContainerRecord($container); + + return -$target['uid']; } } diff --git a/Classes/Integrity/SortingInPage.php b/Classes/Integrity/SortingInPage.php index 39f48868..18520073 100644 --- a/Classes/Integrity/SortingInPage.php +++ b/Classes/Integrity/SortingInPage.php @@ -77,7 +77,7 @@ public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid if (empty($children)) { $sorting = $record['sorting']; } else { - $lastChild = array_pop($children); + $lastChild = $this->containerService->getAfterContainerRecord($container); $sorting = $lastChild['sorting']; if ($prevChild === null || $prevContainer === null) { diff --git a/Tests/Functional/Integrity/Fixtures/SortingInPage/container_is_sorted_before_child_of_previous_container_with_nested_changed_children_sorting.csv b/Tests/Functional/Integrity/Fixtures/SortingInPage/container_is_sorted_before_child_of_previous_container_with_nested_changed_children_sorting.csv new file mode 100644 index 00000000..7e11d2aa --- /dev/null +++ b/Tests/Functional/Integrity/Fixtures/SortingInPage/container_is_sorted_before_child_of_previous_container_with_nested_changed_children_sorting.csv @@ -0,0 +1,10 @@ +"pages" +,"uid","pid" +,1,0 +"tt_content" +,"uid","pid","colPos","CType","sorting","tx_container_parent" +,1,1,0,b13-2cols-with-header-container,1, +,2,1,0,b13-2cols-with-header-container,2,1 +,3,1,202,,5,2 +,4,1,0,"b13-2cols-with-header-container",3, +,5,1,202,,4,3 diff --git a/Tests/Functional/Integrity/SortingInPageTest.php b/Tests/Functional/Integrity/SortingInPageTest.php index 406f22a9..b7cee097 100644 --- a/Tests/Functional/Integrity/SortingInPageTest.php +++ b/Tests/Functional/Integrity/SortingInPageTest.php @@ -77,6 +77,19 @@ public function containerIsSortedAfterChildOfPreviousContainerWithChangedChildre self::assertTrue($rows[2]['sorting'] > $rows[3]['sorting'], 'container should be sorted after child of previous container'); } + /** + * @test + */ + public function containerIsSortedAfterChildOfPreviousContainerWithNestedChangedChildrenSorting(): void + { + $this->importCSVDataSet(__DIR__ . '/Fixtures/SortingInPage/container_is_sorted_before_child_of_previous_container_with_nested_changed_children_sorting.csv'); + $errors = $this->sorting->run(false); + self::assertTrue(count($errors) === 1, 'should get one error'); + $rows = $this->getContentsByUid(); + self::assertTrue($rows[2]['sorting'] > $rows[5]['sorting'], 'container should be sorted after last nested child of previous container'); + self::assertTrue($rows[3]['sorting'] > $rows[2]['sorting'], 'child should be sorted after its own parent container after resorting'); + } + /** * @test */