Commit 62ada6fa authored by Benjamin Franzke's avatar Benjamin Franzke Committed by Andreas Fernandez
Browse files

[BUGFIX] Avoid duplicate pages in pagetree when rootPid is mounted

With the changes in #95854, implicit rootPid dbmounts caused
duplicated pages in pagetree, because explicit page mounts have
been considered multiple times for the pid=0 tree:

 * First time because of their relationship to pid = 0
 * Second time because of their explicit mount
   (which was sorted into the pid = 0 tree)

This happened because #95854 optimized to only use one call
to the PageTree repository, which then had the side effect
of merging "multiple" pages into one tree, instead
of showing "two" separate trees.

The patch ensures that multiple page trees are used when
the rootPid (0) is included as a webmount.

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


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 75c21c6b
......@@ -519,18 +519,26 @@ class TreeController
$permClause
);
}
$rootRecord = [
'uid' => 0,
'title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ?: 'TYPO3',
];
$entryPointRecords = [];
$mountPoints = [];
if ($entryPointIds === null) {
$rootRecord = [
'uid' => 0,
'title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ?: 'TYPO3',
];
//watch out for deleted pages returned as webmount
$mountPoints = array_map('intval', $backendUser->returnWebmounts());
$mountPoints = array_unique($mountPoints);
$mountPoints = array_filter($mountPoints, fn ($id) => !in_array($id, $this->hiddenRecords, true));
// Switch to multiple-entryPoint-mode if the rootPage is to be mounted.
// (other mounts would appear duplicated in the pid = 0 tree otherwise)
if (in_array(0, $mountPoints, true)) {
$entryPointIds = $mountPoints;
}
}
if ($entryPointIds === null) {
if ($query !== '') {
$rootRecord = $repository->getTree(0, null, $mountPoints, true);
} else {
......@@ -541,13 +549,17 @@ class TreeController
$entryPointIds = array_filter($entryPointIds, fn ($id) => !in_array($id, $this->hiddenRecords, true));
$this->calculateBackgroundColors($entryPointIds);
foreach ($entryPointIds as $k => $entryPointId) {
$entryPointRecord = BackendUtility::getRecordWSOL('pages', $entryPointId, '*', $permClause);
if ($entryPointId === 0) {
$entryPointRecord = $rootRecord;
} else {
$entryPointRecord = BackendUtility::getRecordWSOL('pages', $entryPointId, '*', $permClause);
if ($entryPointRecord !== null && !$backendUser->isInWebMount($entryPointId)) {
$entryPointRecord = null;
}
if ($entryPointRecord === null) {
continue;
if ($entryPointRecord !== null && !$backendUser->isInWebMount($entryPointId)) {
$entryPointRecord = null;
}
if ($entryPointRecord === null) {
continue;
}
}
$entryPointRecord['uid'] = (int)$entryPointRecord['uid'];
......
......@@ -214,6 +214,120 @@ class TreeControllerTest extends FunctionalTestCase
self::assertEquals($expected, $actual);
}
/**
* @test
*/
public function getAllEntryPointPageTreesWithRootPageAsMountPoint(): void
{
$this->backendUser->setWebMounts([0, 7000]);
$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' => 1000,
'title' => 'ACME Inc',
'_children' => [
[
'uid' => 1100,
'title' => 'EN: Welcome',
'_children' => [
],
],
[
'uid' => 1200,
'title' => 'EN: Features',
'_children' => [
],
],
[
'uid' => 1400,
'title' => 'EN: ACME in your Region',
'_children' => [
],
],
[
'uid' => 1500,
'title' => 'Internal',
'_children' => [
],
],
[
'uid' => 1700,
'title' => 'Announcements & News',
'_children' => [
],
],
[
'uid' => 404,
'title' => 'Page not found',
'_children' => [
],
],
[
'uid' => 1930,
'title' => 'Our Blog',
'_children' => [
],
],
[
'uid' => 1990,
'title' => 'Storage',
'_children' => [
],
],
],
],
[
'uid' => 7000,
'title' => 'Common Collection',
'_children' => [
[
'uid' => 7100,
'title' => 'Announcements & News',
'_children' => [],
],
],
],
],
],
[
'uid' => 7000,
'title' => 'Common Collection',
'_children' => [
[
'uid' => 7100,
'title' => 'Announcements & News',
'_children' => [
[
'uid' => 7110,
'title' => 'Markets',
'_children' => [],
],
[
'uid' => 7120,
'title' => 'Products',
'_children' => [],
],
[
'uid' => 7130,
'title' => 'Partners',
'_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