Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Mitigate unrelated page traversal for glossary lookup #335

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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
5 changes: 5 additions & 0 deletions Build/phpstan/Core11/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ parameters:
count: 1
path: ../../../Classes/Utility/HtmlUtility.php

-
message: "#^Parameter \\#2 \\$length of function fread expects int\\<1, max\\>, int\\<0, max\\> given\\.$#"
count: 1
path: ../../../Tests/Functional/AbstractDeepLTestCase.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Fixtures\\\\Frontend\\\\PhpError\\:\\:__construct\\(\\) has parameter \\$configuration with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
5 changes: 5 additions & 0 deletions Build/phpstan/Core12/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ parameters:
count: 1
path: ../../../Classes/Utility/HtmlUtility.php

-
message: "#^Parameter \\#2 \\$length of function fread expects int\\<1, max\\>, int\\<0, max\\> given\\.$#"
count: 1
path: ../../../Tests/Functional/AbstractDeepLTestCase.php

-
message: "#^Method WebVision\\\\WvDeepltranslate\\\\Tests\\\\Functional\\\\Fixtures\\\\Frontend\\\\PhpError\\:\\:__construct\\(\\) has parameter \\$configuration with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
40 changes: 28 additions & 12 deletions Classes/Domain/Repository/GlossaryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\SiteFinder;
Expand Down Expand Up @@ -470,33 +471,48 @@ private function getGlossary(
*/
private function getGlossariesInRootByCurrentPage(int $pageId): array
{
$site = GeneralUtility::makeInstance(SiteFinder::class)
->getSiteByPageId($pageId);
$rootPage = $site->getRootPageId();
$allPages = GeneralUtility::makeInstance(PageTreeRepository::class)
->getTreeList($rootPage, 999);
$db = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages');
$statement = $db

$result = $db
->select('uid')
->from('pages')
->where(
$db->expr()->in('uid', $allPages),
$db->expr()->eq('doktype', $db->createNamedParameter(254, Connection::PARAM_INT)),
$db->expr()->eq(
'doktype',
$db->createNamedParameter(
PageRepository::DOKTYPE_SYSFOLDER,
Connection::PARAM_INT
)
),
$db->expr()->eq('module', $db->createNamedParameter('glossary'))
);
$result = $statement->executeQuery()->fetchAllAssociative();
)->executeQuery();

if (!is_array($result)) {
$rows = $result->fetchAllAssociative();
if (count($rows) === 0) {
return [];
}

$rootPage = $this->findRootPageId($pageId);

$ids = [];
foreach ($result as $row) {
foreach ($rows as $row) {
$glossaryRootPageID = $this->findRootPageId($row['uid']);
if ($glossaryRootPageID !== $rootPage) {
continue;
}

$ids[] = $row['uid'];
}
return $ids;
}

private function findRootPageId(int $pageId): int
{
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageId);
return $site->getRootPageId();
}

public function setGlossaryNotSyncOnPage(int $pageId): void
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
Expand Down