Skip to content

Commit

Permalink
[BUGFIX] Migrate usages of the PDO param type constants (#2318)
Browse files Browse the repository at this point in the history
In TYPO3 code, the TYPO3 `Connection` constants should be used instead.
  • Loading branch information
oliverklee authored Jan 16, 2024
1 parent 58e648c commit 57007e4
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 65 deletions.
5 changes: 3 additions & 2 deletions Classes/Backend/RecordList/RecordListConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use GeorgRinger\News\Service\CategoryService;
use GeorgRinger\News\Utility\ConstraintHelper;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
Expand Down Expand Up @@ -245,9 +246,9 @@ protected function getNewsIdsOfCategory($categoryId): array
$queryBuilder->expr()->eq('sys_category.uid', $queryBuilder->quoteIdentifier('sys_category_record_mm.uid_local'))
)
->where(
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', \PDO::PARAM_STR)),
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', Connection::PARAM_STR)),
$queryBuilder->expr()->isNotNull('tx_news_domain_model_news.uid'),
$queryBuilder->expr()->eq('sys_category.uid', $queryBuilder->createNamedParameter($categoryId, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('sys_category.uid', $queryBuilder->createNamedParameter($categoryId, Connection::PARAM_INT))
)
->executeQuery();

Expand Down
3 changes: 2 additions & 1 deletion Classes/DataProcessing/AddNewsToMenuProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -99,7 +100,7 @@ protected function getNewsRecord(): array
->select('*')
->from('tx_news_domain_model_news')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, Connection::PARAM_INT))
)
->executeQuery()->fetchAssociative();

Expand Down
3 changes: 2 additions & 1 deletion Classes/Database/QueryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace GeorgRinger\News\Database;

use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function getTreeList($id, $depth, $begin = 0): string
$queryBuilder->select('uid')
->from('pages')
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($id, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', 0)
)
->orderBy('uid');
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Repository/AdministrationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getTotalCounts(): array
->from('sys_category_record_mm')
->where($queryBuilder->expr()->like(
'tablenames',
$queryBuilder->createNamedParameter('tx_news_domain_model_news', \PDO::PARAM_STR)
$queryBuilder->createNamedParameter('tx_news_domain_model_news', Connection::PARAM_STR)
))
->executeQuery()->fetchOne();

Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Repository/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

namespace GeorgRinger\News\Domain\Repository;

use Doctrine\DBAL\Connection;
use GeorgRinger\News\Domain\Model\Category;
use GeorgRinger\News\Domain\Model\DemandInterface;
use GeorgRinger\News\Service\CategoryService;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -202,7 +202,7 @@ protected function overlayTranslatedCategoryIds(array &$idList): void
->select('l10n_parent', 'uid', 'sys_language_uid')
->from('sys_category')
->where(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($language, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($language, Connection::PARAM_INT)),
$queryBuilder->expr()->in('l10n_parent', $queryBuilder->createNamedParameter($idList, Connection::PARAM_INT_ARRAY))
)
->executeQuery()->fetchAllAssociative();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\Event\ModifyDatabaseQueryForContentEvent;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
Expand Down Expand Up @@ -42,7 +43,7 @@ public function modify(ModifyDatabaseQueryForContentEvent $event): void
// Only hide elements which are inline, allowing for standard
// elements to show
$event->getQueryBuilder()->andWhere(
$event->getQueryBuilder()->expr()->eq('tx_news_related_news', $event->getQueryBuilder()->createNamedParameter(0, \PDO::PARAM_INT))
$event->getQueryBuilder()->expr()->eq('tx_news_related_news', $event->getQueryBuilder()->createNamedParameter(0, Connection::PARAM_INT))
);

if (self::$count === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\Event\ModifyDatabaseQueryForRecordListingEvent;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function modify(ModifyDatabaseQueryForRecordListingEvent $event): void
// Only hide elements which are inline, allowing for standard
// elements to show
$event->getQueryBuilder()->andWhere(
$event->getQueryBuilder()->expr()->eq('tx_news_related_news', $event->getQueryBuilder()->createNamedParameter(0, \PDO::PARAM_INT))
$event->getQueryBuilder()->expr()->eq('tx_news_related_news', $event->getQueryBuilder()->createNamedParameter(0, Connection::PARAM_INT))
);

if (self::$count === 0) {
Expand Down
3 changes: 2 additions & 1 deletion Classes/Hooks/Backend/PageViewQueryHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace GeorgRinger\News\Hooks\Backend;

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function modifyQuery(
// Only hide elements which are inline, allowing for standard
// elements to show
$queryBuilder->andWhere(
$queryBuilder->expr()->eq('tx_news_related_news', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('tx_news_related_news', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT))
);

if (self::$count === 0) {
Expand Down
21 changes: 11 additions & 10 deletions Classes/Seo/NewsAvailability.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace GeorgRinger\News\Seo;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
Expand Down Expand Up @@ -82,26 +83,26 @@ protected function getNewsRecord(int $newsId, int $language)
if ($language === 0) {
$where = [
$queryBuilder->expr()->or(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($language, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($language, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(-1, Connection::PARAM_INT))
),
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, Connection::PARAM_INT)),
];
} else {
$where = [
$queryBuilder->expr()->or(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(-1, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, Connection::PARAM_INT))
),
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($language, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($newsId, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($language, Connection::PARAM_INT))
),
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($language, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($language, Connection::PARAM_INT))
)
),
];
Expand Down
6 changes: 3 additions & 3 deletions Classes/Seo/NewsXmlSitemapDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ protected function getSinglePidFromCategory(int $newsId): int
$queryBuilder->expr()->eq('sys_category_record_mm.uid_local', $queryBuilder->quoteIdentifier('sys_category.uid'))
)
->where(
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', \PDO::PARAM_STR)),
$queryBuilder->expr()->gt('sys_category.single_pid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('sys_category_record_mm.uid_foreign', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', Connection::PARAM_STR)),
$queryBuilder->expr()->gt('sys_category.single_pid', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('sys_category_record_mm.uid_foreign', $queryBuilder->createNamedParameter($newsId, Connection::PARAM_INT))
)
->setMaxResults(1)
->executeQuery()->fetchAssociative();
Expand Down
13 changes: 7 additions & 6 deletions Classes/Service/AccessControlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace GeorgRinger\News\Service;

use GeorgRinger\News\Domain\Model\Dto\EmConfiguration;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
Expand Down Expand Up @@ -102,9 +103,9 @@ public static function getCategoriesForNewsRecord($newsRecord): array
$newsRecordCategoriesCount = $queryBuilder->count('*')
->from('sys_category_record_mm')
->where(
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($newsRecord['uid'], \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', \PDO::PARAM_STR)),
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('categories', \PDO::PARAM_STR))
$queryBuilder->expr()->eq('uid_foreign', $queryBuilder->createNamedParameter($newsRecord['uid'], Connection::PARAM_INT)),
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', Connection::PARAM_STR)),
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('categories', Connection::PARAM_STR))
)
->executeQuery()->fetchOne();
if ($newsRecordCategoriesCount > 0) {
Expand Down Expand Up @@ -141,9 +142,9 @@ public static function getCategoriesForNewsRecord($newsRecord): array
$queryBuilder->expr()->eq('sys_category_record_mm.uid_local', $queryBuilder->quoteIdentifier('sys_category.uid'))
)
->where(
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', \PDO::PARAM_STR)),
$queryBuilder->expr()->eq('sys_category_record_mm.fieldname', $queryBuilder->createNamedParameter('categories', \PDO::PARAM_STR)),
$queryBuilder->expr()->eq('sys_category_record_mm.uid_foreign', $queryBuilder->createNamedParameter($newsRecordUid, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', Connection::PARAM_STR)),
$queryBuilder->expr()->eq('sys_category_record_mm.fieldname', $queryBuilder->createNamedParameter('categories', Connection::PARAM_STR)),
$queryBuilder->expr()->eq('sys_category_record_mm.uid_foreign', $queryBuilder->createNamedParameter($newsRecordUid, Connection::PARAM_INT))
)
->executeQuery();

Expand Down
4 changes: 2 additions & 2 deletions Classes/Service/CategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public static function translateCategoryRecord($default, array $row = []): strin
->select('title')
->from('sys_category')
->where(
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($overlayLanguage, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT))
$queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($overlayLanguage, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($row['uid'], Connection::PARAM_INT))
)
->setMaxResults(1)
->executeQuery()->fetchAssociative();
Expand Down
7 changes: 4 additions & 3 deletions Classes/Service/LinkHandlerTargetPageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace GeorgRinger\News\Service;

use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
Expand Down Expand Up @@ -61,9 +62,9 @@ protected function getSinglePidFromCategory(int $newsId): int
$queryBuilder->expr()->eq('sys_category_record_mm.uid_local', $queryBuilder->quoteIdentifier('sys_category.uid'))
)
->where(
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', \PDO::PARAM_STR)),
$queryBuilder->expr()->gt('sys_category.single_pid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('sys_category_record_mm.uid_foreign', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', Connection::PARAM_STR)),
$queryBuilder->expr()->gt('sys_category.single_pid', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('sys_category_record_mm.uid_foreign', $queryBuilder->createNamedParameter($newsId, Connection::PARAM_INT))
)
->orderBy('sys_category_record_mm.sorting')
->setMaxResults(1)
Expand Down
Loading

0 comments on commit 57007e4

Please sign in to comment.