Breaking: #102875 - ExpressionBuilder changes

See forge#102875

Description

Signature changes for following methods

  • ExpressionBuilder::literal(string $value): Value must be a string now.
  • ExpressionBuilder::trim(): Only \Doctrine\DBAL\Platforms\TrimMode enum for $position argument.

Following class constants have been removed

  • QUOTE_NOTHING: Not used since already TYPO3 v12 and Doctrine DBAL 3.x.
  • QUOTE_IDENTIFIER: Not used since already TYPO3 v12 and Doctrine DBAL 3.x.
  • QUOTE_PARAMETER: Not used since already TYPO3 v12 and Doctrine DBAL 3.x.

Impact

Calling any of the mentioned methods with invalid type will result in a PHP error.

Affected installations

Only those installations that uses one of the mentioned methods with invalid type(s).

Migration

ExpressionBuilder::literal()

Extension author need to ensure that a string is passed to literal().

ExpressionBuilder::trim()

Extension author need to pass the Doctrine DBAL enum TrimMode instead of an integer.

TRIM_LEADING

integer enum
0 TrimMode::UNSPECIFIED
1 TrimMode::LEADING
2 TrimMode::TRAILING
3 TrimMode::BOTH
EXT:my_extension/Classes/Domain/Repository/MyTableRepository.php
use Doctrine\DBAL\Platforms\TrimMode;
use TYPO3\CMS\Core\Database\Connection
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;

// before
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tt_content');
$queryBuilder->expr()->comparison(
    $queryBuilder->expr()->trim($fieldName, 1),
    ExpressionBuilder::EQ,
    $queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);

// after
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tt_content');
$queryBuilder->expr()->comparison(
    $queryBuilder->expr()->trim($fieldName, TrimMode::LEADING),
    ExpressionBuilder::EQ,
    $queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);

// example for dual version compatible code
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tt_content');
$queryBuilder->expr()->comparison(
    $queryBuilder->expr()->trim($fieldName, TrimMode::LEADING),
    ExpressionBuilder::EQ,
    $queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);
Copied!