Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Classes/System/Records/SystemTemplate/SystemTemplateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,29 @@ class SystemTemplateRepository extends AbstractRepository
*/
public function findOneClosestPageIdWithActiveTemplateByRootLine(array $rootLine): ?int
{
$rootLinePageIds = [0];
// rootline always is given in reverse order, so iterate over, as it will go to top of rootline
// from the current called pid
foreach ($rootLine as $rootLineItem) {
$rootLinePageIds[] = (int)$rootLineItem['uid'];
$foundPage = $this->getTemplateIdForGivenPageId($rootLineItem['uid']);
if ($foundPage !== null) {
return $foundPage;
}
}
return null;
}

/**
* @throws DBALException
*/
private function getTemplateIdForGivenPageId(int $pageId): ?int
{
$queryBuilder = $this->getQueryBuilder();

$result = $queryBuilder
->select('uid', 'pid')
->from($this->table)
->where(
$queryBuilder->expr()->in('pid', $rootLinePageIds),
$queryBuilder->expr()->eq('pid', $pageId)
)
->executeQuery()
->fetchAssociative();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"pages"
,"uid","pid","doktype","title"
,1,0,1,"EXT:solr Test"
,100,1,1,""
,33,100,1,"Page with sys_template",
,8657,33,1,"Entry Point for rootline"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"sys_template",
,"uid","pid","root","sorting","config"
,2,100,1,128,"page = PAGE"
,777,33,1,100,"page = PAGE"
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@
*/
class SystemTemplateRepositoryTest extends IntegrationTestBase
{
#[Test]
public function canFindOneClosestPageIdWithActiveTemplateByRootLine(): void
protected function setUp(): void
{
parent::setUp();
$this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/sys_template.csv');
}

#[Test]
public function canFindOneClosestPageIdWithActiveTemplateByRootLine(): void
{
$fakeRootLine = [
['uid' => 100],
['uid' => 33],
['uid' => 8657],
4 => ['uid' => 1],
3 => ['uid' => 100],
2 => ['uid' => 33],
1 => ['uid' => 8657],
];

/** @var SystemTemplateRepository $repository */
Expand Down
Loading