Skip to content

Commit 2d01f43

Browse files
committed
[BUGFIX] Ensure rootline order is respected detecting closest template
When detecting the closest template inside a rootline, it is necessary, respecting the order of the rootline itself. The current database call has a random sorting, which does not respect the ordering, therefore, could return a wrong dataset if multiple templates are given in the root line. To ensure the order is respected, every page inside rootline is called single against the database and returns the pid if a template record exists.
1 parent 7deb9ea commit 2d01f43

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

Classes/System/Records/SystemTemplate/SystemTemplateRepository.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,29 @@ class SystemTemplateRepository extends AbstractRepository
3535
*/
3636
public function findOneClosestPageIdWithActiveTemplateByRootLine(array $rootLine): ?int
3737
{
38-
$rootLinePageIds = [0];
38+
// rootline always is given in reverse order, so iterate over, as it will go to top of rootline
39+
// from the current called pid
3940
foreach ($rootLine as $rootLineItem) {
40-
$rootLinePageIds[] = (int)$rootLineItem['uid'];
41+
$foundPage = $this->getTemplateIdForGivenPageId($rootLineItem['uid']);
42+
if ($foundPage !== null) {
43+
return $foundPage;
44+
}
4145
}
46+
return null;
47+
}
4248

49+
/**
50+
* @throws DBALException
51+
*/
52+
private function getTemplateIdForGivenPageId(int $pageId): ?int
53+
{
4354
$queryBuilder = $this->getQueryBuilder();
4455

4556
$result = $queryBuilder
4657
->select('uid', 'pid')
4758
->from($this->table)
4859
->where(
49-
$queryBuilder->expr()->in('pid', $rootLinePageIds),
60+
$queryBuilder->expr()->eq('pid', $pageId)
5061
)
5162
->executeQuery()
5263
->fetchAssociative();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"pages"
2+
,"uid","pid","doktype","title"
3+
,1,0,1,"EXT:solr Test"
4+
,100,1,1,""
5+
,33,100,1,"Page with sys_template",
6+
,8657,33,1,"Entry Point for rootline"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
"sys_template",
22
,"uid","pid","root","sorting","config"
3+
,2,100,1,128,"page = PAGE"
34
,777,33,1,100,"page = PAGE"

Tests/Integration/System/Records/SystemTemplate/SystemTemplateRepositoryTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@
2525
*/
2626
class SystemTemplateRepositoryTest extends IntegrationTestBase
2727
{
28-
#[Test]
29-
public function canFindOneClosestPageIdWithActiveTemplateByRootLine(): void
28+
protected function setUp(): void
3029
{
30+
parent::setUp();
31+
$this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv');
3132
$this->importCSVDataSet(__DIR__ . '/Fixtures/sys_template.csv');
33+
}
3234

35+
#[Test]
36+
public function canFindOneClosestPageIdWithActiveTemplateByRootLine(): void
37+
{
3338
$fakeRootLine = [
34-
['uid' => 100],
35-
['uid' => 33],
36-
['uid' => 8657],
39+
4 => ['uid' => 1],
40+
3 => ['uid' => 100],
41+
2 => ['uid' => 33],
42+
1 => ['uid' => 8657],
3743
];
3844

3945
/** @var SystemTemplateRepository $repository */

0 commit comments

Comments
 (0)