Commit cfb31933 authored by Benni Mack's avatar Benni Mack Committed by Georg Ringer
Browse files

[TASK] Migrate Doctrine DBAL fetchAll() to fetchAllAssociative()

Since TYPO3 uses the \PDO::FETCH_ASSOC fetch mode
by default, fetchAll() is the equivalent for fetchAllAssociative()
which is the new API for Doctrine 3. In order to
move towards the new Doctrine DBAL 3.x API,
this change migrates all fetchAll() calls
to fetchAllAssociative() or fetchFirstColumn().

Resolves: #94618
Releases: master
Change-Id: I2ab4db871d0b65ad07e629b54bb79b1c3b411005
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70016

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 3748cafd
......@@ -2452,7 +2452,7 @@ class DataHandler implements LoggerAwareInterface
);
}
$result = $queryBuilder->execute()->fetchAll();
$result = $queryBuilder->execute()->fetchAllAssociative();
return $result;
}
......@@ -3887,14 +3887,14 @@ class DataHandler implements LoggerAwareInterface
// If $destPid is < 0, get the pid of the record with uid equal to abs($destPid)
$tscPID = BackendUtility::getTSconfig_pidValue($table, $uid, $destPid) ?? 0;
// Get the localized records to be copied
$l10nRecords = $queryBuilder->execute()->fetchAll();
$l10nRecords = $queryBuilder->execute()->fetchAllAssociative();
if (is_array($l10nRecords)) {
$localizedDestPids = [];
// If $destPid < 0, then it is the uid of the original language record we are inserting after
if ($destPid < 0) {
// Get the localized records of the record we are inserting after
$queryBuilder->setParameter('pointer', abs($destPid), \PDO::PARAM_INT);
$destL10nRecords = $queryBuilder->execute()->fetchAll();
$destL10nRecords = $queryBuilder->execute()->fetchAllAssociative();
// Index the localized record uids by language
if (is_array($destL10nRecords)) {
foreach ($destL10nRecords as $record) {
......@@ -4312,7 +4312,7 @@ class DataHandler implements LoggerAwareInterface
)
)
->execute()
->fetchAll();
->fetchAllAssociative();
if (is_array($l10nRecords)) {
$localizedDestPids = [];
......@@ -4320,7 +4320,7 @@ class DataHandler implements LoggerAwareInterface
if ($originalRecordDestinationPid < 0) {
// Get the localized records of the record we are inserting after
$queryBuilder->setParameter('pointer', abs($originalRecordDestinationPid), \PDO::PARAM_INT);
$destL10nRecords = $queryBuilder->execute()->fetchAll();
$destL10nRecords = $queryBuilder->execute()->fetchAllAssociative();
// Index the localized record uids by language
if (is_array($destL10nRecords)) {
foreach ($destL10nRecords as $record) {
......@@ -7487,7 +7487,7 @@ class DataHandler implements LoggerAwareInterface
$subResults = $queryBuilder
->execute()
->fetchAll();
->fetchAllAssociative();
// Fetches the next record in order to calculate the in-between sortNumber
// There was a record afterwards
if (count($subResults) === 2) {
......
......@@ -310,7 +310,7 @@ class PlainDataResolver
// We thus add a general explicit order by uid here to force deterministic row returns.
$queryBuilder->addOrderBy('uid');
$sortedIds = $queryBuilder->execute()->fetchAll();
$sortedIds = $queryBuilder->execute()->fetchAllAssociative();
return array_map('intval', array_column($sortedIds, 'uid'));
}
......
......@@ -261,7 +261,7 @@ class SlugHelper
$statement = $queryBuilder->execute();
$records = $this->resolveVersionOverlays(
$statement->fetchAll()
$statement->fetchAllAssociative()
);
return count($records) === 0;
}
......@@ -294,7 +294,7 @@ class SlugHelper
$statement = $queryBuilder->execute();
$records = $this->resolveVersionOverlays(
$statement->fetchAll()
$statement->fetchAllAssociative()
);
if (count($records) === 0) {
return true;
......@@ -354,7 +354,7 @@ class SlugHelper
$statement = $queryBuilder->execute();
$records = $this->resolveVersionOverlays(
$statement->fetchAll()
$statement->fetchAllAssociative()
);
return count($records) === 0;
......
......@@ -448,7 +448,7 @@ class QueryView
// EXPLAIN is no ANSI SQL, for now this is only executed on mysql
// @todo: Move away from getSelectQuery() or model differently
$fullQueryString = 'EXPLAIN ' . $selectQueryString;
$dataRows = $connection->executeQuery('EXPLAIN ' . $selectQueryString)->fetchAll();
$dataRows = $connection->executeQuery('EXPLAIN ' . $selectQueryString)->fetchAllAssociative();
} elseif ($mQ === 'count') {
$queryBuilder = $connection->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
......@@ -459,7 +459,7 @@ class QueryView
$dataRows = [$queryBuilder->execute()->fetchOne()];
} else {
$fullQueryString = $selectQueryString;
$dataRows = $connection->executeQuery($selectQueryString)->fetchAll();
$dataRows = $connection->executeQuery($selectQueryString)->fetchAllAssociative();
}
if (!$userTsConfig['mod.']['dbint.']['disableShowSQLQuery']) {
$output .= '<h2>SQL query</h2><div><pre>' . htmlspecialchars($fullQueryString) . '</pre></div>';
......
......@@ -62,7 +62,7 @@ class SchemaIndexDefinitionListener
$sql .= ' AND ' . $connection->quoteIdentifier('INDEX_NAME') . ' = ' . $connection->quote($indexName);
}
$tableIndexes = $event->getConnection()->fetchAll($sql);
$tableIndexes = $event->getConnection()->fetchAllAssociative($sql);
$subPartColumns = array_filter(
$tableIndexes,
......
......@@ -110,7 +110,7 @@ class FileCollectionRepository
$queryBuilder->where(...$conditions);
}
$data = $queryBuilder->execute()->fetchAll();
$data = $queryBuilder->execute()->fetchAllAssociative();
if (!empty($data)) {
$result = $this->createMultipleDomainObjects($data);
}
......
......@@ -176,7 +176,7 @@ class FileIndexRepository implements SingletonInterface
$queryBuilder->expr()->eq('sha1', $queryBuilder->createNamedParameter($hash, \PDO::PARAM_STR))
)
->execute()
->fetchAll();
->fetchAllAssociative();
return $resultRows;
}
......@@ -436,7 +436,7 @@ class FileIndexRepository implements SingletonInterface
)
->orderBy('tstamp', 'ASC')
->execute()
->fetchAll();
->fetchAllAssociative();
return $rows;
}
......@@ -471,7 +471,7 @@ class FileIndexRepository implements SingletonInterface
);
}
$rows = $queryBuilder->execute()->fetchAll();
$rows = $queryBuilder->execute()->fetchAllAssociative();
return $rows;
}
......
......@@ -120,7 +120,7 @@ class FileSearchResult implements FileSearchResultInterface
if ($this->result !== null) {
return;
}
$this->result = FileSearchQuery::createForSearchDemand($this->searchDemand)->execute()->fetchAll();
$this->result = FileSearchQuery::createForSearchDemand($this->searchDemand)->execute()->fetchAllAssociative();
$this->resultCount = count($this->result);
$this->result = array_map(
function (array $fileRow) {
......
......@@ -232,7 +232,7 @@ class PersistedAliasMapper implements PersistedMappableAspectInterface, StaticMa
->select(...$this->persistenceFieldNames)
->where(...$constraints)
->execute()
->fetchAll();
->fetchAllAssociative();
// limit results to be contained in rootPageId of current Site
// (which is defining the route configuration currently being processed)
if ($this->slugUniqueInSite) {
......
......@@ -230,7 +230,7 @@ class PersistedPatternMapper implements PersistedMappableAspectInterface, Static
->select('*')
->where(...$this->createRouteFieldConstraints($queryBuilder, $values))
->execute()
->fetchAll();
->fetchAllAssociative();
// limit results to be contained in rootPageId of current Site
// (which is defining the route configuration currently being processed)
if ($this->slugUniqueInSite) {
......
......@@ -225,7 +225,7 @@ class DatabaseSessionBackend implements SessionBackendInterface, HashableSession
{
$query = $this->getQueryBuilder();
$query->select('*')->from($this->configuration['table']);
return $query->execute()->fetchAll();
return $query->execute()->fetchAllAssociative();
}
/**
......
......@@ -468,7 +468,7 @@ class DatabaseTreeDataProvider extends AbstractTableConfigurationTreeDataProvide
)
)
->execute()
->fetchAll();
->fetchAllAssociative();
if (!empty($records)) {
$relatedUids = array_column($records, 'uid');
......@@ -511,7 +511,7 @@ class DatabaseTreeDataProvider extends AbstractTableConfigurationTreeDataProvide
);
}
$records = $queryBuilder->execute()->fetchAll();
$records = $queryBuilder->execute()->fetchAllAssociative();
$uidArray = is_array($records) ? array_column($records, 'uid') : [];
return $uidArray;
......
......@@ -400,7 +400,7 @@ class ExtendedFileUtility extends BasicFileUtility
)
)
->execute()
->fetchAll();
->fetchAllAssociative();
$deleteFile = true;
if (!empty($refIndexRecords)) {
$shortcutContent = [];
......
......@@ -263,7 +263,7 @@ abstract class AbstractDataHandlerActionTestCase extends FunctionalTestCase
$entryData = (array)unserialize($entry['log_data'], ['allowed_classes' => false]);
return vsprintf($entry['details'], $entryData);
},
$statement->fetchAll()
$statement->fetchAllAssociative()
);
if ($expectedMessages !== null) {
......
......@@ -47,7 +47,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 1,
......@@ -118,7 +118,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 1,
......@@ -155,7 +155,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 6,
......@@ -192,7 +192,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 11,
......@@ -229,7 +229,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 16,
......@@ -266,7 +266,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 21,
......@@ -303,7 +303,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 26,
......@@ -340,7 +340,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 31,
......@@ -377,7 +377,7 @@ class ExpressionBuilderTest extends FunctionalTestCase
)
->orderBy('uid')
->execute()
->fetchAll();
->fetchAllAssociative();
$expected = [
0 => [
'uid' => 36,
......
......@@ -76,7 +76,7 @@ class DashboardRepository
$queryBuilder->expr()->eq('cruser_id', $queryBuilder->createNamedParameter($userId))
)
->execute()
->fetchAll();
->fetchAllAssociative();
$results = [];
foreach ($rows as $row) {
$results[] = $this->createFromRow($row);
......@@ -165,7 +165,7 @@ class DashboardRepository
->from(self::TABLE)
->where($queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($identifier)))
->execute()
->fetchAll();
->fetchAllAssociative();
if (count($row)) {
return $this->createFromRow($row[0]);
}
......
......@@ -250,7 +250,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
$queryBuilder->setMaxResults($query->getLimit());
}
try {
$rows = $queryBuilder->execute()->fetchAll();
$rows = $queryBuilder->execute()->fetchAllAssociative();
} catch (DBALException $e) {
throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074485, $e);
}
......@@ -283,14 +283,14 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
} catch (DBALException $e) {
throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064721, $e);
}
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
} elseif ($realStatement instanceof \Doctrine\DBAL\Statement) {
try {
$realStatement->execute($parameters);
} catch (DBALException $e) {
throw new SqlErrorException($e->getPrevious()->getMessage(), 1481281404, $e);
}
$rows = $realStatement->fetchAll();
$rows = $realStatement->fetchAllAssociative();
} else {
// Do a real raw query. This is very stupid, as it does not allow to use DBAL's real power if
// several tables are on different databases, so this is used with caution and could be removed
......@@ -302,7 +302,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064775, $e);
}
$rows = $statement->fetchAll();
$rows = $statement->fetchAllAssociative();
}
return $rows;
......@@ -590,7 +590,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
)
->setMaxResults(1)
->execute()
->fetchAll();
->fetchAllAssociative();
if (!empty($movedRecords)) {
$rows = $movedRecords;
}
......
......@@ -192,7 +192,7 @@ class ExtensionService implements SingletonInterface
)
->setMaxResults(2)
->execute()
->fetchAll();
->fetchAllAssociative();
if (count($pages) > 1) {
throw new Exception('There is more than one "' . $pluginSignature . '" plugin in the current page tree. Please remove one plugin or set the TypoScript configuration "plugin.tx_' . $pluginSignature . '.view.defaultPid" to a fixed page id', 1280773643);
......
......@@ -199,7 +199,7 @@ class ExtensionRepository extends Repository
)
->orderBy('position', 'DESC')
->execute()
->fetchAll();
->fetchAllAssociative();
$dataMapper = GeneralUtility::makeInstance(DataMapper::class);
return $dataMapper->map(Extension::class, $result);
......
......@@ -865,7 +865,7 @@ class FileList
)
)
->execute()
->fetchAll();
->fetchAllAssociative();
$translations = [];
foreach ($translationRecords as $record) {
......
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