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
......@@ -200,7 +200,7 @@ class DefaultDataProvider implements DataProviderInterface
$statement = $queryBuilder->execute();
$results = [];
while ($record = $statement->fetch()) {
while ($record = $statement->fetchAssociative()) {
BackendUtility::workspaceOL($this->tableName, $record);
if (is_array($record)) {
$results[$record['t3ver_oid'] ?: $record['uid']] = $record;
......
......@@ -464,7 +464,7 @@ class BackendLayoutView implements SingletonInterface
)
)
->execute()
->fetch();
->fetchAssociative();
BackendUtility::workspaceOL('pages', $page);
return $page;
......
......@@ -327,7 +327,7 @@ class PageLayoutContext
)
);
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
unset($availableTranslations[(int)$row[$GLOBALS['TCA']['pages']['ctrl']['languageField']]]);
}
// If any languages are left, make selector:
......
......@@ -1446,7 +1446,7 @@ class PageLayoutView implements LoggerAwareInterface
// Flip uids:
$defaultLanguageUids = array_flip($defaultLanguageUids);
// Traverse any selected elements and unset original UID if any:
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
BackendUtility::workspaceOL('tt_content', $row);
unset($defaultLanguageUids[$row['l18n_parent']]);
}
......@@ -1585,7 +1585,7 @@ class PageLayoutView implements LoggerAwareInterface
)
);
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
unset($availableTranslations[(int)$row[$GLOBALS['TCA']['pages']['ctrl']['languageField']]]);
}
// If any languages are left, make selector:
......@@ -1627,7 +1627,7 @@ class PageLayoutView implements LoggerAwareInterface
{
$output = [];
// Traverse the result:
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
BackendUtility::workspaceOL('tt_content', $row, -99, true);
if ($row) {
// Add the row to the array:
......@@ -2022,7 +2022,7 @@ class PageLayoutView implements LoggerAwareInterface
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
BackendUtility::workspaceOL('pages', $localizedPage);
return $localizedPage['title'];
}
......
......@@ -104,7 +104,7 @@ class AvatarViewHelper extends AbstractViewHelper
)
)
->execute()
->fetch();
->fetchAssociative();
} else {
$backendUser = $GLOBALS['BE_USER']->user;
}
......
......@@ -126,7 +126,7 @@ class TcaSelectItemsTest extends UnitTestCase
/** @var Statement|ObjectProphecy $statementProphet */
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->fetch()->shouldBeCalled();
$statementProphet->fetchAssociative()->shouldBeCalled();
$queryBuilderProphet->select('foreignTable.uid')
->shouldBeCalled()
......@@ -1228,7 +1228,7 @@ class TcaSelectItemsTest extends UnitTestCase
GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
$counter = 0;
$statementProphet->fetch()->shouldBeCalled()->will(function ($args) use (&$counter) {
$statementProphet->fetchAssociative()->shouldBeCalled()->will(function ($args) use (&$counter) {
$counter++;
if ($counter >= 3) {
return false;
......@@ -1338,7 +1338,7 @@ class TcaSelectItemsTest extends UnitTestCase
GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
$counter = 0;
$statementProphet->fetch()->shouldBeCalled()->will(function ($args) use (&$counter) {
$statementProphet->fetchAssociative()->shouldBeCalled()->will(function ($args) use (&$counter) {
$counter++;
if ($counter >= 3) {
return false;
......@@ -1436,7 +1436,7 @@ class TcaSelectItemsTest extends UnitTestCase
'pid' => 23,
'icon' => 'foo.jpg',
];
$statementProphet->fetch()->shouldBeCalled()->willReturn($foreignTableRowResultOne, false);
$statementProphet->fetchAssociative()->shouldBeCalled()->willReturn($foreignTableRowResultOne, false);
$expected = $input;
$expected['processedTca']['columns']['aField']['config']['items'] = [
......@@ -2133,7 +2133,7 @@ class TcaSelectItemsTest extends UnitTestCase
GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
$counter = 0;
$statementProphet->fetch()->shouldBeCalled()->will(function ($args) use (&$counter) {
$statementProphet->fetchAssociative()->shouldBeCalled()->will(function ($args) use (&$counter) {
$counter++;
if ($counter >= 3) {
return false;
......@@ -2256,7 +2256,7 @@ class TcaSelectItemsTest extends UnitTestCase
$counter = 0;
// simulates foreign_table containing two rows
$statementProphet->fetch()->shouldBeCalled()->will(function ($args) use (&$counter) {
$statementProphet->fetchAssociative()->shouldBeCalled()->will(function ($args) use (&$counter) {
$counter++;
if ($counter >= 3) {
return false;
......@@ -2386,7 +2386,7 @@ class TcaSelectItemsTest extends UnitTestCase
$counter = 0;
// simulates foreign_table containing two rows
$statementProphet->fetch()->shouldBeCalled()->will(function ($args) use (&$counter) {
$statementProphet->fetchAssociative()->shouldBeCalled()->will(function ($args) use (&$counter) {
$counter++;
if ($counter >= 3) {
return false;
......@@ -2517,7 +2517,7 @@ class TcaSelectItemsTest extends UnitTestCase
$counter = 0;
// simulates foreign_table containing two rows
$statementProphet->fetch()->shouldBeCalled()->will(function ($args) use (&$counter) {
$statementProphet->fetchAssociative()->shouldBeCalled()->will(function ($args) use (&$counter) {
$counter++;
if ($counter >= 3) {
return false;
......
......@@ -63,7 +63,7 @@ class TcaSelectTreeItemsTest extends UnitTestCase
/** @var Statement|ObjectProphecy $statementProphet */
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->fetch()->shouldBeCalled();
$statementProphet->fetchAssociative()->shouldBeCalled();
$restrictionProphet = $this->prophesize(DefaultRestrictionContainer::class);
$restrictionProphet->removeAll()->willReturn($restrictionProphet->reveal());
......
......@@ -292,7 +292,7 @@ class BackendUtilityTest extends UnitTestCase
[$queryBuilderProphet, $connectionPoolProphet] = $this->mockDatabaseConnection('sys_category');
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->fetch()->shouldBeCalled()->willReturn(
$statementProphet->fetchAssociative()->shouldBeCalled()->willReturn(
[
'uid' => 1,
'title' => 'Category 1',
......
......@@ -149,7 +149,7 @@ class AbstractAuthenticationService implements LoggerAwareInterface
->from($dbUser['table'])
->where(...$constraints)
->execute()
->fetch();
->fetchAssociative();
}
return $user;
}
......
......@@ -1287,7 +1287,7 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
->from($this->user_table)
->where($query->expr()->eq('uid', $query->createNamedParameter($uid, \PDO::PARAM_INT)));
return $query->execute()->fetch();
return $query->execute()->fetchAssociative();
}
/**
......@@ -1306,7 +1306,7 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
->from($this->user_table)
->where($query->expr()->eq('username', $query->createNamedParameter($name, \PDO::PARAM_STR)));
return $query->execute()->fetch();
return $query->execute()->fetchAssociative();
}
/**
......
......@@ -2117,7 +2117,7 @@ TCAdefaults.sys_note.email = ' . $this->user['email'];
->from('sys_workspace')
->orderBy('title')
->execute();
while ($workspaceRecord = $result->fetch()) {
while ($workspaceRecord = $result->fetchAssociative()) {
if ($this->checkWorkspace($workspaceRecord)) {
$defaultWorkspace = (int)$workspaceRecord['uid'];
break;
......
......@@ -122,7 +122,7 @@ class GroupResolver
)
->execute();
$groups = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$groups[(int)$row['uid']] = $row;
}
return $groups;
......@@ -225,7 +225,7 @@ class GroupResolver
->execute();
$groups = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$groups[(int)$row['uid']] = $row;
}
return $groups;
......
......@@ -148,7 +148,7 @@ class Typo3DatabaseBackend extends AbstractBackend implements TaggableBackendInt
)
)
->execute()
->fetch();
->fetchAssociative();
$content = '';
if (!empty($cacheRow)) {
$content = $cacheRow['content'];
......
......@@ -113,7 +113,7 @@ class CategoryCollection extends AbstractRecordCollection implements EditableCol
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
$collectionRecord['table_name'] = $tableName;
$collectionRecord['field_name'] = $fieldName;
......@@ -185,7 +185,7 @@ class CategoryCollection extends AbstractRecordCollection implements EditableCol
$queryBuilder = $this->getCollectedRecordsQueryBuilder();
$result = $queryBuilder->execute();
while ($record = $result->fetch()) {
while ($record = $result->fetchAssociative()) {
$relatedRecords[] = $record;
}
......
......@@ -333,7 +333,7 @@ abstract class AbstractRecordCollection implements RecordCollectionInterface, Pe
->from(static::getCollectionDatabaseTable())
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
return self::create($collectionRecord, $fillItems);
}
......
......@@ -315,7 +315,7 @@ class FlexFormTools
1463833794
);
}
$row = $queryStatement->fetch();
$row = $queryStatement->fetchAssociative();
if (isset($handledUids[$row[$parentFieldName]])) {
// Row has been fetched before already -> loop detected!
throw new InvalidParentRowLoopException(
......
......@@ -3413,7 +3413,7 @@ class DataHandler implements LoggerAwareInterface
$rows = [];
$movedLiveIds = [];
$movedLiveRecords = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
if ($isTableWorkspaceEnabled && (int)$row['t3ver_state'] === VersionState::MOVE_POINTER) {
$movedLiveIds[(int)$row['t3ver_oid']] = (int)$row['uid'];
}
......@@ -5037,7 +5037,7 @@ class DataHandler implements LoggerAwareInterface
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
// Delete any further workspace overlays of the record in question, then delete the record.
$this->discardWorkspaceVersionsOfRecord($table, $row['uid']);
$this->deleteRecord($table, $row['uid'], true, $forceHardDelete);
......@@ -5220,7 +5220,7 @@ class DataHandler implements LoggerAwareInterface
);
$result = $queryBuilder->execute();
while ($record = $result->fetch()) {
while ($record = $result->fetchAssociative()) {
// Ignore workspace delete placeholders. Those records have been marked for
// deletion before - deleting them again in a workspace would revert that state.
if ((int)$this->BE_USER->workspace > 0 && BackendUtility::isTableWorkspaceEnabled($table)) {
......@@ -5562,7 +5562,7 @@ class DataHandler implements LoggerAwareInterface
);
}
$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$this->discard($table, null, $row);
}
}
......@@ -5664,7 +5664,7 @@ class DataHandler implements LoggerAwareInterface
)
)
->execute();
while ($record = $statement->fetch()) {
while ($record = $statement->fetchAssociative()) {
$this->discard($table, null, $record);
}
}
......@@ -6649,7 +6649,7 @@ class DataHandler implements LoggerAwareInterface
));
}
$row = $queryBuilder->execute()->fetch();
$row = $queryBuilder->execute()->fetchAssociative();
$this->runtimeCache->set($cacheId, $row);
return $row;
......@@ -6680,7 +6680,7 @@ class DataHandler implements LoggerAwareInterface
->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)))
->orderBy('sorting')
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
// IF admin, then it's OK
if ($this->admin || $this->BE_USER->doesUserHaveAccess($row, $perms)) {
$inList .= $row['uid'] . ',';
......@@ -6751,7 +6751,7 @@ class DataHandler implements LoggerAwareInterface
->from('pages')
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($destinationId, \PDO::PARAM_INT)))
->execute();
if ($row = $result->fetch()) {
if ($row = $result->fetchAssociative()) {
// Ensure that the moved location is used as the PID value
BackendUtility::workspaceOL('pages', $row, $this->BE_USER->workspace);
if ($row['pid'] == $id) {
......@@ -6864,7 +6864,7 @@ class DataHandler implements LoggerAwareInterface
->from('pages')
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
if ($row) {
$this->pageCache[$id] = $row;
}
......@@ -6895,7 +6895,7 @@ class DataHandler implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
return $result ?: null;
}
......@@ -6921,7 +6921,7 @@ class DataHandler implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
return $record ?: false;
}
......@@ -6942,7 +6942,7 @@ class DataHandler implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
// If record found, check page as well:
if (is_array($output)) {
// Looking up the page for record:
......@@ -7215,7 +7215,7 @@ class DataHandler implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
if (!empty($row)) {
// Traverse array of values that was inserted into the database and compare with the actually stored value:
......@@ -7405,7 +7405,7 @@ class DataHandler implements LoggerAwareInterface
->addOrderBy('uid', 'ASC')
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
if (!empty($row)) {
// The top record was the record itself, so we return its current sorting value
......@@ -7433,7 +7433,7 @@ class DataHandler implements LoggerAwareInterface
$queryBuilder->createNamedParameter(abs($pid), \PDO::PARAM_INT)
))
->execute()
->fetch();
->fetchAssociative();
// There is a previous record
if (!empty($row)) {
......@@ -7618,7 +7618,7 @@ class DataHandler implements LoggerAwareInterface
);
}
// If there is an element, find its localized record in specified localization language on this page
if ($previousRow = $queryBuilder->execute()->fetch()) {
if ($previousRow = $queryBuilder->execute()->fetchAssociative()) {
$previousLocalizedRecord = BackendUtility::getRecordLocalization($table, $previousRow['uid'], $language, 'pid=' . (int)$pid);
if (isset($previousLocalizedRecord[0]) && is_array($previousLocalizedRecord[0])) {
$previousLocalizedRecordUid = $previousLocalizedRecord[0]['uid'];
......@@ -7752,7 +7752,7 @@ class DataHandler implements LoggerAwareInterface
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
// If the current record exists (which it should...), begin comparison:
if (is_array($currentRecord)) {
$tableDetails = $connection->getSchemaManager()->listTableDetails($table);
......@@ -7937,7 +7937,7 @@ class DataHandler implements LoggerAwareInterface
$queryBuilder->select('pid')
->from($table)
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)));
if ($row = $queryBuilder->execute()->fetch()) {
if ($row = $queryBuilder->execute()->fetchAssociative()) {
return $row['pid'];
}
return false;
......@@ -7996,7 +7996,7 @@ class DataHandler implements LoggerAwareInterface
$result = $queryBuilder->execute();
$pages = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$pages[$row['uid']] = $row;
}
......@@ -8288,7 +8288,7 @@ class DataHandler implements LoggerAwareInterface
->from($table)
->where($query->expr()->eq('uid', $query->createNamedParameter(abs($pid), \PDO::PARAM_INT)))
->execute()
->fetch();
->fetchAssociative();
$pid = (int)$row['pid'];
}
return $pid;
......@@ -8478,7 +8478,7 @@ class DataHandler implements LoggerAwareInterface
->execute();
$parentPageId = 0;
while ($row_tmp = $siblings->fetch()) {
while ($row_tmp = $siblings->fetchAssociative()) {
$pageIdsThatNeedCacheFlush[] = (int)$row_tmp['uid'];
$parentPageId = (int)$row_tmp['pid'];
// Add children as well:
......@@ -8495,7 +8495,7 @@ class DataHandler implements LoggerAwareInterface
$siblingChildrenQuery->createNamedParameter($row_tmp['uid'], \PDO::PARAM_INT)
))
->execute();
while ($row_tmp2 = $siblingChildren->fetch()) {
while ($row_tmp2 = $siblingChildren->fetchAssociative()) {
$pageIdsThatNeedCacheFlush[] = (int)$row_tmp2['uid'];
}
}
......@@ -8518,7 +8518,7 @@ class DataHandler implements LoggerAwareInterface
$parentQuery->createNamedParameter($parentPageId, \PDO::PARAM_INT)
))
->execute()
->fetch();
->fetchAssociative();
if (!empty($row_tmp)) {
$pageIdsThatNeedCacheFlush[] = (int)$row_tmp['pid'];
}
......@@ -8540,7 +8540,7 @@ class DataHandler implements LoggerAwareInterface
$parentQuery->createNamedParameter($pageUid, \PDO::PARAM_INT)
))
->execute()
->fetch();
->fetchAssociative();
if (!empty($parentPageRecord)) {
$pageIdsThatNeedCacheFlush[] = (int)$parentPageRecord['pid'];
}
......@@ -8760,7 +8760,7 @@ class DataHandler implements LoggerAwareInterface
)
->execute();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$log_data = unserialize($row['log_data']);
$msg = $row['error'] . ': ' . sprintf($row['details'], $log_data[0], $log_data[1], $log_data[2], $log_data[3], $log_data[4]);
/** @var FlashMessage $flashMessage */
......@@ -9181,7 +9181,7 @@ class DataHandler implements LoggerAwareInterface
$id = $connection->lastInsertId($tableName);
if (!((int)$id > 0)) {
$table = $connection->quoteIdentifier($tableName);
$result = $connection->executeQuery('SELECT IDENT_CURRENT(\'' . $table . '\') AS id')->fetch();
$result = $connection->executeQuery('SELECT IDENT_CURRENT(\'' . $table . '\') AS id')->fetchAssociative();
if (isset($result['id']) && $result['id'] > 0) {
$id = $result['id'];
}
......@@ -9218,7 +9218,7 @@ class DataHandler implements LoggerAwareInterface
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
if ($row !== false) {
$connection->exec(
......
......@@ -186,7 +186,7 @@ class PlainDataResolver
)
->execute();
while ($version = $result->fetch()) {
while ($version = $result->fetchAssociative()) {
$liveReferenceId = $version['t3ver_oid'];
$versionId = $version['uid'];
if (isset($ids[$liveReferenceId])) {
......@@ -243,7 +243,7 @@ class PlainDataResolver
)
->execute();
while ($movedRecord = $result->fetch()) {
while ($movedRecord = $result->fetchAssociative()) {
$liveReferenceId = (int)$movedRecord['t3ver_oid'];
$movedVersionId = (int)$movedRecord['uid'];
// Substitute moved record and purge live reference
......@@ -349,7 +349,7 @@ class PlainDataResolver
->execute();
$versionIds = [];
while ($record = $result->fetch()) {
while ($record = $result->fetchAssociative()) {
$liveId = $record['uid'];
$versionIds[$liveId] = $record['t3ver_oid'];
}
......
......@@ -158,7 +158,7 @@ class ReferenceIndexUpdater
$queryBuilder->expr()->eq('workspace', $queryBuilder->createNamedParameter($workspace, \PDO::PARAM_INT))
)
->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$this->registerForUpdate($row['tablename'], (int)$row['recuid'], (int)$item['targetWorkspace']);
}
}
......
......@@ -17,7 +17,9 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Database\Query;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ForwardCompatibility\Result;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform as PostgreSqlPlatform;
......@@ -204,7 +206,7 @@ class QueryBuilder
/**
* Executes this query using the bound parameters and their types.
*
* @return Statement|int
* @return Statement|Result|ResultStatement|int
*/
public function execute()
{
......
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