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
......@@ -284,7 +284,7 @@ class InfoPageTyposcriptConfigController
$pageArray = [];
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
$this->setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
}
return $this->getList($pageArray);
......
......@@ -231,7 +231,7 @@ class PageInformationController
$this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)
)
->execute()
->fetch();
->fetchAssociative();
BackendUtility::workspaceOL('pages', $row);
// If there was found a page:
if (is_array($row)) {
......@@ -354,7 +354,7 @@ class PageInformationController
$result = $queryBuilder->execute();
$rowCount = $queryBuilder->count('uid')->execute()->fetchOne();
$count = 0;
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
BackendUtility::workspaceOL('pages', $row);
if (is_array($row)) {
$count++;
......
......@@ -420,13 +420,13 @@ class TranslationStatusController
)
->execute();
$row = $result->fetch();
$row = $result->fetchAssociative();
BackendUtility::workspaceOL('pages', $row);
if (is_array($row)) {
$row['_COUNT'] = $queryBuilder->count('uid')->execute()->fetchOne();
$row['_HIDDEN'] = $row['hidden'] || (int)$row['endtime'] > 0 && (int)$row['endtime'] < $GLOBALS['EXEC_TIME'] || $GLOBALS['EXEC_TIME'] < (int)$row['starttime'];
}
$result->closeCursor();
$result->free();
return $row;
}
......
......@@ -200,7 +200,7 @@ class MySql extends AbstractPlatform
*/
public function checkDefaultDatabaseServerCharset(Connection $connection): void
{
$defaultServerCharset = $connection->executeQuery('SHOW VARIABLES LIKE \'character_set_server\'')->fetch();
$defaultServerCharset = $connection->executeQuery('SHOW VARIABLES LIKE \'character_set_server\'')->fetchAssociative();
if (!in_array($defaultServerCharset['Value'], $this->databaseServerCharsetToCheck, true)) {
$this->messageQueue->enqueue(new FlashMessage(
......
......@@ -159,14 +159,13 @@ class PostgreSql extends AbstractPlatform
'SELECT pg_catalog.pg_encoding_to_char(pg_database.encoding) from pg_database where datname = ?',
[$connection->getDatabase()],
[\PDO::PARAM_STR]
)
->fetch();
)->fetchAssociative();
if (!in_array(strtolower($defaultDatabaseCharset['pg_encoding_to_char']), $this->databaseCharsetToCheck, true)) {
$this->messageQueue->enqueue(new FlashMessage(
sprintf(
'Checking database character set failed, got key "%s" instead of "%s"',
$defaultDatabaseCharset,
$defaultDatabaseCharset['pg_encoding_to_char'],
implode(' or ', $this->databaseCharsetToCheck)
),
'PostgreSQL database character set check failed',
......@@ -187,13 +186,13 @@ class PostgreSql extends AbstractPlatform
*/
public function checkDefaultDatabaseServerCharset(Connection $connection): void
{
$defaultServerCharset = $connection->executeQuery('SHOW SERVER_ENCODING')->fetch();
$defaultServerCharset = $connection->executeQuery('SHOW SERVER_ENCODING')->fetchAssociative();
if (!in_array(strtolower($defaultServerCharset['server_encoding']), $this->databaseCharsetToCheck, true)) {
$this->messageQueue->enqueue(new FlashMessage(
sprintf(
'Checking server character set failed, got key "%s" instead of "%s"',
$defaultServerCharset,
$defaultServerCharset['server_encoding'],
implode(' or ', $this->databaseServerCharsetToCheck)
),
'PostgreSQL database character set check failed',
......
......@@ -204,7 +204,7 @@ class DatabaseRowsUpdateWizard implements UpgradeWizardInterface, RepeatableInte
}
$statement = $queryBuilder->execute();
$rowCountWithoutUpdate = 0;
while ($row = $rowBefore = $statement->fetch()) {
while ($row = $rowBefore = $statement->fetchAssociative()) {
foreach ($updaters as $updater) {
$row = $updater->updateTableRow($table, $row);
}
......@@ -249,7 +249,7 @@ class DatabaseRowsUpdateWizard implements UpgradeWizardInterface, RepeatableInte
} else {
// Either different connections for table and sys_registry, or mssql.
// SqlServer can not run a transaction for a table if the same table is queried
// currently - our above ->fetch() main loop.
// currently - our above ->fetchAssociative() main loop.
// So, execute two distinct queries and hope for the best.
$this->updateOrDeleteRow(
$connectionForTable,
......
......@@ -103,7 +103,7 @@ class WorkspaceNewPlaceholderRemovalMigration implements RowUpdaterInterface, Lo
$queryBuilder->expr()->eq('t3ver_oid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
)
->execute()
->fetch();
->fetchAssociative();
return is_array($row) ? $row : null;
}
......
......@@ -176,7 +176,7 @@ class LinkAnalyzer
->execute();
// @todo #64091: only select rows that have content in at least one of the relevant fields (via OR)
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$this->analyzeRecord($results, $table, $fields, $row);
}
}
......@@ -287,7 +287,7 @@ class LinkAnalyzer
)
)
->execute()
->fetch();
->fetchAssociative();
if (!$row) {
// missing record: remove existing links
......
......@@ -136,7 +136,7 @@ class InternalLinktype extends AbstractLinktype
)
)
->execute()
->fetch();
->fetchAssociative();
$this->responsePage = true;
if ($row) {
if ($row['deleted'] == '1') {
......@@ -183,7 +183,7 @@ class InternalLinktype extends AbstractLinktype
)
)
->execute()
->fetch();
->fetchAssociative();
$this->responseContent = true;
// this content element exists
if ($row) {
......
......@@ -106,7 +106,7 @@ class BrokenLinkRepository
$result = [
'total' => 0
];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$result[$row['link_type']] = $row['amount'];
$result['total']+= $row['amount'];
}
......
......@@ -66,7 +66,7 @@ class PagesRepository
)
)
->execute()
->fetch();
->fetchAssociative();
if ($row !== false) {
return $this->doesRootLineContainHiddenPages($row);
......@@ -115,7 +115,7 @@ class PagesRepository
)
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$subpageId = (int)$row['uid'];
$isHidden = (bool)$row['hidden'];
if (!$isHidden || $considerHidden) {
......@@ -180,7 +180,7 @@ class PagesRepository
->execute();
$translatedPages = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$translatedPages[] = (int)$row['uid'];
}
......
......@@ -307,7 +307,7 @@ class LinkAnalyzerResult
)
->setMaxResults(1)
->execute()
->fetch()['uid'] ?: 0;
->fetchAssociative()['uid'] ?: 0;
if ($localizedPageId) {
$this->localizedPages[$identifier] = $localizedPageId;
......
......@@ -157,7 +157,7 @@ class CleanFlexFormsCommand extends Command
)
->execute();
while ($rowSub = $result->fetch()) {
while ($rowSub = $result->fetchAssociative()) {
// Traverse flexforms
$dirtyFlexFormFields = $this->compareAllFlexFormsInRecord($tableName, $rowSub['uid'], $dirtyFlexFormFields);
// Add any versions of those records
......@@ -198,7 +198,7 @@ class CleanFlexFormsCommand extends Command
->orderBy('sorting')
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$dirtyFlexFormFields = $this->findAllDirtyFlexformsInPage($row['uid'], $depth, $dirtyFlexFormFields);
}
}
......@@ -240,7 +240,7 @@ class CleanFlexFormsCommand extends Command
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
)
->execute()
->fetch();
->fetchAssociative();
if ($fullRecord[$columnName]) {
// Clean XML and check against the record fetched from the database
......
......@@ -193,7 +193,7 @@ class DeletedRecordsCommand extends Command
)
->execute();
while ($recordOnPage = $result->fetch()) {
while ($recordOnPage = $result->fetchAssociative()) {
// Register record as deleted
if ($recordOnPage[$deletedField]) {
$deletedRecords[$tableName][$recordOnPage['uid']] = $recordOnPage['uid'];
......@@ -229,7 +229,7 @@ class DeletedRecordsCommand extends Command
->orderBy('sorting')
->execute();
while ($subPage = $result->fetch()) {
while ($subPage = $result->fetchAssociative()) {
$deletedRecords = $this->findAllFlaggedRecordsInPage($subPage['uid'], $depth, $deletedRecords);
}
}
......
......@@ -186,7 +186,7 @@ If you want to get more detailed information, use the --verbose option.')
// Traverse the files and put into a large table
$allReferencesToFiles = [];
while ($record = $result->fetch()) {
while ($record = $result->fetchAssociative()) {
// Compile info string for location of reference
$infoString = $this->formatReferenceIndexEntryToString($record);
$hash = $record['hash'];
......
......@@ -78,7 +78,7 @@ class ListSysLogCommand extends Command
->orderBy('tstamp', 'DESC')
->execute();
while ($row = $rowIterator->fetch()) {
while ($row = $rowIterator->fetchAssociative()) {
$logData = unserialize($row['log_data']);
$userInformation = $row['userid'];
if (!empty($logData['originalUser'])) {
......
......@@ -183,7 +183,7 @@ If you want to get more detailed information, use the --verbose option.')
->execute();
// Traverse the references and check if the files exists
while ($record = $result->fetch()) {
while ($record = $result->fetchAssociative()) {
$fileName = $this->getFileNameWithoutAnchor($record['ref_string']);
if (empty($record['softref_key']) && !@is_file(Environment::getPublicPath() . '/' . $fileName)) {
$missingReferences[$fileName][$record['hash']] = $this->formatReferenceIndexEntryToString($record);
......@@ -216,7 +216,7 @@ If you want to get more detailed information, use the --verbose option.')
->execute();
// Traverse the references and check if the files exists
while ($record = $result->fetch()) {
while ($record = $result->fetchAssociative()) {
$fileName = $this->getFileNameWithoutAnchor($record['ref_string']);
if (!@is_file(Environment::getPublicPath() . '/' . $fileName)) {
$missingReferences[] = $fileName . ' - ' . $record['hash'] . ' - ' . $this->formatReferenceIndexEntryToString($record);
......
......@@ -245,7 +245,7 @@ If you want to get more detailed information, use the --verbose option.')
->execute();
$existingRecords = [];
while ($rec = $rowIterator->fetch()) {
while ($rec = $rowIterator->fetchAssociative()) {
$isSoftReference = !empty($rec['softref_key']);
$idx = $rec['ref_table'] . ':' . $rec['ref_uid'];
// Get referenced record:
......@@ -273,7 +273,7 @@ If you want to get more detailed information, use the --verbose option.')
)
)
->execute()
->fetch();
->fetchAssociative();
}
// Compile info string for location of reference:
$infoString = $this->formatReferenceIndexEntryToString($rec);
......
......@@ -122,7 +122,7 @@ Manual repair suggestions:
$rowCount = $queryBuilder->count('uid')->execute()->fetchOne();
if ($rowCount) {
$orphans[$tableName] = [];
while ($orphanRecord = $result->fetch()) {
while ($orphanRecord = $result->fetchAssociative()) {
$orphans[$tableName][$orphanRecord['uid']] = $orphanRecord['uid'];
}
......@@ -183,7 +183,7 @@ Manual repair suggestions:
)
->execute();
while ($rowSub = $result->fetch()) {
while ($rowSub = $result->fetchAssociative()) {
$allRecords[$tableName][$rowSub['uid']] = $rowSub['uid'];
// Add any versions of those records:
$versions = BackendUtility::selectVersionsOfRecord($tableName, $rowSub['uid'], 'uid,t3ver_wsid', null, true);
......@@ -217,7 +217,7 @@ Manual repair suggestions:
->orderBy('sorting')
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$allRecords = $this->findAllConnectedRecordsInPage((int)$row['uid'], $depth, $allRecords);
}
}
......
......@@ -442,7 +442,7 @@ class QueryGenerator
$statement = $queryBuilder->orWhere(...$likes)->execute();
$lastRow = null;
$rowArr = [];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$rowArr[] = $this->resultRowDisplay($row, $conf, $table);
$lastRow = $row;
}
......@@ -498,7 +498,7 @@ class QueryGenerator
->orderBy('title')
->execute();
$opt[] = '<option value="0">__Save to Action:__</option>';
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$opt[] = '<option value="-' . (int)$row['uid'] . '">' . htmlspecialchars($row['title']
. ' [' . (int)$row['uid'] . ']') . '</option>';
}
......@@ -1104,7 +1104,7 @@ class QueryGenerator
$queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($permsClause));
}
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
if ($begin <= 0) {
$theList .= ',' . $row['uid'];
}
......@@ -1190,7 +1190,7 @@ class QueryGenerator
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$statement = $queryBuilder->select($fieldName)->from($table)->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
if (strpos($row[$fieldName], ',') !== false) {
$checkContent = explode(',', $row[$fieldName]);
foreach ($checkContent as $singleValue) {
......@@ -1299,7 +1299,7 @@ class QueryGenerator
}
$statement = $queryBuilder->execute();
$this->tableArray[$from_table] = [];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$this->tableArray[$from_table][] = $row;
}
}
......@@ -1976,7 +1976,7 @@ class QueryGenerator
$statement = $queryBuilder->select($fieldName)
->from($table)
->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
if (strpos($row[$fieldName], ',') !== false) {
$checkContent = explode(',', $row[$fieldName]);
foreach ($checkContent as $singleValue) {
......@@ -2087,10 +2087,7 @@ class QueryGenerator
}
}
$statement = $queryBuilder->execute();
$this->tableArray[$from_table] = [];
while ($row = $statement->fetch()) {
$this->tableArray[$from_table][] = $row;
}
$this->tableArray[$from_table] = $statement->fetchAllAssociative();
}
foreach ($this->tableArray[$from_table] as $key => $val) {
......
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