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
......@@ -133,7 +133,7 @@ class PageSlugCandidateProvider
)
->execute();
$page = $statement->fetch();
$page = $statement->fetchAssociative();
if (empty($page)) {
return null;
}
......@@ -230,7 +230,7 @@ class PageSlugCandidateProvider
$pageRepository = GeneralUtility::makeInstance(PageRepository::class, $this->context);
$isRecursiveCall = !empty($excludeUids);
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$mountPageInformation = null;
$pageIdInDefaultLanguage = (int)($languageId > 0 ? $row['l10n_parent'] : $row['uid']);
// When this page was added before via recursion, this page should be skipped
......
......@@ -95,7 +95,7 @@ class DatabaseSessionBackend implements SessionBackendInterface, HashableSession
$query->select('*')
->from($this->configuration['table'])
->where($query->expr()->eq('ses_id', $query->createNamedParameter($this->hash($sessionId), \PDO::PARAM_STR)));
$result = $query->execute()->fetch();
$result = $query->execute()->fetchAssociative();
if (!is_array($result)) {
throw new SessionNotFoundException(
'The session with identifier ' . $sessionId . ' was not found ',
......
......@@ -346,7 +346,7 @@ class DatabaseTreeDataProvider extends AbstractTableConfigurationTreeDataProvide
)
->setMaxResults(1)
->execute()
->fetch();
->fetchAssociative();
}
if (empty($nodeData)) {
$nodeData = [
......
......@@ -660,7 +660,7 @@ class ExtendedTemplateService extends TemplateService
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($templateUid, \PDO::PARAM_INT))
);
}
$row = $queryBuilder->execute()->fetch();
$row = $queryBuilder->execute()->fetchAssociative();
BackendUtility::workspaceOL('sys_template', $row);
return $row;
......@@ -679,7 +679,7 @@ class ExtendedTemplateService extends TemplateService
}
$result = $this->getTemplateQueryBuilder($pid)->execute();
$outRes = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
BackendUtility::workspaceOL('sys_template', $row);
if (is_array($row)) {
$outRes[] = $row;
......
......@@ -551,7 +551,7 @@ class TemplateService
->addOrderBy('sorting')
->setMaxResults(1)
->execute();
if ($row = $queryResult->fetch()) {
if ($row = $queryResult->fetchAssociative()) {
$this->versionOL($row);
if (is_array($row)) {
$this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']);
......@@ -656,7 +656,7 @@ class TemplateService
->execute();
// make it an associative array with the UID as key
$subTemplates = [];
while ($rowItem = $queryResult->fetch()) {
while ($rowItem = $queryResult->fetchAssociative()) {
$subTemplates[(int)$rowItem['uid']] = $rowItem;
}
// Traversing list again to ensure the sorting of the templates
......
......@@ -586,7 +586,7 @@ class ExtendedFileUtility extends BasicFileUtility
)
)
->execute()
->fetch();
->fetchAssociative();
return [
'recuid' => $fileReference['uid_foreign'],
......
......@@ -251,7 +251,7 @@ class RootlineUtility
$queryBuilder->expr()->in('t3ver_wsid', $queryBuilder->createNamedParameter([0, $this->workspaceUid], Connection::PARAM_INT_ARRAY))
)
->execute()
->fetch();
->fetchAssociative();
if (empty($row)) {
throw new PageNotFoundException('Could not fetch page data for uid ' . $uid . '.', 1343589451);
}
......@@ -354,7 +354,7 @@ class RootlineUtility
throw new PagePropertyRelationNotFoundException('Could to resolve related records for page ' . $uid . ' and foreign_table ' . htmlspecialchars($table), 1343589452);
}
$relatedUids = [];
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$relatedUids[] = $row['uid'];
}
}
......
......@@ -98,7 +98,7 @@ class Typo3DatabaseBackendTest extends FunctionalTestCase
'cache_pages',
['identifier' => 'myIdentifier']
)
->fetch();
->fetchAssociative();
// Content comes back uncompressed
self::assertSame('myCachedContent', gzuncompress($row['content']));
......
......@@ -136,7 +136,7 @@ class CategoryCollectionTest extends FunctionalTestCase
->from('tx_test_test')
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)))
->execute();
$record = $statement->fetch();
$record = $statement->fetchAssociative();
$collection->rewind();
self::assertEquals($record, $collection->current());
// Add a new record
......
......@@ -56,7 +56,7 @@ class DatabaseWriterTest extends FunctionalTestCase
'sys_log',
['request_id' => $logRecordData['request_id']]
)
->fetch();
->fetchAssociative();
self::assertEquals($logRecordData, $rowInDatabase);
}
......
......@@ -74,7 +74,7 @@ class RegistryTest extends FunctionalTestCase
'sys_registry',
['entry_namespace' => 'myExtension', 'entry_key' => 'myKey']
)
->fetch();
->fetchAssociative();
self::assertSame('myValue', unserialize($valueInDatabase['entry_value']));
}
......@@ -102,7 +102,7 @@ class RegistryTest extends FunctionalTestCase
'sys_registry',
['entry_namespace' => 'myExtension', 'entry_key' => 'myKey']
)
->fetch();
->fetchAssociative();
self::assertSame('myNewValue', unserialize($valueInDatabase['entry_value']));
}
......
......@@ -658,7 +658,7 @@ class FlexFormToolsTest extends UnitTestCase
// First db call returns $secondRow, second returns $thirdRow, which points back to $initialRow -> exception
$statementProphecy->fetchOne()->willReturn(1);
$statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
$statementProphecy->fetchAssociative()->willReturn($secondRow, $thirdRow);
$this->expectException(InvalidParentRowLoopException::class);
$this->expectExceptionCode(1464110956);
......@@ -727,7 +727,7 @@ class FlexFormToolsTest extends UnitTestCase
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow, second returns $thirdRow. $thirdRow has pid 0 and still no ds -> exception
$statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
$statementProphecy->fetchAssociative()->willReturn($secondRow, $thirdRow);
$this->expectException(InvalidParentRowRootException::class);
$this->expectExceptionCode(1464112555);
......@@ -869,7 +869,7 @@ class FlexFormToolsTest extends UnitTestCase
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow, second returns $thirdRow. $thirdRow resolves ds
$statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
$statementProphecy->fetchAssociative()->willReturn($secondRow, $thirdRow);
$expected = '{"type":"record","tableName":"aTableName","uid":1,"fieldName":"tx_templavoila_ds"}';
self::assertSame($expected, (new FlexFormTools())->getDataStructureIdentifier($fieldTca, 'aTableName', 'aFieldName', $initialRow));
......@@ -928,7 +928,7 @@ class FlexFormToolsTest extends UnitTestCase
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow. $secondRow resolves DS and does not look further up
$statementProphecy->fetch()->willReturn($secondRow);
$statementProphecy->fetchAssociative()->willReturn($secondRow);
$expected = '{"type":"record","tableName":"aTableName","uid":2,"fieldName":"tx_templavoila_ds"}';
self::assertSame($expected, (new FlexFormTools())->getDataStructureIdentifier($fieldTca, 'aTableName', 'aFieldName', $initialRow));
......@@ -991,7 +991,7 @@ class FlexFormToolsTest extends UnitTestCase
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow. $secondRow resolves DS and does not look further up
$statementProphecy->fetch()->willReturn($secondRow);
$statementProphecy->fetchAssociative()->willReturn($secondRow);
$expected = '{"type":"record","tableName":"aTableName","uid":2,"fieldName":"tx_templavoila_next_ds"}';
self::assertSame($expected, (new FlexFormTools())->getDataStructureIdentifier($fieldTca, 'aTableName', 'aFieldName', $initialRow));
......@@ -1075,7 +1075,7 @@ class FlexFormToolsTest extends UnitTestCase
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow. $secondRow resolves DS and does not look further up
$statementProphecy->fetch()->willReturn($secondRow);
$statementProphecy->fetchAssociative()->willReturn($secondRow);
$expected = '{"type":"record","tableName":"foreignTableName","uid":42,"fieldName":"foreignTableField"}';
self::assertSame($expected, (new FlexFormTools())->getDataStructureIdentifier($fieldTca, 'aTableName', 'aFieldName', $initialRow));
......
......@@ -74,7 +74,7 @@ class AbstractRepositoryTest extends UnitTestCase
public function findByUidAcceptsNumericUidInString()
{
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->fetch()->shouldBeCalled()->willReturn(['uid' => 123]);
$statementProphet->fetchAssociative()->shouldBeCalled()->willReturn(['uid' => 123]);
$queryBuilderProphet = $this->createDatabaseMock();
$queryBuilderProphet->select('*')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
......
......@@ -101,7 +101,7 @@ class DatabaseTreeDataProviderTest extends UnitTestCase
->shouldBeCalled()
->willReturn($queryBuilderProphecy->reveal());
$statementProphecy->fetch()
$statementProphecy->fetchAssociative()
->shouldBeCalled()
->willReturn(['uid' => 0, 'parent' => '']);
......
......@@ -180,7 +180,7 @@ class BackendConfigurationManager extends AbstractConfigurationManager
)
->orderBy('sorting')
->execute()
->fetch();
->fetchAssociative();
if (empty($rootPage)) {
return 0;
......@@ -213,7 +213,7 @@ class BackendConfigurationManager extends AbstractConfigurationManager
)
->orderBy('crdate')
->execute()
->fetch();
->fetchAssociative();
if (empty($rootTemplate)) {
return 0;
......@@ -297,7 +297,7 @@ class BackendConfigurationManager extends AbstractConfigurationManager
)
->orderBy('uid')
->execute();
while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
if ($begin <= 0) {
$children[] = (int)$row['uid'];
}
......
......@@ -639,7 +639,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
)
)
->execute();
if ($row = $result->fetch()) {
if ($row = $result->fetchAssociative()) {
$storagePage = $row['pid'];
$pageIdsToClear[] = $storagePage;
}
......
......@@ -105,7 +105,7 @@ class AddTest extends FunctionalTestCase
)
)
->execute()
->fetch();
->fetchAssociative();
self::assertEquals(0, $newBlogRecord['sys_language_uid']);
}
......@@ -135,7 +135,7 @@ class AddTest extends FunctionalTestCase
)
)
->execute()
->fetch();
->fetchAssociative();
self::assertEquals(-1, $newBlogRecord['sys_language_uid']);
}
......@@ -171,7 +171,7 @@ class AddTest extends FunctionalTestCase
)
)
->execute()
->fetch();
->fetchAssociative();
self::assertNull($newBlogRecord['subtitle']);
}
}
......@@ -123,7 +123,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertSame($newPostTitle, $post['title']);
self::assertEquals($countPostsOriginal + 1, $post['sorting']);
}
......@@ -155,7 +155,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertEquals(10, $post['sorting']);
$posts = $this->blog->getPosts();
......@@ -186,7 +186,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertNull($post['uid']);
$queryBuilder->resetQueryParts();
......@@ -200,7 +200,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertSame('Post9', $post['title']);
self::assertEquals(9, $post['sorting']);
}
......@@ -260,7 +260,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertSame('Post10', $post['title']);
self::assertEquals(11, $post['sorting']);
......@@ -276,7 +276,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertSame($newPostTitle, $post['title']);
self::assertEquals(6, $post['sorting']);
}
......@@ -326,7 +326,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertSame('Post10', $post['title']);
self::assertEquals(10, $post['sorting']);
}
......@@ -385,7 +385,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertSame('Post9', $post['title']);
self::assertEquals(10, $post['sorting']);
......@@ -403,7 +403,7 @@ class RelationTest extends FunctionalTestCase
)
)
->execute()
->fetch();
->fetchAssociative();
self::assertSame('MOVED POST Post10', $post['title']);
self::assertEquals(10, $post['uid']);
}
......@@ -456,7 +456,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertEquals($newTag->getUid(), $tag['uid_foreign']);
}
......@@ -510,7 +510,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertEquals(9, $tag['uid_foreign']);
$queryBuilder->resetQueryParts();
......@@ -530,7 +530,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertNull($tag['uid_foreign']);
}
......@@ -594,7 +594,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertEquals(10, $tag['uid_foreign']);
$queryBuilder->resetQueryParts();
......@@ -611,7 +611,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertEquals($newTag->getUid(), $tag['uid_foreign']);
}
......@@ -671,7 +671,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertEquals(10, $tag['uid_foreign']);
self::assertEquals(10, $tag['sorting']);
......@@ -689,7 +689,7 @@ class RelationTest extends FunctionalTestCase
)
)
->execute()
->fetch();
->fetchAssociative();
self::assertNull($tag['uid_foreign']);
}
......@@ -759,7 +759,7 @@ class RelationTest extends FunctionalTestCase
)
)->orderBy('sorting', 'DESC')
->execute()
->fetch();
->fetchAssociative();
self::assertEquals(9, $tag['uid_foreign']);
self::assertEquals(10, $tag['sorting']);
......@@ -781,7 +781,7 @@ class RelationTest extends FunctionalTestCase
)
)
->execute()
->fetch();
->fetchAssociative();
self::assertEquals(10, $tag['uid_foreign']);
}
......@@ -802,7 +802,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetch();
->fetchAssociative();
$postRepository = $this->getContainer()->get(PostRepository::class);
$post = $postRepository->findByUid(1);
......@@ -819,7 +819,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetch();
->fetchAssociative();
self::assertTrue($rawPost2['tstamp'] > $rawPost['tstamp']);
}
......
......@@ -322,7 +322,7 @@ class BulkExtensionRepositoryWriter implements \SplObserver
->execute();
$extensionUids = [];
while ($row = $queryResult->fetch()) {
while ($row = $queryResult->fetchAssociative()) {
$extensionUids[] = $row['uid'];
}
......
......@@ -211,7 +211,7 @@ class FrontendUserRepository
->setMaxResults(1)
;
$row = $query->execute()->fetch();
$row = $query->execute()->fetchAssociative();
return is_array($row) ? $row : 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