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
......@@ -114,7 +114,7 @@ final class MigrateFeloginPlugins implements UpgradeWizardInterface
->execute();
// Update the found record sets
while ($record = $statement->fetch()) {
while ($record = $statement->fetchAssociative()) {
$queryBuilder = $connection->createQueryBuilder();
$updateResult = $queryBuilder->update('tt_content')
->where(
......
......@@ -196,7 +196,7 @@ class FrontendUserRepositoryTest extends FunctionalTestCase
))
;
$user = $query->execute()->fetch();
$user = $query->execute()->fetchAssociative();
self::assertSame('new-password', $user['password']);
self::assertSame('', $user['felogin_forgotHash']);
......
......@@ -86,7 +86,7 @@ class CategoryCollection extends \TYPO3\CMS\Core\Category\Collection\CategoryCol
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
$collectionRecord['table_name'] = $tableName;
$collectionRecord['field_name'] = $fieldName;
......@@ -157,7 +157,7 @@ class CategoryCollection extends \TYPO3\CMS\Core\Category\Collection\CategoryCol
// Get the related records from the database
$result = $queryBuilder->execute();
while ($record = $result->fetch()) {
while ($record = $result->fetchAssociative()) {
// Overlay the record for workspaces
$pageRepository->versionOL(
$this->getItemTableName(),
......
......@@ -5434,7 +5434,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
if (is_array($cacheEntry)) {
// Cache hit
......@@ -5487,7 +5487,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
}
$result = $queryBuilder->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
/** @var VersionState $versionState */
$versionState = VersionState::cast($row['t3ver_state']);
$tsfe->sys_page->versionOL('pages', $row);
......@@ -5529,7 +5529,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
$queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($moreWhereClauses));
}
$row = $queryBuilder->execute()->fetch();
$row = $queryBuilder->execute()->fetchAssociative();
$tsfe->sys_page->versionOL('pages', $row);
if ((int)$row['doktype'] === PageRepository::DOKTYPE_RECYCLER
|| (int)$row['doktype'] === PageRepository::DOKTYPE_BE_USER_SECTION
......@@ -5692,7 +5692,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
$statement = $this->exec_getQuery($tableName, $queryConfiguration);
$tsfe = $this->getTypoScriptFrontendController();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
// Versioning preview:
$tsfe->sys_page->versionOL($tableName, $row, true);
......
......@@ -667,7 +667,7 @@ abstract class AbstractMenuContentObject
}
// Get sub-pages:
$statement = $this->parent_cObj->exec_getQuery('pages', ['pidInList' => $id, 'orderBy' => $sortingField]);
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
// When the site language configuration is in "free" mode, then the page without overlay is fetched
// (which is kind-of strange for pages, but this is what exec_getQuery() is doing)
// this means, that $row is a translated page, but hasn't been overlaid. For this reason, we fetch
......@@ -830,7 +830,7 @@ abstract class AbstractMenuContentObject
'orderBy' => $sortingField ?: $sortField . ' DESC',
'max' => $limit
]);
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
// When the site language configuration is in "free" mode, then the page without overlay is fetched
// (which is kind-of strange for pages, but this is what exec_getQuery() is doing)
// this means, that $row is a translated page, but hasn't been overlaid. For this reason, we fetch
......@@ -956,7 +956,7 @@ abstract class AbstractMenuContentObject
}
$result = $queryBuilder->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$tsfe->sys_page->versionOL('pages', $row, true);
if (is_array($row)) {
$menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
......@@ -1869,7 +1869,7 @@ abstract class AbstractMenuContentObject
throw new \UnexpectedValueException($message, 1337334849);
}
$result = [];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$this->sys_page->versionOL('tt_content', $row);
if ($this->getCurrentLanguageAspect()->doOverlays() && $basePageRow['_PAGES_OVERLAY_LANGUAGE']) {
$row = $this->sys_page->getRecordOverlay(
......
......@@ -858,7 +858,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
}
$queryBuilder->andWhere($constraint);
$page = $queryBuilder->execute()->fetch();
$page = $queryBuilder->execute()->fetchAssociative();
if ($this->whichWorkspace() > 0) {
// Fetch overlay of page if in workspace and check if it is hidden
......@@ -1280,7 +1280,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
$this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)
)
->execute()
->fetch();
->fetchAssociative();
// versionOL()?
if (!$row) {
......@@ -3341,7 +3341,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
$timeConditions
)
->execute()
->fetch();
->fetchAssociative();
if ($row) {
foreach ($timeFields as $timeField => $_) {
......
......@@ -729,7 +729,7 @@ class AbstractPlugin
$tRows[] = $this->pi_list_header();
// Make list table rows
$c = 0;
while ($this->internal['currentRow'] = $statement->fetch()) {
while ($this->internal['currentRow'] = $statement->fetchAssociative()) {
$tRows[] = $this->pi_list_row($c);
$c++;
}
......@@ -1246,7 +1246,7 @@ class AbstractPlugin
$result = $queryBuilder->execute();
$outArr = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$outArr[$row['uid']] = $row;
}
return $outArr;
......
......@@ -602,7 +602,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
$queryBuilder->createNamedParameter(PageRepository::DOKTYPE_BE_USER_SECTION, \PDO::PARAM_INT)
)
)->execute();
while ($row = $queryResult->fetch()) {
while ($row = $queryResult->fetchAssociative()) {
// Find mount point if any:
$next_id = (int)$row['uid'];
$next_MP_array = $MP_array;
......
......@@ -378,7 +378,7 @@ class UriPrefixRenderingTest extends FunctionalTestCase
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
$template = $connection->select(['uid', 'constants'], 'sys_template', ['pid' => $pageId, 'root' => 1])->fetch();
$template = $connection->select(['uid', 'constants'], 'sys_template', ['pid' => $pageId, 'root' => 1])->fetchAssociative();
if (empty($template)) {
self::fail('Cannot find root template on page with id: "' . $pageId . '"');
}
......
......@@ -302,7 +302,7 @@ class FrontendUserAuthenticationTest extends UnitTestCase
$queryBuilderFeUserProphecy->where(Argument::cetera())->shouldBeCalled()->willReturn($queryBuilderFeUserProphecyRevelation);
$statementFeUserProphecy = $this->prophesize(Statement::class);
$queryBuilderFeUserProphecy->execute()->shouldBeCalled()->willReturn($statementFeUserProphecy->reveal());
$statementFeUserProphecy->fetch()->willReturn(
$statementFeUserProphecy->fetchAssociative()->willReturn(
[
'uid' => 1,
'username' => 'existingUserName',
......
......@@ -172,7 +172,7 @@ class AbstractMenuContentObjectTest extends UnitTestCase
public function sectionIndexReturnsOverlaidRowBasedOnTheLanguageOfTheGivenPage()
{
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->fetch()->shouldBeCalledTimes(2)->willReturn(['uid' => 0, 'header' => 'NOT_OVERLAID'], false);
$statementProphet->fetchAssociative()->shouldBeCalledTimes(2)->willReturn(['uid' => 0, 'header' => 'NOT_OVERLAID'], false);
$this->prepareSectionIndexTest();
$this->subject->_set('mconf', [
......@@ -246,7 +246,7 @@ class AbstractMenuContentObjectTest extends UnitTestCase
public function sectionIndexFilters($expectedAmount, array $dataRow)
{
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->fetch()->willReturn($dataRow, false);
$statementProphet->fetchAssociative()->willReturn($dataRow, false);
$this->prepareSectionIndexTest();
$this->subject->_set('mconf', [
......@@ -315,7 +315,7 @@ class AbstractMenuContentObjectTest extends UnitTestCase
public function sectionIndexQueriesWithDifferentColPos($configuration, $colPosFromStdWrapValue, $whereClausePrefix)
{
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->fetch()->willReturn([]);
$statementProphet->fetchAssociative()->willReturn([]);
$this->prepareSectionIndexTest();
$this->subject->_set('mconf', ['sectionIndex.' => $configuration]);
......
......@@ -207,7 +207,7 @@ class ExportController extends ImportExportController
$rParts = explode(':', $ref);
if ($beUser->check('tables_select', $rParts[0])) {
$statement = $this->exec_listQueryPid($rParts[0], (int)$rParts[1]);
while ($subTrow = $statement->fetch()) {
while ($subTrow = $statement->fetchAssociative()) {
$this->export->export_addRecord($rParts[0], $subTrow);
}
}
......@@ -391,7 +391,7 @@ class ExportController extends ImportExportController
&& !$GLOBALS['TCA'][$table]['ctrl']['is_static']
) {
$statement = $this->exec_listQueryPid($table, $k);
while ($subTrow = $statement->fetch()) {
while ($subTrow = $statement->fetchAssociative()) {
$this->export->export_addRecord($table, $subTrow);
}
}
......
......@@ -70,7 +70,7 @@ class PresetRepository
}
$presets = $queryBuilder->execute();
while ($presetCfg = $presets->fetch()) {
while ($presetCfg = $presets->fetchAssociative()) {
$options[$presetCfg['uid']] = $presetCfg['title'] . ' [' . $presetCfg['uid'] . ']'
. ($presetCfg['public'] ? ' [Public]' : '')
. ($presetCfg['user_uid'] === $this->getBackendUser()->user['uid'] ? ' [Own]' : '');
......@@ -98,7 +98,7 @@ class PresetRepository
)
)
->execute()
->fetch();
->fetchAssociative();
}
/**
......
......@@ -535,7 +535,7 @@ class Import extends ImportExport
->orderBy('uid')
->execute();
$rows = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$rows[$row['uid']] = $row;
}
return $rows;
......@@ -840,7 +840,7 @@ class Import extends ImportExport
)
)
->execute()
->fetch();
->fetchAssociative();
// if no record could be found, $this->import_mapId['sys_file'][$record['file']] is pointing
// to a file, that was already there, thus a new metadata record should be created
if (is_array($recordInDatabase)) {
......
......@@ -148,7 +148,7 @@ abstract class AbstractImportExportTestCase extends FunctionalTestCase
$queryBuilder->addOrderBy('uid', 'ASC');
$result = $queryBuilder->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$export->export_addRecord($table, $this->forceStringsOnRowValues($row));
}
}
......
......@@ -293,7 +293,7 @@ class AdministrationController extends ActionController
)
)
->execute()
->fetch();
->fetchAssociative();
if (!is_array($pageHashRow)) {
$this->redirect('statistic');
......@@ -310,7 +310,7 @@ class AdministrationController extends ActionController
)
)
->execute()
->fetch();
->fetchAssociative();
$debugInfo = [];
$lexer = '';
if (is_array($debugRow)) {
......
......@@ -309,7 +309,7 @@ class SearchController extends ActionController
)
)
->execute()
->fetch();
->fetchAssociative();
$categoryTitle = LocalizationUtility::translate('indexingConfigurationHeader.' . $freeIndexUid, 'IndexedSearch');
$categoryTitle = $categoryTitle ?: $indexCfgRec['title'];
} else {
......@@ -752,7 +752,7 @@ class SearchController extends ActionController
)
)
->execute()
->fetch();
->fetchAssociative();
if ($ftdrow !== false) {
// Cut HTTP references after some length
$content = preg_replace('/(http:\\/\\/[^ ]{' . $this->settings['results.']['hrefInSummaryCropAfter'] . '})([^ ]+)/i', '$1...', $ftdrow['fulltextdata']);
......@@ -1198,7 +1198,7 @@ class SearchController extends ActionController
)
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$indexId = (int)$row['uid'];
$title = LocalizationUtility::translate('indexingConfigurations.' . $indexId, 'IndexedSearch');
$allOptions[$indexId] = $title ?: $row['title'];
......
......@@ -78,7 +78,7 @@ class AdministrationRepository
->execute()
->fetchOne();
$allRows = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$row['pcount'] = $numberOfRows;
$allRows[] = $row;
}
......@@ -172,7 +172,7 @@ class AdministrationRepository
->orderBy('item_type')
->execute();
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
$this->addAdditionalInformation($row);
$result[] = $row;
......@@ -192,7 +192,7 @@ class AdministrationRepository
)
)
->execute();
while ($row2 = $res2->fetch()) {
while ($row2 = $res2->fetchAssociative()) {
$this->addAdditionalInformation($row2);
$result[] = $row2;
}
......@@ -255,7 +255,7 @@ class AdministrationRepository
->orderBy('item_type')
->execute();
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
$itemType = $row['item_type'];
$counts[] = [
'count' => $row['count'],
......@@ -356,7 +356,7 @@ class AdministrationRepository
->orderBy('data_page_id')
->execute();
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
$this->addAdditionalInformation($row);
$result[] = $row;
......@@ -375,7 +375,7 @@ class AdministrationRepository
)
)
->execute();
while ($row2 = $res2->fetch()) {
while ($row2 = $res2->fetchAssociative()) {
$this->addAdditionalInformation($row2);
$result[] = $row2;
}
......@@ -421,7 +421,7 @@ class AdministrationRepository
->count('uid')
->execute()
->fetchOne();
$result->closeCursor();
$result->free();
// exist several statistics for this page?
if ($count === 0) {
......@@ -570,7 +570,7 @@ class AdministrationRepository
$lines = [];
// Collecting phash values (to remove local indexing for)
// Traverse the result set of phash rows selected:
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$row['icon'] = $this->makeItemTypeIcon($row['item_type']);
$this->allPhashListed[] = $row['phash'];
......@@ -594,7 +594,7 @@ class AdministrationRepository
->count('index_rel.wid')
->execute()
->fetchOne();
$wordCountResult->closeCursor();
$wordCountResult->free();
if ($mode === 'content') {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
......@@ -609,7 +609,7 @@ class AdministrationRepository
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('index_rel');
......@@ -689,7 +689,7 @@ class AdministrationRepository
->execute();
$pageIds = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
if ($begin <= 0) {
$pageIds[] = (int)$row['uid'];
}
......@@ -733,7 +733,7 @@ class AdministrationRepository
)
)
->execute();
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
$idList[] = (int)$row['page_id'];
}
......
......@@ -245,7 +245,7 @@ class IndexSearchRepository
// Now, traverse result and put the rows to be displayed into an array
// Each row should contain the fields from 'ISEC.*, IP.*' combined
// + artificial fields "show_resume" (bool) and "result_number" (counter)
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
// Set first row
if (!$c) {
$firstRow = $row;
......@@ -289,7 +289,7 @@ class IndexSearchRepository
}
}
$result->closeCursor();
$result->free();
return [
'resultRows' => $resultRows,
......@@ -641,7 +641,7 @@ class IndexSearchRepository
if ($res) {
// Get phash list by searching for it:
$phashList = [];
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
$phashList[] = $row['phash'];
}
// Here the phash list are merged with the existing result based on whether we are dealing with OR, NOT or AND operations.
......@@ -912,7 +912,7 @@ class IndexSearchRepository
)
)
->execute()
->fetch();
->fetchAssociative();
if (is_array($indexCfgRec)) {
$refs = GeneralUtility::trimExplode(',', $indexCfgRec['indexcfgs']);
......@@ -935,7 +935,7 @@ class IndexSearchRepository
)
)
->execute()
->fetch();
->fetchAssociative();
if ($idxRec) {
$list[] = $uid;
}
......@@ -949,7 +949,7 @@ class IndexSearchRepository
)
)
->execute();
while ($idxRec = $indexCfgRecordsFromPid->fetch()) {
while ($idxRec = $indexCfgRecordsFromPid->fetchAssociative()) {
$list[] = $idxRec['uid'];
}
break;
......
......@@ -1536,7 +1536,7 @@ class Indexer
[],
1
)
->fetch();
->fetchAssociative();
// If there was an indexing of the page...:
if (!empty($row)) {
if ($this->tstamp_maxAge && $row['tstamp'] + $this->tstamp_maxAge < $GLOBALS['EXEC_TIME']) {
......@@ -1601,7 +1601,7 @@ class Indexer
[],
1
)
->fetch();
->fetchAssociative();
if (!empty($row)) {
$result = $row;
......@@ -1854,7 +1854,7 @@ class Indexer
->execute();
$this->log_setTSlogMessage('Inserting words: ' . ($wordListArrayCount - $count), 1);
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
unset($wordListArray[$row['baseword']]);
}
......@@ -1896,7 +1896,7 @@ class Indexer
->execute();
$stopWords = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$stopWords[$row['wid']] = $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