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