Commit 597a92fd authored by Stefan Bürk's avatar Stefan Bürk Committed by Benni Mack
Browse files

[TASK] Use proper QueryBuilder execute() replacement methods

doctrine/dbal implemented single purpose method to replace the
compound 'execute()' in QueryBuilder to avoid the incompatible
return typehint tuple of 'Doctrine\DBAL\Result|int' in favour
of 'executeQuery()' and 'executeStatement()' which was added
forward-compatible with #96247 marking the old one internal
but not deprecated for now to keep a eventually longer grace
period to mitigate for extensions developers.

This patch however goes through the core and replace these
methods to be clean as possible and is a first preparation
to remove the 'checkThisOnly' option from phpstan which are
swallowed by this option.

* replace 'execute' with 'executeQuery()' for select and
  count queries generating results ('Doctrine\DBAL\Result').
* use 'executeStatement()' for insert, update and delete
  queries return affected rows as return value (int)
* adjust return typehints to match the single return type
  signature on really minor places to match the return type
  of the wrapped replaced execute method.
* replace one really old 'exec()' from connection with
  corresponding replacement method along the way.
* add several todos on two places which are weird and do
  not make any sense for further investigation and fixing,
  as declared as out-of-the-scope for this wide-area patch.

Resolves: #96551
Related: #96247
Related: #96521
Releases: main, 11.5
Change-Id: Ie8d40f3882f1694ab7f7e5053729fa1c798a9c5f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73032


Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 4343860f
......@@ -68,7 +68,7 @@ class FrontendGroupsRepository
->where(
$beUser->getPagePermsClause(Permission::PAGE_SHOW)
)
->execute()
->executeQuery()
->fetchOne();
return (int)$optionCount;
......@@ -97,7 +97,7 @@ class FrontendGroupsRepository
$beUser->getPagePermsClause(Permission::PAGE_SHOW)
)
->orderBy('fe_groups.title')
->execute()
->executeQuery()
->fetchAllAssociative();
}
......
......@@ -75,7 +75,7 @@ class PasswordReset implements LoggerAwareInterface
->select('uid')
->from('be_users')
->setMaxResults(1)
->execute();
->executeQuery();
return (int)$statement->fetchOne() > 0;
}
......@@ -95,7 +95,7 @@ class PasswordReset implements LoggerAwareInterface
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($userId, \PDO::PARAM_INT))
)
->setMaxResults(1)
->execute();
->executeQuery();
return $statement->fetchOne() > 0;
}
......@@ -127,7 +127,7 @@ class PasswordReset implements LoggerAwareInterface
->andWhere(
$queryBuilder->expr()->eq('email', $queryBuilder->createNamedParameter($emailAddress))
)
->execute()
->executeQuery()
->fetchAllAssociative();
if (!is_array($users) || count($users) === 0) {
// No user found, do nothing, also no log to sys_log in order avoid log flooding
......@@ -289,10 +289,10 @@ class PasswordReset implements LoggerAwareInterface
$queryBuilder->andWhere(
$queryBuilder->expr()->comparison('SHA1(CONCAT(' . $queryBuilder->quoteIdentifier('email') . ', ' . $queryBuilder->quoteIdentifier('uid') . '))', $queryBuilder->expr()::EQ, $queryBuilder->createNamedParameter($identity))
);
$user = $queryBuilder->execute()->fetchAssociative();
$user = $queryBuilder->executeQuery()->fetchAssociative();
} else {
// no native SHA1/ CONCAT functionality, has to be done in PHP
$stmt = $queryBuilder->execute();
$stmt = $queryBuilder->executeQuery();
while ($row = $stmt->fetchAssociative()) {
if (hash_equals(hash('sha1', $row['email'] . (string)$row['uid']), $identity)) {
$user = $row;
......@@ -489,7 +489,7 @@ class PasswordReset implements LoggerAwareInterface
$queryBuilder->expr()->eq('log_data', $queryBuilder->createNamedParameter(serialize(['email' => $email]))),
$queryBuilder->expr()->gte('tstamp', $queryBuilder->createNamedParameter($since->getTimestamp(), \PDO::PARAM_INT))
)
->execute()
->executeQuery()
->fetchOne();
}
}
......@@ -93,7 +93,7 @@ class DefaultAvatarProvider implements AvatarProviderInterface
$queryBuilder->createNamedParameter((int)$backendUserId, \PDO::PARAM_INT)
)
)
->execute()
->executeQuery()
->fetchOne();
return (int)$fileUid;
......
......@@ -163,7 +163,7 @@ class ShortcutRepository
$queryBuilder->expr()->eq('route', $queryBuilder->createNamedParameter($routeIdentifier)),
$queryBuilder->expr()->eq('arguments', $queryBuilder->createNamedParameter($arguments))
)
->execute()
->executeQuery()
->fetchOne();
return (bool)$uid;
......@@ -195,7 +195,7 @@ class ShortcutRepository
'description' => $title ?: 'Shortcut', // Fall back to "Shortcut", see: initShortcuts()
'sorting' => $GLOBALS['EXEC_TIME'],
])
->execute();
->executeStatement();
return $affectedRows === 1;
}
......@@ -236,7 +236,7 @@ class ShortcutRepository
}
}
$affectedRows = $queryBuilder->execute();
$affectedRows = $queryBuilder->executeStatement();
return $affectedRows === 1;
}
......@@ -261,7 +261,7 @@ class ShortcutRepository
$queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
)
)
->execute();
->executeStatement();
if ($affectedRows === 1) {
$success = true;
......@@ -381,7 +381,7 @@ class ShortcutRepository
)
->orderBy('sc_group')
->addOrderBy('sorting')
->execute();
->executeQuery();
while ($row = $result->fetchAssociative()) {
$pageId = 0;
......
......@@ -80,7 +80,7 @@ class UserToolbarItem implements ToolbarItemInterface
->from('be_users')
->where(
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($backendUser->uc['recentSwitchedToUsers'], Connection::PARAM_INT_ARRAY))
)->execute();
)->executeQuery();
// Flip the array to have a "sorted" list of items
$mostRecentUsers = array_flip($backendUser->uc['recentSwitchedToUsers']);
......
......@@ -423,7 +423,7 @@ class Clipboard
);
}
foreach ($queryBuilder->execute()->fetchAllAssociative() as $record) {
foreach ($queryBuilder->executeQuery()->fetchAllAssociative() as $record) {
$title = htmlspecialchars(GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $record), $this->getBackendUser()->uc['titleLen']));
if (!$isRequestedTable) {
// In case the current table is not the requested table, e.g. "_FILE", wrap title in "muted" style
......
......@@ -181,7 +181,7 @@ class TranslationConfigurationProvider
);
}
$translationRecords = $queryBuilder
->execute()
->executeQuery()
->fetchAllAssociative();
$translations = [];
......
......@@ -682,7 +682,7 @@ class ElementInformationController
->select('*')
->from('sys_refindex')
->where(...$predicates)
->execute()
->executeQuery()
->fetchAllAssociative();
// Compile information for title tag:
......@@ -773,7 +773,7 @@ class ElementInformationController
->select('*')
->from('sys_refindex')
->where(...$predicates)
->execute()
->executeQuery()
->fetchAllAssociative();
// Compile information for title tag:
......@@ -832,7 +832,7 @@ class ElementInformationController
$queryBuilder->createNamedParameter($referenceRecord['recuid'], \PDO::PARAM_INT)
)
)
->execute()
->executeQuery()
->fetchAssociative();
return [
......
......@@ -1899,7 +1899,7 @@ class EditDocumentController
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
)
)
->execute()
->executeQuery()
->fetchOne();
}
......@@ -1922,7 +1922,7 @@ class EditDocumentController
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
)
)
->execute()
->executeQuery()
->fetchOne();
}
......@@ -2181,7 +2181,7 @@ class EditDocumentController
$queryBuilder->createNamedParameter($rowsByLang[0]['uid'], \PDO::PARAM_INT)
)
)
->execute();
->executeQuery();
while ($row = $result->fetchAssociative()) {
if ($backendUser->workspace !== 0 && BackendUtility::isTableWorkspaceEnabled($table)) {
......@@ -2298,7 +2298,7 @@ class EditDocumentController
$queryBuilder->createNamedParameter($origUid, \PDO::PARAM_INT)
)
)
->execute()
->executeQuery()
->fetchAssociative();
$returnUrl = $parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '';
if (is_array($localizedRecord)) {
......@@ -2362,7 +2362,7 @@ class EditDocumentController
$queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
)
)
->execute();
->executeQuery();
$availableLanguages = [];
......
......@@ -439,7 +439,7 @@ class LoginController
->select('uid', 'title', 'content', 'crdate')
->from($systemNewsTable)
->orderBy('crdate', 'DESC')
->execute()
->executeQuery()
->fetchAllAssociative();
foreach ($systemNewsRecords as $systemNewsRecord) {
$systemNews[] = [
......
......@@ -377,7 +377,7 @@ class NewRecordController
$numberOfPages = $queryBuilder
->count('*')
->from('pages')
->execute()
->executeQuery()
->fetchOne();
return $numberOfPages > 0;
}
......
......@@ -263,7 +263,7 @@ class NewMultiplePagesController
)
)
->orderBy('sorting')
->execute()
->executeQuery()
->fetchAllAssociative();
}
......
......@@ -214,7 +214,7 @@ class SortSubPagesController
)
)
->orderBy($orderBy)
->execute()
->executeQuery()
->fetchAllAssociative();
}
......
......@@ -267,7 +267,7 @@ class PageLayoutController
$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
$queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
)
)->execute();
)->executeQuery();
while ($pageTranslation = $statement->fetchAssociative()) {
$languageId = $pageTranslation[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
if (isset($this->availableLanguages[$languageId])) {
......@@ -526,7 +526,7 @@ class PageLayoutController
->where($queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)));
$links = [];
$rows = $queryBuilder->execute()->fetchAllAssociative();
$rows = $queryBuilder->executeQuery()->fetchAllAssociative();
if (!empty($rows)) {
foreach ($rows as $row) {
$linkToPid = $this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $row['uid']]);
......@@ -564,7 +564,7 @@ class PageLayoutController
)
)
->setMaxResults(1)
->execute()
->executeQuery()
->fetchAssociative();
BackendUtility::workspaceOL('pages', $localizedPage);
return $localizedPage['title'];
......@@ -847,7 +847,7 @@ class PageLayoutController
)
)
->setMaxResults(1)
->execute()
->executeQuery()
->fetchAssociative();
BackendUtility::workspaceOL('pages', $overlayRecord, $this->getBackendUser()->workspace);
$url = (string)$this->uriBuilder->buildUriFromRoute(
......@@ -959,7 +959,7 @@ class PageLayoutController
}
$count = $queryBuilder
->execute()
->executeQuery()
->fetchOne();
return (int)$count;
......
......@@ -725,7 +725,7 @@ class SiteConfigurationController
)
->orderBy('pid')
->addOrderBy('sorting')
->execute();
->executeQuery();
$pages = [];
while ($row = $statement->fetchAssociative()) {
......
......@@ -83,7 +83,7 @@ class LocalizationRepository
->groupBy('tt_content_orig.sys_language_uid');
$this->getAllowedLanguageConstraintsForBackendUser($pageId, $queryBuilder, $this->getBackendUser(), 'tt_content_orig');
return $queryBuilder->execute()->fetchAssociative() ?: [];
return $queryBuilder->executeQuery()->fetchAssociative() ?: [];
}
/**
......@@ -114,7 +114,7 @@ class LocalizationRepository
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
)
)
->execute()
->executeQuery()
->fetchOne();
return (int)$rowCount;
......@@ -145,7 +145,7 @@ class LocalizationRepository
->groupBy('sys_language_uid');
$this->getAllowedLanguageConstraintsForBackendUser($pageId, $queryBuilder, $this->getBackendUser());
$languages = $queryBuilder->execute()->fetchAllAssociative();
$languages = $queryBuilder->executeQuery()->fetchAllAssociative();
return $languages ?: [];
}
......@@ -202,7 +202,7 @@ class LocalizationRepository
$queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
)
)
->execute();
->executeQuery();
while ($origUid = $originalUidsStatement->fetchOne()) {
$originalUids[] = (int)$origUid;
......@@ -232,7 +232,7 @@ class LocalizationRepository
);
}
return $queryBuilder->execute();
return $queryBuilder->executeQuery();
}
/**
......
......@@ -568,7 +568,7 @@ class InlineRecordContainer extends AbstractContainer
)
)
->setMaxResults(1)
->execute()
->executeQuery()
->fetchAssociative();
if (!empty($recordInDatabase)) {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
......
......@@ -79,7 +79,7 @@ abstract class AbstractDatabaseRecordProvider implements LoggerAwareInterface
$row = $queryBuilder->select('*')
->from($tableName)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
->execute()
->executeQuery()
->fetchAssociative();
return $row ?: [];
......
......@@ -268,7 +268,7 @@ abstract class AbstractItemProvider
$queryBuilder = $this->buildForeignTableQueryBuilder($result, $fieldName);
try {
$queryResult = $queryBuilder->execute();
$queryResult = $queryBuilder->executeQuery();
} catch (DBALException $e) {
$databaseError = $e->getPrevious()->getMessage();
}
......
......@@ -68,7 +68,7 @@ class DatabasePageLanguageOverlayRows implements FormDataProviderInterface
$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
$queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)
))
->execute()
->executeQuery()
->fetchAllAssociative();
return $rows;
......
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