Skip to content

Commit

Permalink
[BUGFIX] Fix sorting for translated content in free mode
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-codappix committed Aug 27, 2024
1 parent 49d2cf5 commit 8539644
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 7 deletions.
7 changes: 6 additions & 1 deletion Classes/Command/SortingInPageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SortingInPageCommand extends Command
protected function configure()
{
$this->addArgument('pid', InputArgument::OPTIONAL, 'limit to this pid', 0);
$this->addArgument('languageId', InputArgument::OPTIONAL, 'limit to this languageId', 0);
$this->addOption('apply', null, InputOption::VALUE_NONE, 'apply migration');
$this->addOption(
'enable-logging',
Expand All @@ -51,13 +52,17 @@ public function execute(InputInterface $input, OutputInterface $output): int
{
$dryrun = $input->getOption('apply') !== true;
$pid = (int)$input->getArgument('pid');
if ($input->getArgument('languageId') !== 'all') {
$languageId = (int)$input->getArgument('languageId');
}

Bootstrap::initializeBackendAuthentication();
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
$errors = $this->sorting->run(
$dryrun,
$input->getOption('enable-logging'),
$pid
$pid,
$languageId,
);
foreach ($errors as $error) {
$output->writeln($error);
Expand Down
14 changes: 10 additions & 4 deletions Classes/Integrity/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getChildrenByContainerAndColPos(int $containerId, int $colPos, i
return $rows;
}

public function getNonContainerChildrenPerColPos(array $containerUsedColPosArray, ?int $pid = null): array
public function getNonContainerChildrenPerColPos(array $containerUsedColPosArray, ?int $pid = null, ?int $languageId = null): array
{
$queryBuilder = $this->getQueryBuilder();
$stm = $queryBuilder
Expand All @@ -116,12 +116,18 @@ public function getNonContainerChildrenPerColPos(array $containerUsedColPosArray
$queryBuilder->expr()->notIn(
'colPos',
$queryBuilder->createNamedParameter($containerUsedColPosArray, Connection::PARAM_INT_ARRAY)
),
)
);

if (!is_null($languageId)) {
$stm->andWhere(
$queryBuilder->expr()->eq(
'sys_language_uid',
$queryBuilder->createNamedParameter(0, Connection::PARAM_INT)
$queryBuilder->createNamedParameter($languageId, Connection::PARAM_INT)
)
);
}

if (!empty($pid)) {
$stm->andWhere(
$queryBuilder->expr()->eq(
Expand All @@ -136,7 +142,7 @@ public function getNonContainerChildrenPerColPos(array $containerUsedColPosArray
$results = $stm->executeQuery()->fetchAllAssociative();
$rows = [];
foreach ($results as $result) {
$key = $result['pid'] . '-' . $result['colPos'];
$key = $result['pid'] . '-' . $result['sys_language_uid'] . '-' . $result['colPos'];
if (!isset($rows[$key])) {
$rows[$key] = [];
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Integrity/SortingInPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(Database $database, Registry $tcaRegistry, Container
$this->containerService = $containerService;
}

public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid = null): array
public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid = null, ?int $languageId = null): array
{
$this->unsetContentDefenderConfiguration();
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
Expand All @@ -65,7 +65,7 @@ public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid
$containerUsedColPosArray[] = $column['colPos'];
}
}
$rows = $this->database->getNonContainerChildrenPerColPos($containerUsedColPosArray, $pid);
$rows = $this->database->getNonContainerChildrenPerColPos($containerUsedColPosArray, $pid, $languageId);
foreach ($rows as $recordsPerPageAndColPos) {
$prevSorting = 0;
$prevContainer = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"pages"
,"uid","pid","sys_language_uid"
,1,0,0
,2,1,1
,3,1,2
"tt_content"
,"uid","pid","colPos","CType","sorting","tx_container_parent","sys_language_uid"
,1,2,0,"b13-2cols-with-header-container",1,,1
,2,2,0,"b13-2cols-with-header-container",2,,1
,3,2,202,,4,1,1
,4,2,202,,3,2,1
,5,3,0,"b13-2cols-with-header-container",5,,2
,6,3,0,"b13-2cols-with-header-container",6,,2
,7,3,202,,8,5,2
,8,3,202,,7,6,2
51 changes: 51 additions & 0 deletions Tests/Functional/Integrity/SortingInPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,57 @@ public function containerIsSortedAfterChildOfPreviousContainer(): void
self::assertTrue($rows[2]['sorting'] > $rows[3]['sorting'], 'container should be sorted after child of previous container');
}

public static function getPossibleTranslations(): iterable
{
yield 'with language id 1' => [
'languageId' => 1,
'expected' => [
'errors' => 1,
'sortings' => [
2 => 3,
]
]
];
yield 'with language id 2' => [
'languageId' => 2,
'expected' => [
'errors' => 1,
'sortings' => [
6 => 7,
]
]
];
yield 'with all languages' => [
'languageId' => null,
'expected' => [
'errors' => 2,
'sortings' => [
2 => 3,
6 => 7,
]
]
];
}

/**
* @test
* @dataProvider getPossibleTranslations
*/
public function containerIsSortedAfterChildOfPreviousContainerOnTranslatedPage(?int $languageId = null, array $expected): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/SortingInPage/container_is_sorted_before_child_of_previous_container_on_translated_page.csv');
$errors = $this->sorting->run(false, false, null, 0);
self::assertTrue(count($errors) === 0, 'different number of errors for default language');

$errors = $this->sorting->run(false, false, null, $languageId);
self::assertTrue(count($errors) === $expected['errors'], 'different number of errors for given language');

$rows = $this->getContentsByUid();
foreach ($expected['sortings'] as $before => $after) {
self::assertTrue($rows[$before]['sorting'] > $rows[$after]['sorting'], 'container should be sorted after child of previous container');
}
}

/**
* @test
*/
Expand Down

0 comments on commit 8539644

Please sign in to comment.