Skip to content

Commit

Permalink
[TASK] Fix SiteProvider fetch methods (#757)
Browse files Browse the repository at this point in the history
* [TASK] Fix SiteProvider fetch methods

- there was an error in line 99 before this change about illegal array offset because fetches returned empty array instead of results

* [TASK] Replace \PDO::PARAM_INT with Connection::PARAM_INT
  • Loading branch information
oskardydo authored Aug 14, 2024
1 parent c73c41e commit a2bd9a5
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions Classes/DataProcessing/RootSiteProcessing/SiteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace FriendsOfTYPO3\Headless\DataProcessing\RootSiteProcessing;

use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Result;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Site\Entity\Site;
Expand Down Expand Up @@ -149,7 +148,7 @@ private function filterSites(array $allowedSites = []): array

foreach ($allSites as $site) {
if (in_array($site->getRootPageId(), $allowedSites, true) &&
$site->getConfiguration()['headless'] ?? false) {
$site->getConfiguration()['headless'] ?? false) {
$sites[] = $site;
}
}
Expand All @@ -166,18 +165,15 @@ private function fetchAvailableRootSitesByPid(int $pid): array
{
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');

$stmt = $queryBuilder
$pagesData = $queryBuilder
->select('uid')
->from('pages')
->where('is_siteroot = 1')
->andWhere('hidden = 0')
->andWhere('deleted = 0')->andWhere('pid = ' . $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT))->executeQuery();

$pagesData = [];

if ($stmt instanceof Result) {
$pagesData = $stmt->fetchAllAssociative();
}
->andWhere(
$queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, Connection::PARAM_INT)),
)
->executeQuery()
->fetchAllAssociative();

return array_map(static function (array $item): int {
return (int)$item['uid'];
Expand Down Expand Up @@ -206,14 +202,17 @@ private function fetchPageData(array $sites, array $config = []): array

$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');

$pagesData = [];
$stmt = $queryBuilder
$pagesData = $queryBuilder
->select(...$columns)
->from('pages')->where('uid IN (' . $queryBuilder->createNamedParameter($rootPagesId, Connection::PARAM_INT_ARRAY) . ')')->executeQuery();

if ($stmt instanceof Result) {
$pagesData = $stmt->fetchAllAssociative();
}
->from('pages')
->where(
$queryBuilder->expr()->in(
'uid',
$queryBuilder->createNamedParameter($rootPagesId, Connection::PARAM_INT_ARRAY)
)
)
->executeQuery()
->fetchAllAssociative();

$pages = [];

Expand Down

0 comments on commit a2bd9a5

Please sign in to comment.