Commit 81bb030e authored by Stefan Bürk's avatar Stefan Bürk Committed by Benni Mack
Browse files

[TASK] Replace 'CompositeExpression->add()' 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.

This patch replaces the usage of 'CompositeExpression::add()'
with the immutable way using 'with()' with re-assigning the
returned instance to the used variable.

In general this means that following usage example:

  $or = CompositeExpression::or();
  $or->add($queryBuilder->expr()->eq(...));

will be replaced with:

  $or = CompositeExpression::or();
  $or = $or->with($queryBuilder->expr()->eq(...));

Alternativly this could be refactored collecting parts in a
array first and add them later with one 'with()' call or by
directly creating the 'or()' or 'and()' CompositeExpression
with the provided parts directly - which would have been a
larger and harder to review patch. Thus this patch does the
simple replacement to have minimal changes for easier review
experience.

Resolves: #97124
Related: #97081
Releases: main
Change-Id: I00fde09593e1c1ccb2949daaec3ee4aa688dda63
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73833


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 5c6c7611
......@@ -256,7 +256,7 @@ class SuggestWizardDefaultReceiver
$expressionBuilder = $this->queryBuilder->expr();
$selectParts = $expressionBuilder->or();
if (MathUtility::canBeInterpretedAsInteger($searchString) && (int)$searchString > 0) {
$selectParts->add($expressionBuilder->eq('uid', (int)$searchString));
$selectParts = $selectParts->with($expressionBuilder->eq('uid', (int)$searchString));
}
$searchWholePhrase = !isset($this->config['searchWholePhrase']) || $this->config['searchWholePhrase'];
$likeCondition = ($searchWholePhrase ? '%' : '') . $this->queryBuilder->escapeLikeWildcards($searchString) . '%';
......@@ -265,7 +265,7 @@ class SuggestWizardDefaultReceiver
$selectFields = GeneralUtility::trimExplode(',', $selectFieldsList, true);
$selectFields = array_unique($selectFields);
foreach ($selectFields as $field) {
$selectParts->add($expressionBuilder->like($field, $this->queryBuilder->createPositionalParameter($likeCondition)));
$selectParts = $selectParts->with($expressionBuilder->like($field, $this->queryBuilder->createPositionalParameter($likeCondition)));
}
return $selectParts;
......
......@@ -360,7 +360,7 @@ class LiveSearch
}
// Apply additional condition, if any
if ($fieldConfig['search']['andWhere'] ?? false) {
$searchConstraint->add(
$searchConstraint = $searchConstraint->with(
QueryHelper::stripLogicalOperatorPrefix(QueryHelper::quoteDatabaseIdentifiers($queryBuilder->getConnection(), $fieldConfig['search']['andWhere']))
);
}
......
......@@ -528,7 +528,7 @@ class PageTreeRepository
$searchParts = $expressionBuilder->or();
if (is_numeric($searchFilter) && $searchFilter > 0) {
$searchParts->add(
$searchParts = $searchParts->with(
$expressionBuilder->eq('uid', $queryBuilder->createNamedParameter($searchFilter, \PDO::PARAM_INT))
);
}
......@@ -544,7 +544,7 @@ class PageTreeRepository
$queryBuilder->createNamedParameter($searchFilter, \PDO::PARAM_STR)
)
);
$searchParts->add($searchWhereAlias);
$searchParts = $searchParts->with($searchWhereAlias);
$queryBuilder->andWhere($searchParts);
$pageRecords = $queryBuilder
......
......@@ -241,13 +241,13 @@ class BackendUtility
if (is_array($ctrl)) {
if ($ctrl['enablecolumns']['disabled'] ?? false) {
$field = $table . '.' . $ctrl['enablecolumns']['disabled'];
$query->add($expressionBuilder->eq($field, 0));
$invQuery->add($expressionBuilder->neq($field, 0));
$query = $query->with($expressionBuilder->eq($field, 0));
$invQuery = $invQuery->with($expressionBuilder->neq($field, 0));
}
if ($ctrl['enablecolumns']['starttime'] ?? false) {
$field = $table . '.' . $ctrl['enablecolumns']['starttime'];
$query->add($expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME']));
$invQuery->add(
$query = $query->with($expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME']));
$invQuery = $invQuery->with(
$expressionBuilder->and(
$expressionBuilder->neq($field, 0),
$expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
......@@ -256,13 +256,13 @@ class BackendUtility
}
if ($ctrl['enablecolumns']['endtime'] ?? false) {
$field = $table . '.' . $ctrl['enablecolumns']['endtime'];
$query->add(
$query = $query->with(
$expressionBuilder->or(
$expressionBuilder->eq($field, 0),
$expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
)
);
$invQuery->add(
$invQuery = $invQuery->with(
$expressionBuilder->and(
$expressionBuilder->neq($field, 0),
$expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
......
......@@ -505,7 +505,7 @@ class BackendUserAuthentication extends AbstractUserAuthentication
// Group (if any is set)
if (!empty($this->userGroupsUID)) {
$constraint->add(
$constraint = $constraint->with(
$expressionBuilder->and(
$expressionBuilder->in(
'pages.perms_groupid',
......
......@@ -115,7 +115,7 @@ class PagePermissionRestriction implements QueryRestrictionInterface
// User groups (if any are set)
$groupIds = array_map('intval', $this->userAspect->getGroupIds());
if (!empty($groupIds)) {
$constraint->add(
$constraint = $constraint->with(
$expressionBuilder->and(
$expressionBuilder->in(
$tableAlias . '.perms_groupid',
......
......@@ -616,7 +616,7 @@ class RelationHandler
$additionalWhere = $expressionBuilder->and();
// Add WHERE clause if configured
if ($this->MM_table_where) {
$additionalWhere->add(
$additionalWhere = $additionalWhere->with(
QueryHelper::stripLogicalOperatorPrefix(
str_replace('###THIS_UID###', (string)$uid, $this->MM_table_where)
)
......@@ -624,7 +624,7 @@ class RelationHandler
}
// Select, update or delete only those relations that match the configured fields
foreach ($this->MM_match_fields as $field => $value) {
$additionalWhere->add($expressionBuilder->eq($field, $expressionBuilder->literal($value)));
$additionalWhere = $additionalWhere->with($expressionBuilder->eq($field, $expressionBuilder->literal($value)));
}
$queryBuilder = $connection->createQueryBuilder();
......@@ -752,13 +752,13 @@ class RelationHandler
foreach ($oldMMs as $oldMM_key => $mmItem) {
// If UID field is present, of course we need only use that for deleting.
if ($this->MM_hasUidField) {
$removeClauses->add($queryBuilder->expr()->eq(
$removeClauses = $removeClauses->with($queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($oldMMs_inclUid[$oldMM_key], \PDO::PARAM_INT)
));
} else {
if (is_array($mmItem)) {
$removeClauses->add(
$removeClauses = $removeClauses->with(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq(
'tablenames',
......@@ -771,7 +771,7 @@ class RelationHandler
)
);
} else {
$removeClauses->add(
$removeClauses = $removeClauses->with(
$queryBuilder->expr()->eq(
$uidForeign_field,
$queryBuilder->createNamedParameter($mmItem, \PDO::PARAM_INT)
......
......@@ -178,7 +178,7 @@ class CacheLifetimeCalculator
. ' THEN NULL ELSE ' . $queryBuilder->quoteIdentifier($timeFields[$field]) . ' END'
. ') AS ' . $queryBuilder->quoteIdentifier($timeFields[$field])
);
$timeConditions->add(
$timeConditions = $timeConditions->with(
$queryBuilder->expr()->gt(
$timeFields[$field],
$queryBuilder->createNamedParameter($currentTimestamp, \PDO::PARAM_INT)
......
......@@ -5262,13 +5262,13 @@ class ContentObjectRenderer implements LoggerAwareInterface
$searchWordConstraint = $queryBuilder->expr()->or();
$searchWord = $queryBuilder->escapeLikeWildcards($searchWord);
foreach ($searchFields as $field) {
$searchWordConstraint->add(
$searchWordConstraint = $searchWordConstraint->with(
$queryBuilder->expr()->like($prefixTableName . $field, $queryBuilder->quote('%' . $searchWord . '%'))
);
}
if ($searchWordConstraint->count()) {
$where->add($searchWordConstraint);
$where = $where->with($searchWordConstraint);
}
}
......
......@@ -761,17 +761,17 @@ class IndexSearchRepository
$whereClause = $expressionBuilder->and();
$match = false;
if (!($this->searchRootPageIdList < 0)) {
$whereClause->add(
$whereClause = $whereClause->with(
$expressionBuilder->in('ISEC.rl0', GeneralUtility::intExplode(',', $this->searchRootPageIdList, true))
);
}
if (strpos($this->sections, 'rl1_') === 0) {
$whereClause->add(
$whereClause = $whereClause->with(
$expressionBuilder->in('ISEC.rl1', GeneralUtility::intExplode(',', substr($this->sections, 4)))
);
$match = true;
} elseif (strpos($this->sections, 'rl2_') === 0) {
$whereClause->add(
$whereClause = $whereClause->with(
$expressionBuilder->in('ISEC.rl2', GeneralUtility::intExplode(',', substr($this->sections, 4)))
);
$match = true;
......@@ -779,7 +779,7 @@ class IndexSearchRepository
// Traversing user configured fields to see if any of those are used to limit search to a section:
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['addRootLineFields'] ?? [] as $fieldName => $rootLineLevel) {
if (strpos($this->sections, $fieldName . '_') === 0) {
$whereClause->add(
$whereClause = $whereClause->with(
$expressionBuilder->in(
'ISEC.' . $fieldName,
GeneralUtility::intExplode(',', substr($this->sections, strlen($fieldName) + 1))
......@@ -794,15 +794,15 @@ class IndexSearchRepository
if (!$match) {
switch ((string)$this->sections) {
case '-1':
$whereClause->add(
$whereClause = $whereClause->with(
$expressionBuilder->eq('ISEC.page_id', $this->getTypoScriptFrontendController()->id)
);
break;
case '-2':
$whereClause->add($expressionBuilder->eq('ISEC.rl2', 0));
$whereClause = $whereClause->with($expressionBuilder->eq('ISEC.rl2', 0));
break;
case '-3':
$whereClause->add($expressionBuilder->gt('ISEC.rl2', 0));
$whereClause = $whereClause->with($expressionBuilder->gt('ISEC.rl2', 0));
break;
}
}
......@@ -1088,7 +1088,7 @@ class IndexSearchRepository
// (no "sentence search" should be done here - may deselect results)
$wordSel = $queryBuilder->expr()->or();
foreach ($this->wSelClauses as $wSelClause) {
$wordSel->add(QueryHelper::stripLogicalOperatorPrefix($wSelClause));
$wordSel = $wordSel->with(QueryHelper::stripLogicalOperatorPrefix($wSelClause));
}
$queryBuilder->andWhere($wordSel);
}
......
......@@ -2267,7 +2267,7 @@ class DatabaseRecordList
// This will hide records from display - it has nothing to do with user rights!!
$pidList = GeneralUtility::intExplode(',', $backendUser->getTSConfig()['options.']['hideRecords.']['pages'] ?? '', true);
if (!empty($pidList)) {
$permsClause->add($expressionBuilder->notIn('pages.uid', $pidList));
$permsClause = $permsClause->with($expressionBuilder->notIn('pages.uid', $pidList));
}
$this->perms_clause = (string)$permsClause;
......@@ -2582,10 +2582,10 @@ class DatabaseRecordList
$searchConstraint = $expressionBuilder->and($expressionBuilder->like($fieldName, $like));
}
if (($searchConfig['pidonly'] ?? false) && $currentPid > 0) {
$searchConstraint->add($expressionBuilder->eq($tablePidField, (int)$currentPid));
$searchConstraint = $searchConstraint->with($expressionBuilder->eq($tablePidField, (int)$currentPid));
}
if ($searchConfig['andWhere'] ?? false) {
$searchConstraint->add(
$searchConstraint = $searchConstraint->with(
QueryHelper::quoteDatabaseIdentifiers($queryBuilder->getConnection(), QueryHelper::stripLogicalOperatorPrefix($fieldConfig['search']['andWhere']))
);
}
......
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