Skip to content

Commit 8539644

Browse files
committed
[BUGFIX] Fix sorting for translated content in free mode
1 parent 49d2cf5 commit 8539644

File tree

5 files changed

+84
-7
lines changed

5 files changed

+84
-7
lines changed

Classes/Command/SortingInPageCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SortingInPageCommand extends Command
3232
protected function configure()
3333
{
3434
$this->addArgument('pid', InputArgument::OPTIONAL, 'limit to this pid', 0);
35+
$this->addArgument('languageId', InputArgument::OPTIONAL, 'limit to this languageId', 0);
3536
$this->addOption('apply', null, InputOption::VALUE_NONE, 'apply migration');
3637
$this->addOption(
3738
'enable-logging',
@@ -51,13 +52,17 @@ public function execute(InputInterface $input, OutputInterface $output): int
5152
{
5253
$dryrun = $input->getOption('apply') !== true;
5354
$pid = (int)$input->getArgument('pid');
55+
if ($input->getArgument('languageId') !== 'all') {
56+
$languageId = (int)$input->getArgument('languageId');
57+
}
5458

5559
Bootstrap::initializeBackendAuthentication();
5660
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
5761
$errors = $this->sorting->run(
5862
$dryrun,
5963
$input->getOption('enable-logging'),
60-
$pid
64+
$pid,
65+
$languageId,
6166
);
6267
foreach ($errors as $error) {
6368
$output->writeln($error);

Classes/Integrity/Database.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function getChildrenByContainerAndColPos(int $containerId, int $colPos, i
106106
return $rows;
107107
}
108108

109-
public function getNonContainerChildrenPerColPos(array $containerUsedColPosArray, ?int $pid = null): array
109+
public function getNonContainerChildrenPerColPos(array $containerUsedColPosArray, ?int $pid = null, ?int $languageId = null): array
110110
{
111111
$queryBuilder = $this->getQueryBuilder();
112112
$stm = $queryBuilder
@@ -116,12 +116,18 @@ public function getNonContainerChildrenPerColPos(array $containerUsedColPosArray
116116
$queryBuilder->expr()->notIn(
117117
'colPos',
118118
$queryBuilder->createNamedParameter($containerUsedColPosArray, Connection::PARAM_INT_ARRAY)
119-
),
119+
)
120+
);
121+
122+
if (!is_null($languageId)) {
123+
$stm->andWhere(
120124
$queryBuilder->expr()->eq(
121125
'sys_language_uid',
122-
$queryBuilder->createNamedParameter(0, Connection::PARAM_INT)
126+
$queryBuilder->createNamedParameter($languageId, Connection::PARAM_INT)
123127
)
124128
);
129+
}
130+
125131
if (!empty($pid)) {
126132
$stm->andWhere(
127133
$queryBuilder->expr()->eq(
@@ -136,7 +142,7 @@ public function getNonContainerChildrenPerColPos(array $containerUsedColPosArray
136142
$results = $stm->executeQuery()->fetchAllAssociative();
137143
$rows = [];
138144
foreach ($results as $result) {
139-
$key = $result['pid'] . '-' . $result['colPos'];
145+
$key = $result['pid'] . '-' . $result['sys_language_uid'] . '-' . $result['colPos'];
140146
if (!isset($rows[$key])) {
141147
$rows[$key] = [];
142148
}

Classes/Integrity/SortingInPage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(Database $database, Registry $tcaRegistry, Container
5252
$this->containerService = $containerService;
5353
}
5454

55-
public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid = null): array
55+
public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid = null, ?int $languageId = null): array
5656
{
5757
$this->unsetContentDefenderConfiguration();
5858
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
@@ -65,7 +65,7 @@ public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid
6565
$containerUsedColPosArray[] = $column['colPos'];
6666
}
6767
}
68-
$rows = $this->database->getNonContainerChildrenPerColPos($containerUsedColPosArray, $pid);
68+
$rows = $this->database->getNonContainerChildrenPerColPos($containerUsedColPosArray, $pid, $languageId);
6969
foreach ($rows as $recordsPerPageAndColPos) {
7070
$prevSorting = 0;
7171
$prevContainer = null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"pages"
2+
,"uid","pid","sys_language_uid"
3+
,1,0,0
4+
,2,1,1
5+
,3,1,2
6+
"tt_content"
7+
,"uid","pid","colPos","CType","sorting","tx_container_parent","sys_language_uid"
8+
,1,2,0,"b13-2cols-with-header-container",1,,1
9+
,2,2,0,"b13-2cols-with-header-container",2,,1
10+
,3,2,202,,4,1,1
11+
,4,2,202,,3,2,1
12+
,5,3,0,"b13-2cols-with-header-container",5,,2
13+
,6,3,0,"b13-2cols-with-header-container",6,,2
14+
,7,3,202,,8,5,2
15+
,8,3,202,,7,6,2

Tests/Functional/Integrity/SortingInPageTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,57 @@ public function containerIsSortedAfterChildOfPreviousContainer(): void
6565
self::assertTrue($rows[2]['sorting'] > $rows[3]['sorting'], 'container should be sorted after child of previous container');
6666
}
6767

68+
public static function getPossibleTranslations(): iterable
69+
{
70+
yield 'with language id 1' => [
71+
'languageId' => 1,
72+
'expected' => [
73+
'errors' => 1,
74+
'sortings' => [
75+
2 => 3,
76+
]
77+
]
78+
];
79+
yield 'with language id 2' => [
80+
'languageId' => 2,
81+
'expected' => [
82+
'errors' => 1,
83+
'sortings' => [
84+
6 => 7,
85+
]
86+
]
87+
];
88+
yield 'with all languages' => [
89+
'languageId' => null,
90+
'expected' => [
91+
'errors' => 2,
92+
'sortings' => [
93+
2 => 3,
94+
6 => 7,
95+
]
96+
]
97+
];
98+
}
99+
100+
/**
101+
* @test
102+
* @dataProvider getPossibleTranslations
103+
*/
104+
public function containerIsSortedAfterChildOfPreviousContainerOnTranslatedPage(?int $languageId = null, array $expected): void
105+
{
106+
$this->importCSVDataSet(__DIR__ . '/Fixtures/SortingInPage/container_is_sorted_before_child_of_previous_container_on_translated_page.csv');
107+
$errors = $this->sorting->run(false, false, null, 0);
108+
self::assertTrue(count($errors) === 0, 'different number of errors for default language');
109+
110+
$errors = $this->sorting->run(false, false, null, $languageId);
111+
self::assertTrue(count($errors) === $expected['errors'], 'different number of errors for given language');
112+
113+
$rows = $this->getContentsByUid();
114+
foreach ($expected['sortings'] as $before => $after) {
115+
self::assertTrue($rows[$before]['sorting'] > $rows[$after]['sorting'], 'container should be sorted after child of previous container');
116+
}
117+
}
118+
68119
/**
69120
* @test
70121
*/

0 commit comments

Comments
 (0)