Commit c975426b authored by Benni Mack's avatar Benni Mack Committed by Oliver Bartsch
Browse files

[TASK] Doctrine DBAL: Use fetchAssociative() instead of fetch()

This change migrates $result->fetch() methods
to $result->fetchAssociative() and $result->closeCursor()
to $result->free() methods.

Since TYPO3 uses fetchMode "associative" by default when
setting up the connections, this change is another
step towards Doctrine DBAL 3.0 compatibility.

Resolves: #94659
Releases: master
Change-Id: Idce7c8466925a6e58059e7e16ebc3ffe35ca6fa6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70125

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent e5805210
......@@ -289,11 +289,11 @@ 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()->fetch();
$user = $queryBuilder->execute()->fetchAssociative();
} else {
// no native SHA1/ CONCAT functionality, has to be done in PHP
$stmt = $queryBuilder->execute();
while ($row = $stmt->fetch()) {
while ($row = $stmt->fetchAssociative()) {
if (hash_equals(hash('sha1', $row['email'] . (string)$row['uid']), $identity)) {
$user = $row;
break;
......
......@@ -469,7 +469,7 @@ class ShortcutRepository
->addOrderBy('sorting')
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$pageId = 0;
$shortcut = ['raw' => $row];
$routeIdentifier = $row['route'] ?? '';
......
......@@ -87,7 +87,7 @@ class UserToolbarItem implements ToolbarItemInterface
// Flip the array to have a "sorted" list of items
$mostRecentUsers = array_flip($backendUser->uc['recentSwitchedToUsers']);
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$mostRecentUsers[$row['uid']] = $row;
}
......
......@@ -835,7 +835,7 @@ class ElementInformationController
)
)
->execute()
->fetch();
->fetchAssociative();
return [
'recuid' => $fileReference['uid_foreign'],
......
......@@ -2130,7 +2130,7 @@ class EditDocumentController
)
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
if ($backendUser->workspace !== 0 && BackendUtility::isTableWorkspaceEnabled($table)) {
$workspaceVersion = BackendUtility::getWorkspaceVersionOfRecord($backendUser->workspace, $table, $row['uid'], 'uid,t3ver_state');
if (!empty($workspaceVersion)) {
......@@ -2243,7 +2243,7 @@ class EditDocumentController
)
)
->execute()
->fetch();
->fetchAssociative();
$returnUrl = $parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '';
if (is_array($localizedRecord)) {
// Create redirect response to self to edit just created record
......@@ -2317,7 +2317,7 @@ class EditDocumentController
];
}
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$languageId = (int)$row[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
if (isset($allLanguages[$languageId])) {
$availableLanguages[$languageId] = $allLanguages[$languageId];
......
......@@ -156,7 +156,7 @@ class LocalizationController
);
$flatRecords = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
BackendUtility::workspaceOL('tt_content', $row, -99, true);
if (!$row || VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
continue;
......
......@@ -254,7 +254,7 @@ class PageLayoutController
$queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
)
)->execute();
while ($pageTranslation = $statement->fetch()) {
while ($pageTranslation = $statement->fetchAssociative()) {
$languageId = $pageTranslation[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
if (isset($this->availableLanguages[$languageId])) {
$this->MOD_MENU['language'][$languageId] = $this->availableLanguages[$languageId]->getTitle();
......@@ -529,7 +529,7 @@ class PageLayoutController
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
BackendUtility::workspaceOL('pages', $localizedPage);
return $localizedPage['title'];
}
......@@ -818,7 +818,7 @@ class PageLayoutController
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
BackendUtility::workspaceOL('pages', $overlayRecord, (int)$this->getBackendUser()->workspace);
// Edit button
$urlParameters = [
......
......@@ -747,7 +747,7 @@ class SiteConfigurationController
->execute();
$pages = [];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$row['rootline'] = BackendUtility::BEgetRootLine((int)$row['uid']);
array_pop($row['rootline']);
$row['rootline'] = array_reverse($row['rootline']);
......
......@@ -84,7 +84,7 @@ class LocalizationRepository
->groupBy('tt_content_orig.sys_language_uid');
$this->getAllowedLanguageConstraintsForBackendUser($pageId, $queryBuilder, $this->getBackendUser(), 'tt_content_orig');
return $queryBuilder->execute()->fetch() ?: [];
return $queryBuilder->execute()->fetchAssociative() ?: [];
}
/**
......
......@@ -559,7 +559,7 @@ class InlineRecordContainer extends AbstractContainer
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
if (!empty($recordInDatabase)) {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$url = (string)$uriBuilder->buildUriFromRoute('record_edit', [
......
......@@ -80,7 +80,7 @@ abstract class AbstractDatabaseRecordProvider implements LoggerAwareInterface
->from($tableName)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
return $row ?: [];
}
......
......@@ -368,7 +368,7 @@ abstract class AbstractItemProvider
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
while ($foreignRow = $queryResult->fetch()) {
while ($foreignRow = $queryResult->fetchAssociative()) {
BackendUtility::workspaceOL($foreignTable, $foreignRow);
// Only proceed in case the row was not unset and we don't deal with a delete placeholder
if (is_array($foreignRow)
......
......@@ -164,7 +164,7 @@ class SuggestWizardDefaultReceiver
->execute()
->fetchOne();
if ($allRowsCount) {
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
// check if we already have collected the maximum number of records
if (count($rows) > $this->maxItems) {
break;
......
......@@ -314,7 +314,7 @@ class RecordHistory
->from('sys_history')
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($lastHistoryEntry, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
if (empty($record)) {
return [];
......@@ -382,7 +382,7 @@ class RecordHistory
{
$events = [];
$result = $queryBuilder->orderBy('tstamp', 'DESC')->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$identifier = (int)$row['uid'];
$actionType = (int)$row['actiontype'];
if ($actionType === RecordHistoryStore::ACTION_ADD || $actionType === RecordHistoryStore::ACTION_UNDELETE) {
......
......@@ -209,7 +209,7 @@ class LiveSearch
$collect = [];
$result = $queryBuilder->execute();
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
BackendUtility::workspaceOL($tableName, $row);
if (!is_array($row)) {
continue;
......
......@@ -162,7 +162,7 @@ final class CategoryPermissionsAspect
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
)
->execute()
->fetch();
->fetchAssociative();
$parentUids = [];
if ($row['parent'] > 0) {
......
......@@ -563,7 +563,7 @@ abstract class AbstractTreeView
*/
public function getDataNext(&$res)
{
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
BackendUtility::workspaceOL($this->table, $row, $this->getBackendUser()->workspace, true);
if (is_array($row)) {
break;
......@@ -580,7 +580,7 @@ abstract class AbstractTreeView
*/
public function getDataFree(&$res)
{
$res->closeCursor();
$res->free();
}
/**
......
......@@ -388,7 +388,7 @@ class PagePositionMap
$lines[$vv] = [];
$lines[$vv][] = $this->insertPositionIcon('', $vv, $kk, $moveUid, $pid);
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
BackendUtility::workspaceOL('tt_content', $row);
if (is_array($row)) {
$lines[$vv][] = $this->getRecordHeader($row);
......
......@@ -117,7 +117,7 @@ class BackendUtility
$queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($where));
}
$row = $queryBuilder->execute()->fetch();
$row = $queryBuilder->execute()->fetchAssociative();
if ($row) {
return $row;
}
......@@ -474,8 +474,8 @@ class BackendUtility
$statement->bindValue(1, (int)$uid);
$statement->execute();
}
$row = $statement->fetch();
$statement->closeCursor();
$row = $statement->fetchAssociative();
$statement->free();
if ($row) {
if ($workspaceOL) {
......@@ -816,7 +816,7 @@ class BackendUtility
->where(QueryHelper::stripLogicalOperatorPrefix($where))
->execute();
while ($record = $res->fetch()) {
while ($record = $res->fetchAssociative()) {
// store the uid, because it might be unset if it's not among the requested $fields
$recordId = $record['uid'];
$record[$titleField] = self::getRecordTitle($table, $record);
......@@ -1617,7 +1617,7 @@ class BackendUtility
->execute();
$mmlA = [];
while ($MMrow = $result->fetch()) {
while ($MMrow = $result->fetchAssociative()) {
// Keep sorting of $selectUids
$selectedUid = array_search($MMrow['uid'], $selectUids);
$mmlA[$selectedUid] = $MMrow['uid'];
......@@ -1696,7 +1696,7 @@ class BackendUtility
->where(...$constraints)
->execute();
while ($record = $result->fetch()) {
while ($record = $result->fetchAssociative()) {
$rParts[] = $record['uid'];
}
}
......@@ -1777,7 +1777,7 @@ class BackendUtility
->execute();
$mmlA = [];
while ($MMrow = $result->fetch()) {
while ($MMrow = $result->fetchAssociative()) {
// Keep sorting of $selectUids
$selectedUid = array_search($MMrow['uid'], $selectUids);
$mmlA[$selectedUid] = $MMrow['uid'];
......@@ -2890,7 +2890,7 @@ class BackendUtility
->execute();
$lang = static::getLanguageService();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$row += [
'userid' => 0,
'record_pid' => 0,
......@@ -3526,7 +3526,7 @@ class BackendUtility
)
)
->execute()
->fetch();
->fetchAssociative();
return $row;
}
......
......@@ -261,7 +261,7 @@ class ContentFetcher
protected function getResult($result): array
{
$output = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
BackendUtility::workspaceOL('tt_content', $row, -99, true);
if ($row && !VersionState::cast($row['t3ver_state'] ?? 0)->equals(VersionState::DELETE_PLACEHOLDER)) {
$output[] = $row;
......
Markdown is supported
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