Commit b1ac6218 authored by Stefan Bürk's avatar Stefan Bürk Committed by Christian Kuhn
Browse files

[TASK] Replace ExpressionBuilder andX() / orX() usage

doctrine/dbal moves their classes forward and deprecated
some stuff while providing replacement for it. This has
been early adopted for the core facade classes with #97081
in a forward-compatible way. Before deprecating the old
methods core usage have to be replaced.

Following ExpressionBuilder methods are replaced:

* 'andX()' with 'and()'
* 'orX()' with 'or()'

'and()' and 'or()' are made strict along the way.

This is a preparation to deprecate 'andX()' and 'orX()'
to align with ongoing deprecation and replacement of
doctrine/dbal changes.

Resolves: #97110
Related: #97081
Releases: main
Change-Id: Ia931266c6edc3abea38122242d7eab1092ae7d49
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73817


Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 43fb4eea
......@@ -351,7 +351,7 @@ class ShortcutRepository
$result = $queryBuilder->select('*')
->from(self::TABLE_NAME)
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq(
'userid',
$queryBuilder->createNamedParameter($backendUser->user['uid'], \PDO::PARAM_INT)
......
......@@ -695,7 +695,7 @@ class PageLayoutController
);
}
if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
$andWhere[] = $queryBuilder->expr()->andX(
$andWhere[] = $queryBuilder->expr()->and(
$queryBuilder->expr()->neq(
'starttime',
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
......@@ -707,7 +707,7 @@ class PageLayoutController
);
}
if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
$andWhere[] = $queryBuilder->expr()->andX(
$andWhere[] = $queryBuilder->expr()->and(
$queryBuilder->expr()->neq(
'endtime',
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
......@@ -720,7 +720,7 @@ class PageLayoutController
}
if (!empty($andWhere)) {
$queryBuilder->andWhere(
$queryBuilder->expr()->orX(...$andWhere)
$queryBuilder->expr()->or(...$andWhere)
);
}
$count = $queryBuilder
......
......@@ -702,8 +702,8 @@ class SiteConfigurationController
->from('pages')
->where(
$queryBuilder->expr()->eq('sys_language_uid', 0),
$queryBuilder->expr()->orX(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq('pid', 0),
$queryBuilder->expr()->neq('doktype', PageRepository::DOKTYPE_SYSFOLDER)
),
......
......@@ -228,7 +228,7 @@ class SuggestWizardDefaultReceiver
$constraints[] = $this->buildConstraintBlock($splitString);
}
foreach ($constraints as $constraint) {
$this->queryBuilder->andWhere($expressionBuilder->andX($constraint));
$this->queryBuilder->andWhere($expressionBuilder->and($constraint));
}
}
if (!empty($this->allowedPages)) {
......@@ -254,7 +254,7 @@ class SuggestWizardDefaultReceiver
protected function buildConstraintBlock(string $searchString)
{
$expressionBuilder = $this->queryBuilder->expr();
$selectParts = $expressionBuilder->orX();
$selectParts = $expressionBuilder->or();
if (MathUtility::canBeInterpretedAsInteger($searchString) && (int)$searchString > 0) {
$selectParts->add($expressionBuilder->eq('uid', (int)$searchString));
}
......
......@@ -346,7 +346,7 @@ class RecordHistory
);
} else {
$queryBuilder->andWhere(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->eq('workspace', 0),
$queryBuilder->expr()->eq('workspace', $queryBuilder->createNamedParameter($backendUser->workspace, \PDO::PARAM_INT))
)
......
......@@ -340,7 +340,7 @@ class LiveSearch
$evalRules = $fieldConfig['eval'] ?? '';
// Check whether search should be case-sensitive or not
$searchConstraint = $queryBuilder->expr()->andX(
$searchConstraint = $queryBuilder->expr()->and(
$queryBuilder->expr()->comparison(
'LOWER(' . $queryBuilder->quoteIdentifier($fieldName) . ')',
'LIKE',
......@@ -351,7 +351,7 @@ class LiveSearch
if (is_array($fieldConfig['search'] ?? false)) {
if (in_array('case', $fieldConfig['search'], true)) {
// Replace case insensitive default constraint
$searchConstraint = $queryBuilder->expr()->andX(
$searchConstraint = $queryBuilder->expr()->and(
$queryBuilder->expr()->like(
$fieldName,
$queryBuilder->createNamedParameter($like, \PDO::PARAM_STR)
......@@ -384,7 +384,7 @@ class LiveSearch
return '0=1';
}
return $queryBuilder->expr()->orX(...$constraints);
return $queryBuilder->expr()->or(...$constraints);
}
/**
......
......@@ -526,7 +526,7 @@ class PageTreeRepository
QueryHelper::stripLogicalOperatorPrefix($additionalWhereClause)
);
$searchParts = $expressionBuilder->orX();
$searchParts = $expressionBuilder->or();
if (is_numeric($searchFilter) && $searchFilter > 0) {
$searchParts->add(
$expressionBuilder->eq('uid', $queryBuilder->createNamedParameter($searchFilter, \PDO::PARAM_INT))
......@@ -534,7 +534,7 @@ class PageTreeRepository
}
$searchFilter = '%' . $queryBuilder->escapeLikeWildcards($searchFilter) . '%';
$searchWhereAlias = $expressionBuilder->orX(
$searchWhereAlias = $expressionBuilder->or(
$expressionBuilder->like(
'nav_title',
$queryBuilder->createNamedParameter($searchFilter, \PDO::PARAM_STR)
......
......@@ -231,8 +231,8 @@ class BackendUtility
$expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable($table)
->getExpressionBuilder();
$query = $expressionBuilder->andX();
$invQuery = $expressionBuilder->orX();
$query = $expressionBuilder->and();
$invQuery = $expressionBuilder->or();
$ctrl += [
'enablecolumns' => [],
......@@ -248,7 +248,7 @@ class BackendUtility
$field = $table . '.' . $ctrl['enablecolumns']['starttime'];
$query->add($expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME']));
$invQuery->add(
$expressionBuilder->andX(
$expressionBuilder->and(
$expressionBuilder->neq($field, 0),
$expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
)
......@@ -257,13 +257,13 @@ class BackendUtility
if ($ctrl['enablecolumns']['endtime'] ?? false) {
$field = $table . '.' . $ctrl['enablecolumns']['endtime'];
$query->add(
$expressionBuilder->orX(
$expressionBuilder->or(
$expressionBuilder->eq($field, 0),
$expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
)
);
$invQuery->add(
$expressionBuilder->andX(
$expressionBuilder->and(
$expressionBuilder->neq($field, 0),
$expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
)
......@@ -3173,9 +3173,9 @@ class BackendUtility
't3ver_wsid',
$queryBuilder->createNamedParameter($workspace, \PDO::PARAM_INT)
),
$queryBuilder->expr()->orX(
$queryBuilder->expr()->or(
// t3ver_state=1 does not contain a t3ver_oid, and returns itself
$queryBuilder->expr()->andX(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
......
......@@ -156,8 +156,8 @@ class DefaultDataProvider implements DataProviderInterface
->select('*')
->from($this->tableName)
->where(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->and(
$queryBuilder->expr()->comparison(
$queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT),
ExpressionBuilder::EQ,
......@@ -169,7 +169,7 @@ class DefaultDataProvider implements DataProviderInterface
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
)
),
$queryBuilder->expr()->orX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->eq(
'backend_layout.pid',
$queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT)
......@@ -179,7 +179,7 @@ class DefaultDataProvider implements DataProviderInterface
$queryBuilder->createNamedParameter($storagePid, \PDO::PARAM_INT)
)
),
$queryBuilder->expr()->andX(
$queryBuilder->expr()->and(
$queryBuilder->expr()->comparison(
$queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT),
ExpressionBuilder::EQ,
......
......@@ -487,13 +487,13 @@ class BackendUserAuthentication extends AbstractUserAuthentication
->expr();
// User
$constraint = $expressionBuilder->orX(
$constraint = $expressionBuilder->or(
$expressionBuilder->comparison(
$expressionBuilder->bitAnd('pages.perms_everybody', $perms),
ExpressionBuilder::EQ,
$perms
),
$expressionBuilder->andX(
$expressionBuilder->and(
$expressionBuilder->eq('pages.perms_userid', (int)$this->user['uid']),
$expressionBuilder->comparison(
$expressionBuilder->bitAnd('pages.perms_user', $perms),
......@@ -506,7 +506,7 @@ class BackendUserAuthentication extends AbstractUserAuthentication
// Group (if any is set)
if (!empty($this->userGroupsUID)) {
$constraint->add(
$expressionBuilder->andX(
$expressionBuilder->and(
$expressionBuilder->in(
'pages.perms_groupid',
$this->userGroupsUID
......
......@@ -164,7 +164,7 @@ class GroupResolver
$users = $queryBuilder
->where(
$queryBuilder->expr()->orX(...$constraints)
$queryBuilder->expr()->or(...$constraints)
)
->executeQuery()
->fetchAllAssociative();
......@@ -220,7 +220,7 @@ class GroupResolver
$result = $queryBuilder
->where(
$queryBuilder->expr()->orX(...$constraints)
$queryBuilder->expr()->or(...$constraints)
)
->executeQuery();
......
......@@ -2465,7 +2465,7 @@ class DataHandler implements LoggerAwareInterface
&& ($GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? '') !== '') {
$queryBuilder
->andWhere(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->or(
// records without l10n_parent must be taken into account (in any language)
$queryBuilder->expr()->eq(
$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'],
......@@ -7658,7 +7658,7 @@ class DataHandler implements LoggerAwareInterface
if ($considerWorkspaces) {
$queryBuilder->andWhere(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->eq('t3ver_oid', 0),
$queryBuilder->expr()->eq('t3ver_state', VersionState::MOVE_POINTER)
)
......@@ -7742,7 +7742,7 @@ class DataHandler implements LoggerAwareInterface
if ($considerWorkspaces) {
$queryBuilder->andWhere(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->eq('t3ver_oid', 0),
$queryBuilder->expr()->eq('t3ver_state', VersionState::MOVE_POINTER)
)
......
......@@ -1116,7 +1116,7 @@ class DataMapProcessor
$zeroParameter
),
// any parent or source pointers
$queryBuilder->expr()->orX(...$ancestorPredicates),
$queryBuilder->expr()->or(...$ancestorPredicates),
];
} elseif (!empty($fieldNames['origin'])) {
// fetch by origin dependency ("copied from")
......
......@@ -177,12 +177,12 @@ class ReferenceIndexUpdater
$queryBuilder->delete('sys_refindex')
->where(
$queryBuilder->expr()->eq('workspace', $queryBuilder->createNamedParameter($workspace, \PDO::PARAM_INT)),
$queryBuilder->expr()->orX(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq('tablename', $queryBuilder->createNamedParameter($table)),
$queryBuilder->expr()->eq('recuid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
),
$queryBuilder->expr()->andX(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq('ref_table', $queryBuilder->createNamedParameter($table)),
$queryBuilder->expr()->eq('ref_uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
)
......
......@@ -94,7 +94,7 @@ class ExpressionBuilder
*
* @return CompositeExpression
*/
public function and(...$expressions): CompositeExpression
public function and(CompositeExpression|string|null ...$expressions): CompositeExpression
{
return CompositeExpression::and(...$expressions);
}
......@@ -106,7 +106,7 @@ class ExpressionBuilder
*
* @return CompositeExpression
*/
public function or(...$expressions): CompositeExpression
public function or(CompositeExpression|string|null ...$expressions): CompositeExpression
{
return CompositeExpression::or(...$expressions);
}
......@@ -344,7 +344,7 @@ class ExpressionBuilder
case 'mssql':
// See unit and functional tests for details
if ($isColumn) {
$expression = $this->orX(
$expression = $this->or(
$this->eq($fieldName, $value),
$this->like($fieldName, $value . ' + \',%\''),
$this->like($fieldName, '\'%,\' + ' . $value),
......@@ -356,7 +356,7 @@ class ExpressionBuilder
['[[]', '[%]'],
$this->unquoteLiteral($value)
);
$expression = $this->orX(
$expression = $this->or(
$this->eq($fieldName, $this->literal($this->unquoteLiteral((string)$value))),
$this->like($fieldName, $this->literal($likeEscapedValue . ',%')),
$this->like($fieldName, $this->literal('%,' . $likeEscapedValue)),
......@@ -457,7 +457,7 @@ class ExpressionBuilder
case 'mssql':
// See unit and functional tests for details
if ($isColumn) {
$expression = $this->andX(
$expression = $this->and(
$this->neq($fieldName, $value),
$this->notLike($fieldName, $value . ' + \',%\''),
$this->notLike($fieldName, '\'%,\' + ' . $value),
......@@ -469,7 +469,7 @@ class ExpressionBuilder
['[[]', '[%]'],
$this->unquoteLiteral($value)
);
$expression = $this->andX(
$expression = $this->and(
$this->neq($fieldName, $this->literal($this->unquoteLiteral((string)$value))),
$this->notLike($fieldName, $this->literal($likeEscapedValue . ',%')),
$this->notLike($fieldName, $this->literal('%,' . $likeEscapedValue)),
......
......@@ -708,7 +708,7 @@ class QueryBuilder
*/
public function leftJoin(string $fromAlias, string $join, string $alias, string $condition = null): QueryBuilder
{
$condition = $this->expr()->andX(
$condition = $this->expr()->and(
$condition,
$this->restrictionContainer->buildExpression([$alias ?? $join => $join], $this->expr())
);
......@@ -745,7 +745,7 @@ class QueryBuilder
}
}
$condition = $this->expr()->andX(
$condition = $this->expr()->and(
$condition,
$this->restrictionContainer->buildExpression([$fromAlias => $fromTable], $this->expr())
);
......
......@@ -50,7 +50,7 @@ abstract class AbstractRestrictionContainer implements QueryRestrictionContainer
foreach ($this->restrictions as $restriction) {
$constraints[] = $restriction->buildExpression($queriedTables, $expressionBuilder);
}
return $expressionBuilder->andX(...$constraints);
return $expressionBuilder->and(...$constraints);
}
/**
......
......@@ -70,7 +70,7 @@ class BackendWorkspaceRestriction implements QueryRestrictionInterface
(int)$this->workspaceId
);
if ($this->includeRowsForWorkspaceOverlay) {
$constraints[] = $expressionBuilder->orX(
$constraints[] = $expressionBuilder->or(
$workspaceIdExpression,
$expressionBuilder->lte(
$tableAlias . '.t3ver_state',
......@@ -88,6 +88,6 @@ class BackendWorkspaceRestriction implements QueryRestrictionInterface
}
}
}
return $expressionBuilder->andX(...$constraints);
return $expressionBuilder->and(...$constraints);
}
}
......@@ -46,6 +46,6 @@ class DeletedRestriction implements QueryRestrictionInterface
);
}
}
return $expressionBuilder->andX(...$constraints);
return $expressionBuilder->and(...$constraints);
}
}
......@@ -61,6 +61,6 @@ class DocumentTypeExclusionRestriction implements QueryRestrictionInterface
$constraints[] = $expressionBuilder->notIn($tableAlias . '.doktype', $this->doktypes);
}
return $expressionBuilder->andX(...$constraints);
return $expressionBuilder->and(...$constraints);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment