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
......@@ -844,7 +844,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) {
......@@ -957,7 +957,7 @@ class QueryGenerator
}
$statement = $queryBuilder->execute();
$this->tableArray[$from_table] = [];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$this->tableArray[$from_table][] = $row;
}
}
......@@ -1602,7 +1602,7 @@ class QueryGenerator
$queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($permClause));
}
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
if ($begin <= 0) {
$theList .= ',' . $row['uid'];
}
......
......@@ -157,7 +157,7 @@ class QueryView
->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>';
}
......@@ -640,7 +640,7 @@ class QueryView
$statement = $queryBuilder->orWhere(...$likes)->execute();
$lastRow = null;
$rowArr = [];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$rowArr[] = $this->resultRowDisplay($row, $conf, $table);
$lastRow = $row;
}
......@@ -905,7 +905,7 @@ class QueryView
QueryHelper::stripLogicalOperatorPrefix($permsClause)
)
->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
if ($begin <= 0) {
$theList .= ',' . $row['uid'];
}
......@@ -985,7 +985,7 @@ class QueryView
$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) {
......@@ -1094,7 +1094,7 @@ class QueryView
}
$statement = $queryBuilder->execute();
$this->tableArray[$from_table] = [];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$this->tableArray[$from_table][] = $row;
}
}
......
......@@ -198,7 +198,7 @@ class ReferenceIndex implements LoggerAwareInterface
)
)->execute();
$currentRelationHashes = [];
while ($relation = $queryResult->fetch()) {
while ($relation = $queryResult->fetchAssociative()) {
$currentRelationHashes[$relation['hash']] = true;
}
......@@ -642,7 +642,7 @@ class ReferenceIndex implements LoggerAwareInterface
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
// Check if reference existed.
if (!is_array($referenceRecord)) {
......@@ -668,7 +668,7 @@ class ReferenceIndex implements LoggerAwareInterface
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
if (is_array($record)) {
// Get relation for single field from record
......@@ -939,7 +939,7 @@ class ReferenceIndex implements LoggerAwareInterface
$progressListener->start($queryResult->rowCount(), $tableName);
}
$tableNames[] = $tableName;
while ($record = $queryResult->fetch()) {
while ($record = $queryResult->fetchAssociative()) {
if ($progressListener) {
$progressListener->advance();
}
......@@ -1124,7 +1124,7 @@ class ReferenceIndex implements LoggerAwareInterface
)
);
}
return $queryBuilder->execute()->fetch();
return $queryBuilder->execute()->fetchAssociative();
}
/**
......
......@@ -499,7 +499,7 @@ class RelationHandler
$queryBuilder->addOrderBy($fieldName, $order);
}
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$this->itemArray[] = ['id' => $row['uid'], 'table' => $table];
$this->tableArray[$table][] = $row['uid'];
}
......@@ -575,7 +575,7 @@ class RelationHandler
$queryBuilder->orderBy($sorting_field);
$queryBuilder->addOrderBy($uidForeign_field);
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
// Default
if (!$this->MM_is_foreign) {
// If tablesnames columns exists and contain a name, then this value is the table, else it's the firstTable...
......@@ -674,7 +674,7 @@ class RelationHandler
// This is necessary if the "multiple" feature is used for the MM relations.
// $oldMMs is still needed for the in_array() search used to look if an item from $this->itemArray is in $oldMMs
$oldMMs_inclUid = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
if (!$this->MM_is_foreign && $prep) {
$oldMMs[] = [$row['tablenames'], $row[$uidForeign_field]];
} else {
......@@ -1010,7 +1010,7 @@ class RelationHandler
// Get the rows from storage
$rows = [];
$result = $queryBuilder->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$rows[(int)$row['uid']] = $row;
}
if (!empty($rows)) {
......@@ -1228,7 +1228,7 @@ class RelationHandler
);
}
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$this->results[$table][$row['uid']] = $row;
}
}
......@@ -1466,7 +1466,7 @@ class RelationHandler
->orderBy('t3ver_state', 'DESC')
->execute();
while ($version = $result->fetch()) {
while ($version = $result->fetchAssociative()) {
$versionId = $version['uid'];
if (isset($ids[$versionId])) {
unset($ids[$versionId]);
......@@ -1509,7 +1509,7 @@ class RelationHandler
->orderBy('t3ver_state', 'DESC')
->execute();
while ($version = $result->fetch()) {
while ($version = $result->fetchAssociative()) {
$versionId = $version['uid'];
$liveId = $version['t3ver_oid'];
if (isset($ids[$liveId]) && isset($ids[$versionId])) {
......@@ -1562,7 +1562,7 @@ class RelationHandler
)
->execute();
while ($version = $result->fetch()) {
while ($version = $result->fetchAssociative()) {
$liveId = $version['t3ver_oid'];
if (isset($ids[$liveId])) {
unset($ids[$liveId]);
......
......@@ -1235,7 +1235,7 @@ class ConnectionMigrator
)
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$index = $row['table'];
unset($row['table']);
$tableOptions[$index] = $row;
......
......@@ -296,7 +296,7 @@ class PageRepository implements LoggerAwareInterface
$this->where_groupAccess = '';
}
$row = $queryBuilder->execute()->fetch();
$row = $queryBuilder->execute()->fetchAssociative();
if ($row) {
$this->versionOL('pages', $row);
if (is_array($row)) {
......@@ -337,7 +337,7 @@ class PageRepository implements LoggerAwareInterface
->from('pages')
->where($queryBuilder->expr()->eq('uid', (int)$uid))
->execute()
->fetch();
->fetchAssociative();
$result = [];
if ($row) {
......@@ -559,7 +559,7 @@ class PageRepository implements LoggerAwareInterface
->execute();
// Create a list of rows ordered by values in $languageUids
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$orderedListByLanguages[$row[$languageField]] = $row;
}
......@@ -653,7 +653,7 @@ class PageRepository implements LoggerAwareInterface
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
$this->versionOL($table, $olrow);
// Merge record content by traversing all fields:
......@@ -821,7 +821,7 @@ class PageRepository implements LoggerAwareInterface
$result = $res->execute();
$pages = [];
while ($page = $result->fetch()) {
while ($page = $result->fetchAssociative()) {
$originalUid = $page['uid'];
// Versioning Preview Overlay
......@@ -1112,7 +1112,7 @@ class PageRepository implements LoggerAwareInterface
)
)
->execute()
->fetch();
->fetchAssociative();
// Only look for version overlay if page record is not supplied; This assumes
// that the input record is overlaid with preview version, if any!
......@@ -1144,7 +1144,7 @@ class PageRepository implements LoggerAwareInterface
)
)
->execute()
->fetch();
->fetchAssociative();
$this->versionOL('pages', $mountRec);
if (is_array($mountRec)) {
......@@ -1197,7 +1197,7 @@ class PageRepository implements LoggerAwareInterface
)
)
->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$validPageIds[] = (int)$row['uid'];
}
return $validPageIds;
......@@ -1227,7 +1227,7 @@ class PageRepository implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
if ($row) {
$this->versionOL($table, $row);
......@@ -1280,7 +1280,7 @@ class PageRepository implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
if ($row) {
$this->versionOL($table, $row);
......@@ -1518,7 +1518,7 @@ class PageRepository implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
if (is_array($newPidRec)) {
$workspaceId = (int)$newPidRec['t3ver_wsid'];
......@@ -1579,7 +1579,7 @@ class PageRepository implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter((int)$row['t3ver_oid'], \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
}
if ($wsAlt = $this->getWorkspaceVersionOfRecord($this->versioningWorkspaceId, $table, $row['uid'], $fieldNames, $bypassEnableFieldsCheck)) {
if (is_array($wsAlt)) {
......@@ -1672,7 +1672,7 @@ class PageRepository implements LoggerAwareInterface
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
if (is_array($row)) {
return (int)$row['pid'];
......@@ -1730,7 +1730,7 @@ class PageRepository implements LoggerAwareInterface
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
// If version found, check if it could have been selected with enableFields on
// as well:
......
......@@ -168,7 +168,7 @@ class Registry implements SingletonInterface
'sys_registry',
['entry_namespace' => $namespace]
);
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$this->entries[$namespace][$row['entry_key']] = unserialize($row['entry_value']);
}
$this->loadedNamespaces[$namespace] = true;
......
......@@ -152,7 +152,7 @@ abstract class AbstractRepository implements RepositoryInterface, SingletonInter
$result = $queryBuilder->execute();
// fetch all records and create objects out of them
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$items[] = $this->createDomainObject($row);
}
return $items;
......@@ -210,7 +210,7 @@ abstract class AbstractRepository implements RepositoryInterface, SingletonInter
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
)
->execute()
->fetch();
->fetchAssociative();
if (!is_array($row)) {
throw new \RuntimeException('Could not find row with UID "' . $uid . '" in table "' . $this->table . '"', 1314354065);
}
......
......@@ -84,7 +84,7 @@ class CategoryBasedFileCollection extends AbstractFileCollection
)
->execute();
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
while ($record = $statement->fetch()) {
while ($record = $statement->fetchAssociative()) {
$this->add($resourceFactory->getFileObject((int)$record['file']));
}
}
......
......@@ -61,7 +61,7 @@ class FileCollectionRepository
->from($this->table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
if (is_array($data)) {
$object = $this->createDomainObject($data);
}
......
......@@ -101,7 +101,7 @@ class FileRepository extends AbstractRepository
->orderBy('sorting_foreign')
->execute();
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
$referenceUids[] = $row['uid'];
}
} else {
......
......@@ -93,7 +93,7 @@ class FileIndexRepository implements SingletonInterface
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($fileUid, \PDO::PARAM_INT))
)
->execute()
->fetch();
->fetchAssociative();
return is_array($row) ? $row : false;
}
......@@ -120,7 +120,7 @@ class FileIndexRepository implements SingletonInterface
$queryBuilder->expr()->eq('identifier_hash', $queryBuilder->createNamedParameter($identifierHash))
)
->execute()
->fetch();
->fetchAssociative();
return is_array($row) ? $row : false;
}
......@@ -208,7 +208,7 @@ class FileIndexRepository implements SingletonInterface
->execute();
$resultRows = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$resultRows[$row['identifier']] = $row;
}
......@@ -281,7 +281,7 @@ class FileIndexRepository implements SingletonInterface
$result = $queryBuilder->execute();
$fileRecords = [];
while ($fileRecord = $result->fetch()) {
while ($fileRecord = $result->fetchAssociative()) {
$fileRecords[$fileRecord['identifier']] = $fileRecord;
}
......
......@@ -121,7 +121,7 @@ class MetaDataRepository implements SingletonInterface
$queryBuilder->expr()->in('sys_language_uid', $queryBuilder->createNamedParameter([0, -1], Connection::PARAM_INT_ARRAY))
)
->execute()
->fetch();
->fetchAssociative();
if (empty($record)) {
return [];
......
......@@ -134,7 +134,7 @@ class ProcessedFileRepository extends AbstractRepository implements LoggerAwareI
)
)
->execute()
->fetch();
->fetchAssociative();
if ($databaseRow) {
$processedFileObject = $this->createDomainObject($databaseRow);
......@@ -244,7 +244,7 @@ class ProcessedFileRepository extends AbstractRepository implements LoggerAwareI
)
)
->execute()
->fetch();
->fetchAssociative();
if (is_array($databaseRow)) {
$processedFile = $this->createDomainObject($databaseRow);
......@@ -279,7 +279,7 @@ class ProcessedFileRepository extends AbstractRepository implements LoggerAwareI
->execute();
$itemList = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$itemList[] = $this->createDomainObject($row);
}
return $itemList;
......@@ -313,7 +313,7 @@ class ProcessedFileRepository extends AbstractRepository implements LoggerAwareI
$errorCount = 0;
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
if ($storageUid && (int)$storageUid !== (int)$row['storage']) {
continue;
}
......
......@@ -143,7 +143,7 @@ class ResourceFactory implements SingletonInterface
)
)
->execute()
->fetch();
->fetchAssociative();
if (empty($recordData)) {
throw new \InvalidArgumentException('No collection found for given UID: "' . $uid . '"', 1314085992);
}
......@@ -497,7 +497,7 @@ class ResourceFactory implements SingletonInterface
)
)
->execute()
->fetch();
->fetchAssociative();
}
return $fileReferenceData;
}
......
......@@ -17,6 +17,9 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Resource\Search;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ForwardCompatibility\Result;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
......@@ -50,7 +53,7 @@ class FileSearchQuery
private $additionalRestrictions = [];
/**
* @var \Doctrine\DBAL\Driver\Statement|int
* @var Statement|Result|ResultStatement|int
*/
private $result;
......
......@@ -146,7 +146,7 @@ class StorageRepository implements LoggerAwareInterface
->execute();
$this->storageRowCache = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
if (!empty($row['uid'])) {
$this->storageRowCache[$row['uid']] = $row;
}
......
......@@ -69,7 +69,7 @@ class SynchronizeFolderRelations
)
->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$folder = preg_replace(sprintf('/^%s/', preg_quote($sourceIdentifier, '/')), $targetIdentifier, $row['folder']) ?? '';
if ($folder !== '') {
$queryBuilder = $this->getPreparedQueryBuilder('sys_file_collection');
......@@ -110,7 +110,7 @@ class SynchronizeFolderRelations
)
->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$path = preg_replace(sprintf('/^%s/', preg_quote($sourceIdentifier, '/')), $targetIdentifier, $row['path']) ?? '';
if ($path !== '') {
$queryBuilder = $this->getPreparedQueryBuilder('sys_filemounts');
......
......@@ -203,7 +203,7 @@ class PersistedAliasMapper implements PersistedMappableAspectInterface, StaticMa
$queryBuilder->createNamedParameter($value, \PDO::PARAM_INT)
))
->execute()
->fetch();
->fetchAssociative();
return $result !== false ? $result : null;
}
......
......@@ -217,7 +217,7 @@ class PersistedPatternMapper implements PersistedMappableAspectInterface, Static
$queryBuilder->createNamedParameter($value, \PDO::PARAM_INT)
))
->execute()
->fetch();
->fetchAssociative();
return $result !== false ? $result : null;
}
......
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