Skip to content

Commit

Permalink
[TASK] Replace QueryGenerator
Browse files Browse the repository at this point in the history
The use of the QueryGenerator was replaced with the TYPO3 page repository.

Resolves: #3453
  • Loading branch information
3l73 committed Jan 16, 2023
1 parent 379ca70 commit 4cb8a82
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
18 changes: 7 additions & 11 deletions Classes/Domain/Index/Queue/UpdateHandler/AbstractUpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\QueryGenerator;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -173,8 +173,12 @@ protected function getSubPageIds(int $pageId): array
// here we retrieve only the subpages of this page because the permission clause is not evaluated
// on the root node.
$permissionClause = ' 1 ' . $this->getPagesRepository()->getBackendEnableFields();
$treePageIdList = (string)$this->getQueryGenerator()->getTreeList($pageId, 20, 0, $permissionClause);
$treePageIds = array_map('intval', explode(',', $treePageIdList));
$pageRepository = GeneralUtility::makeInstance(PageRepository::class);
$treePageIds = $pageRepository->getDescendantPageIdsRecursive(
$pageId,
20,
0
);

// the first one can be ignored because this is the page itself
array_shift($treePageIds);
Expand Down Expand Up @@ -302,14 +306,6 @@ protected function getUpdateSubPagesRecursiveTriggerConfiguration(): array
return $this->updateSubPagesRecursiveTriggerConfiguration;
}

/**
* @return QueryGenerator
*/
protected function getQueryGenerator(): QueryGenerator
{
return GeneralUtility::makeInstance(QueryGenerator::class);
}

/**
* @return PagesRepository
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use ApacheSolrForTypo3\Solr\System\TCA\TCAService;
use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Core\Database\QueryGenerator;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -63,6 +63,11 @@ abstract class AbstractUpdateHandlerTest extends UnitTest
*/
protected $queryGeneratorMock;

/**
* @var PageRepository|MockObject
*/
protected PageRepository|MockObject $typo3PageRepositoryMock;

/**
* @var PagesRepository|MockObject
*/
Expand All @@ -82,9 +87,9 @@ protected function setUp(): void
->method('getSolrConfigurationFromPageId')
->willReturn($this->typoScriptConfigurationMock);

$this->queryGeneratorMock = $this->createMock(QueryGenerator::class);
$this->typo3PageRepositoryMock = $this->createMock(PageRepository::class);

GeneralUtility::addInstance(QueryGenerator::class, $this->queryGeneratorMock);
GeneralUtility::addInstance(PageRepository::class, $this->typo3PageRepositoryMock);
parent::setUp();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ public function handlePageUpdateTriggersRecursivePageProcessing(): void

$GLOBALS['TCA']['pages'] = ['columns' => []];

$this->queryGeneratorMock
$this->typo3PageRepositoryMock
->expects(self::any())
->method('getTreeList')
->method('getDescendantPageIdsRecursive')
->willReturn($dummyPageRecord['uid'] . ',100,200');

$this->pagesRepositoryMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ public function performRecordGarbageCheckTriggersPageGarbageCollection(): void
->with('pages', $dummyPageRecord)
->willReturn($dummyPageRecord);

$this->queryGeneratorMock
$this->typo3PageRepositoryMock
->expects(self::any())
->method('getTreeList')
->method('getDescendantPageIdsRecursive')
->willReturn($dummyPageRecord['uid'] . ',100,200');

$this->garbageHandler->performRecordGarbageCheck($dummyPageRecord['uid'], 'pages', ['hidden' => 1], true);
Expand Down

0 comments on commit 4cb8a82

Please sign in to comment.