Commit 0b25b007 authored by Benjamin Franzke's avatar Benjamin Franzke
Browse files

[BUGFIX] Fix ordering of db mounts in page tree

With the changes in #95854, database mounts
are no longer sorted by the order they are defined in
the group/user settings, but undefined by the
order the database returns.

DB mounts aren't sorted against each other,
that means sorting values are not meaningful anyway,
and results in uncontrolable orderings.

Explicitly preserve the order using usort().
Also revert groupAndSortPages() to the state prior
to #95854, as the forcePid parameter would now be unused.

Releases: main, 11.5, 10.4
Resolves: #96359
Related: #95854
Change-Id: I64b8d90c68246cc0ac01abcbf3678aa1055189e3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72813


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
parent 70dcd9ff
......@@ -544,6 +544,14 @@ class TreeController
} else {
$rootRecord = $repository->getTreeLevels($rootRecord, $this->levelsToFetch, $mountPoints);
}
$mountPointOrdering = array_flip($mountPoints);
if (isset($rootRecord['_children'])) {
usort($rootRecord['_children'], static function ($a, $b) use ($mountPointOrdering) {
return ($mountPointOrdering[$a['uid']] ?? 0) <=> ($mountPointOrdering[$b['uid']] ?? 0);
});
}
$entryPointRecords[] = $rootRecord;
} else {
$entryPointIds = array_filter($entryPointIds, fn ($id) => !in_array($id, $this->hiddenRecords, true));
......
......@@ -177,7 +177,7 @@ class PageTreeRepository
if (count($entryPointIds) > 0) {
$pageRecords = $this->getPageRecords($entryPointIds);
$groupedAndSortedPagesByPid = $this->groupAndSortPages($pageRecords, $groupedAndSortedPagesByPid, 0);
$groupedAndSortedPagesByPid[$pageTree['uid']] = $pageRecords;
$parentPageIds = $entryPointIds;
} else {
$parentPageIds = [$pageTree['uid']];
......@@ -713,16 +713,12 @@ class PageTreeRepository
*
* @param array $pages
* @param array $groupedAndSortedPagesByPid
* @param int|null $forcePid
* @return array
*/
protected function groupAndSortPages(array $pages, $groupedAndSortedPagesByPid = [], ?int $forcePid = null): array
protected function groupAndSortPages(array $pages, $groupedAndSortedPagesByPid = []): array
{
foreach ($pages as $key => $pageRecord) {
$parentPageId = (int)$pageRecord['pid'];
if ($forcePid !== null) {
$parentPageId = $forcePid;
}
$sorting = (int)$pageRecord['sorting'];
while (isset($groupedAndSortedPagesByPid[$parentPageId][$sorting])) {
$sorting++;
......
......@@ -434,6 +434,40 @@ class TreeControllerTest extends FunctionalTestCase
self::assertEquals($expected, $actual);
}
/**
* @test
*/
public function getAllEntryPointPageTreesWithMountPointPreservesOrdering(): void
{
$this->backendUser->setWebmounts([1210, 1100]);
$actual = $this->subject->_call('getAllEntryPointPageTrees');
$keepProperties = array_flip(['uid', 'title', '_children']);
$actual = $this->sortTreeArray($actual);
$actual = $this->normalizeTreeArray($actual, $keepProperties);
$expected = [
[
'uid' => 0,
'title' => 'New TYPO3 site',
'_children' =>[
[
'uid' => 1210,
'title' => 'EN: Frontend Editing',
'_children' => [
],
],
[
'uid' => 1100,
'title' => 'EN: Welcome',
'_children' => [
],
],
],
],
];
self::assertEquals($expected, $actual);
}
/**
* @test
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment