Skip to content

Commit

Permalink
[BUGFIX] Switch from PDO to Connection constants (#2184)
Browse files Browse the repository at this point in the history
Prepares for compatibility with upcoming major Doctrine
dependency switch.
  • Loading branch information
NamelessCoder authored Oct 24, 2024
1 parent ffa2dce commit 022da09
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Classes/Content/ContentTypeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FluidTYPO3\Flux\Content\TypeDefinition\FluidRenderingContentTypeDefinitionInterface;
use FluidTYPO3\Flux\Service\TemplateValidationService;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -123,7 +124,7 @@ protected function countUsages(ContentTypeDefinitionInterface $definition): int
->where(
$queryBuilder->expr()->eq(
'CType',
$queryBuilder->createNamedParameter($definition->getContentTypeName(), \PDO::PARAM_STR)
$queryBuilder->createNamedParameter($definition->getContentTypeName(), Connection::PARAM_STR)
)
);
return (integer) $queryBuilder->execute()->rowCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Doctrine\DBAL\Exception\TableNotFoundException;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Expand Down Expand Up @@ -38,8 +39,8 @@ public function fetchContentTypeDefinitions(): array
$typeRecords = $queryBuilder->select(...$keys)
->from('content_types')
->where(
$queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('hidden', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('hidden', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT))
)
->orderBy('sorting', 'ASC')
->execute()
Expand Down
18 changes: 9 additions & 9 deletions Classes/Integration/HookSubscribers/DataHandlerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ public function processDatamap_afterDatabaseOperations($command, $table, $id, $f

if ($newColumnPosition > 0) {
$queryBuilder = $this->createQueryBuilderForTable($table);
$queryBuilder->update($table)->set('colPos', $newColumnPosition, true, \PDO::PARAM_INT)->where(
$queryBuilder->update($table)->set('colPos', $newColumnPosition, true, Connection::PARAM_INT)->where(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($reference->substNEWwithIDs[$id], \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($reference->substNEWwithIDs[$id], Connection::PARAM_INT)
)
)->orWhere(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq(
't3ver_oid',
$queryBuilder->createNamedParameter($reference->substNEWwithIDs[$id], \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($reference->substNEWwithIDs[$id], Connection::PARAM_INT)
),
$queryBuilder->expr()->eq(
't3ver_wsid',
$queryBuilder->createNamedParameter($GLOBALS['BE_USER']->workspace, \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($GLOBALS['BE_USER']->workspace, Connection::PARAM_INT)
)
)
)->execute();
Expand Down Expand Up @@ -498,7 +498,7 @@ protected function getSingleRecordWithRestrictions(string $table, int $uid, stri
$queryBuilder->getRestrictions()->removeAll()->add($deletedRestriction);
$queryBuilder->select(...GeneralUtility::trimExplode(',', $fieldsToSelect))
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)));
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)));
/** @var array|false $firstResult */
$firstResult = $queryBuilder->execute()->fetch();
return $firstResult ?: null;
Expand All @@ -513,7 +513,7 @@ protected function getSingleRecordWithoutRestrictions(string $table, int $uid, s
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select(...GeneralUtility::trimExplode(',', $fieldsToSelect))
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)));
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)));
/** @var array|false $firstResult */
$firstResult = $queryBuilder->execute()->fetch();
return $firstResult ?: null;
Expand Down Expand Up @@ -559,12 +559,12 @@ protected function getTranslatedVersionOfParentInLanguageOnPage(
->where(
$queryBuilder->expr()->eq(
'sys_language_uid',
$queryBuilder->createNamedParameter($languageUid, \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($languageUid, Connection::PARAM_INT)
),
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageUid, Connection::PARAM_INT)),
$queryBuilder->expr()->eq(
'l10n_source',
$queryBuilder->createNamedParameter($originalParentUid, \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($originalParentUid, Connection::PARAM_INT)
)
);
/** @var array|false $firstResult */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected function fetchFieldData(int $uid): array
$queryBuilder = $this->createQueryBuilderForTable('flux_field');
/** @var array[] $result */
$result = $queryBuilder->select('uid', 'field_name', 'field_value')->from('flux_field')->where(
$queryBuilder->expr()->eq('sheet', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
$queryBuilder->expr()->eq('sheet', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT))
)->execute()->fetchAllAssociative();
foreach ($result as $fieldRecord) {
$settings = $this->assignVariableByDottedPath(
Expand All @@ -238,11 +238,11 @@ protected function fetchConfigurationRecords(): array
return $queryBuilder->select('*')->from('flux_sheet')->where(
$queryBuilder->expr()->eq(
'source_table',
$queryBuilder->createNamedParameter($this->table, \PDO::PARAM_STR)
$queryBuilder->createNamedParameter($this->table, Connection::PARAM_STR)
),
$queryBuilder->expr()->eq(
'source_field',
$queryBuilder->createNamedParameter($this->field, \PDO::PARAM_STR)
$queryBuilder->createNamedParameter($this->field, Connection::PARAM_STR)
),
)->execute()->fetchAllAssociative();
}
Expand All @@ -254,7 +254,7 @@ protected function fetchSheetRecord(string $sheetName): ?array
{
$queryBuilder = $this->createQueryBuilderForTable('flux_sheet');
return $queryBuilder->select('uid', 'name')->from('flux_sheet')->where(
$queryBuilder->expr()->eq('name', $queryBuilder->createNamedParameter($sheetName, \PDO::PARAM_STR))
$queryBuilder->expr()->eq('name', $queryBuilder->createNamedParameter($sheetName, Connection::PARAM_STR))
)->execute()->fetchAssociative() ?: null;
}

Expand Down
17 changes: 12 additions & 5 deletions Classes/Updates/MigrateColPosWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use FluidTYPO3\Flux\Utility\ColumnNumberUtility;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Registry;
Expand Down Expand Up @@ -157,8 +158,14 @@ public function executeUpdate(): bool
->selectLiteral('MAX(sorting)')
->from('tt_content')
->where(
$queryBuilder->expr()->gte('colPos', $queryBuilder->createNamedParameter($min, \PDO::PARAM_INT)),
$queryBuilder->expr()->lte('colPos', $queryBuilder->createNamedParameter($max, \PDO::PARAM_INT)),
$queryBuilder->expr()->gte(
'colPos',
$queryBuilder->createNamedParameter($min, Connection::PARAM_INT)
),
$queryBuilder->expr()->lte(
'colPos',
$queryBuilder->createNamedParameter($max, Connection::PARAM_INT)
),
)
->execute()
->fetchOne();
Expand All @@ -174,15 +181,15 @@ public function executeUpdate(): bool
->where(
$queryBuilder->expr()->eq(
'pid',
$queryBuilder->createNamedParameter($contentRow['pid'], \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($contentRow['pid'], Connection::PARAM_INT)
),
$queryBuilder->expr()->eq(
'colPos',
$queryBuilder->createNamedParameter($contentRow['colPos'], \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($contentRow['colPos'], Connection::PARAM_INT)
),
$queryBuilder->expr()->gte(
'sorting',
$queryBuilder->createNamedParameter($contentRow['sorting'], \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($contentRow['sorting'], Connection::PARAM_INT)
),
)
->orderBy('sorting', 'ASC')
Expand Down

0 comments on commit 022da09

Please sign in to comment.