From 24054fb4b6e86710e21c67c0b52bb23af685f609 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Thu, 4 Aug 2016 17:06:01 +0200 Subject: [PATCH] [TASK] Doctrine: Migrate exec_INSERTquery Change-Id: I7fff080ada226153142126bda278de9ae20282d3 Resolves: #77410 Releases: master Reviewed-on: https://review.typo3.org/49383 Reviewed-by: Sebastian Bumann <bumann.sebastian@gmail.com> Tested-by: Sebastian Bumann <bumann.sebastian@gmail.com> Tested-by: Bamboo TYPO3com <info@typo3.com> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org> --- .../core/Classes/Database/RelationHandler.php | 6 +++++- typo3/sysext/core/Classes/Tests/Testbase.php | 18 +++++++----------- .../Collection/CategoryCollectionTest.php | 19 +++++++++++++++---- .../AbstractDataHandlerActionTestCase.php | 17 ++++++++++------- .../ContentObject/ContentObjectRenderer.php | 16 ++++++++++------ .../ContentObjectRendererTest.php | 13 +++++++++++++ .../Updates/ProcessedFileChecksumUpdate.php | 18 +++++++++++++++--- 7 files changed, 75 insertions(+), 32 deletions(-) diff --git a/typo3/sysext/core/Classes/Database/RelationHandler.php b/typo3/sysext/core/Classes/Database/RelationHandler.php index f632fcfee84f..f2f8e0fe6eaa 100644 --- a/typo3/sysext/core/Classes/Database/RelationHandler.php +++ b/typo3/sysext/core/Classes/Database/RelationHandler.php @@ -658,7 +658,11 @@ class RelationHandler $insertFields['tablenames'] = $tablename; $insertFields = $this->completeOppositeUsageValues($tablename, $insertFields); } - $GLOBALS['TYPO3_DB']->exec_INSERTquery($MM_tableName, $insertFields); + GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($MM_tableName) + ->insert( + $MM_tableName, + $insertFields + ); if ($this->MM_is_foreign) { $this->updateRefIndex($val['table'], $val['id']); } diff --git a/typo3/sysext/core/Classes/Tests/Testbase.php b/typo3/sysext/core/Classes/Tests/Testbase.php index 199c4786d44a..5ffdfda9d5aa 100644 --- a/typo3/sysext/core/Classes/Tests/Testbase.php +++ b/typo3/sysext/core/Classes/Tests/Testbase.php @@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Tests; */ use TYPO3\CMS\Core\Core\Bootstrap; +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Object\ObjectManager; @@ -627,9 +628,6 @@ class Testbase ); } - /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */ - $database = $GLOBALS['TYPO3_DB']; - $fileContent = file_get_contents($path); // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept $previousValueOfEntityLoader = libxml_disable_entity_loader(true); @@ -659,16 +657,14 @@ class Testbase } $tableName = $table->getName(); - $result = $database->exec_INSERTquery($tableName, $insertArray); - if ($result === false) { - throw new Exception( - 'Error when processing fixture file: ' . $path . ' Can not insert data to table ' . $tableName . ': ' . $database->sql_error(), - 1376746262 - ); - } + $connection = (new ConnectionPool())->getConnectionForTable($tableName); + $connection->insert( + $tableName, + $insertArray + ); if (isset($table['id'])) { $elementId = (string)$table['id']; - $foreignKeys[$tableName][$elementId] = $database->sql_insert_id(); + $foreignKeys[$tableName][$elementId] = $connection->lastInsertId(); } } } diff --git a/typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php b/typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php index 8b2ef91c9285..8b31cd61d538 100644 --- a/typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php +++ b/typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php @@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Tests\Functional\Category\Collection; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -242,7 +243,10 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase $values = array( 'title' => $this->getUniqueId('title') ); - $this->database->exec_INSERTquery($this->tableName, $values); + (new ConnectionPool())->getConnectionForTable($this->tableName)->insert( + $this->tableName, + $values + ); } } @@ -260,7 +264,10 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase 'tablenames' => $this->tableName, 'fieldname' => 'categories' ); - $this->database->exec_INSERTquery('sys_category_record_mm', $values); + (new ConnectionPool())->getConnectionForTable('sys_category_record_mm')->insert( + 'sys_category_record_mm', + $values + ); } } @@ -310,7 +317,11 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase 'description' => '', 'is_dummy_record' => 1 ); - $this->database->exec_INSERTquery('sys_category', $values); - $this->categoryUid = $this->database->sql_insert_id(); + $connection = (new ConnectionPool())->getConnectionForTable('sys_category'); + $connection->insert( + 'sys_category', + $values + ); + $this->categoryUid = $connection->lastInsertId(); } } diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php b/typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php index d7e28ce048d9..aaa99d3a743e 100644 --- a/typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php +++ b/typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php @@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Functional\DataHandling; * The TYPO3 project - inspiring people to share! */ +use Doctrine\DBAL\DBALException; +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Tests\Functional\DataHandling\Framework\DataSet; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -113,13 +115,14 @@ abstract class AbstractDataHandlerActionTestCase extends \TYPO3\CMS\Core\Tests\F foreach ($dataSet->getTableNames() as $tableName) { foreach ($dataSet->getElements($tableName) as $element) { - $this->getDatabaseConnection()->exec_INSERTquery( - $tableName, - $element - ); - $sqlError = $this->getDatabaseConnection()->sql_error(); - if (!empty($sqlError)) { - $this->fail('SQL Error for table "' . $tableName . '": ' . LF . $sqlError); + $connection = (new ConnectionPool())->getConnectionForTable($tableName); + try { + $connection->insert( + $tableName, + $element + ); + } catch (DBALException $e) { + $this->fail('SQL Error for table "' . $tableName . '": ' . LF . $e->getMessage()); } } } diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 0bbf81ae0572..2d9f18fba25b 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -16,6 +16,7 @@ namespace TYPO3\CMS\Frontend\ContentObject; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Charset\CharsetConverter; +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\FrontendEditing\FrontendEditingController; use TYPO3\CMS\Core\Html\HtmlParser; use TYPO3\CMS\Core\Log\LogManager; @@ -7303,12 +7304,15 @@ class ContentObjectRenderer $theList[] = $addId; } } - $db->exec_INSERTquery('cache_treelist', [ - 'md5hash' => $requestHash, - 'pid' => $id, - 'treelist' => implode(',', $theList), - 'tstamp' => $GLOBALS['EXEC_TIME'] - ]); + GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('cache_treelist')->insert( + 'cache_treelist', + [ + 'md5hash' => $requestHash, + 'pid' => $id, + 'treelist' => implode(',', $theList), + 'tstamp' => $GLOBALS['EXEC_TIME'] + ] + ); } return implode(',', $theList); diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index 5cd291a70db8..5b922725a4f2 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -14,11 +14,14 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject; * The TYPO3 project - inspiring people to share! */ +use Prophecy\Argument; use Psr\Log\LoggerInterface; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface as CacheFrontendInterface; use TYPO3\CMS\Core\Charset\CharsetConverter; use TYPO3\CMS\Core\Core\ApplicationContext; +use TYPO3\CMS\Core\Database\Connection; +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\DatabaseConnection; use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Resource\File; @@ -1821,6 +1824,11 @@ class ContentObjectRendererTest extends UnitTestCase public function getTreeListReturnsChildPageUids() { $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(null)); + $connectionPoolProphecy = $this->prophesize(ConnectionPool::class); + GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal()); + $connectionProphecy = $this->prophesize(Connection::class); + $connectionPoolProphecy->getConnectionForTable('cache_treelist')->willReturn($connectionProphecy->reveal()); + $connectionProphecy->insert(Argument::cetera())->shouldBeCalled(); $GLOBALS['TSFE']->sys_page ->expects($this->any()) ->method('getRawRecord') @@ -1863,6 +1871,11 @@ class ContentObjectRendererTest extends UnitTestCase public function getTreeListReturnsChildPageUidsAndOriginalPidForNegativeValue() { $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->with('treelist')->will($this->returnValue(null)); + $connectionPoolProphecy = $this->prophesize(ConnectionPool::class); + GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal()); + $connectionProphecy = $this->prophesize(Connection::class); + $connectionPoolProphecy->getConnectionForTable('cache_treelist')->willReturn($connectionProphecy->reveal()); + $connectionProphecy->insert(Argument::cetera())->shouldBeCalled(); $GLOBALS['TSFE']->sys_page ->expects($this->any()) ->method('getRawRecord') diff --git a/typo3/sysext/install/Classes/Updates/ProcessedFileChecksumUpdate.php b/typo3/sysext/install/Classes/Updates/ProcessedFileChecksumUpdate.php index aed94af13fbd..1df4ae7bddd8 100644 --- a/typo3/sysext/install/Classes/Updates/ProcessedFileChecksumUpdate.php +++ b/typo3/sysext/install/Classes/Updates/ProcessedFileChecksumUpdate.php @@ -14,6 +14,7 @@ namespace TYPO3\CMS\Install\Updates; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Resource\ProcessedFile; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -86,7 +87,13 @@ This can either happen on demand, when the processed file is first needed, or by if ($storage->getDriverType() !== 'Local') { // non-local storage, we can't treat this, skip the record and mark it done - $db->exec_INSERTquery('sys_registry', array('entry_namespace' => 'ProcessedFileChecksumUpdate', 'entry_key' => $processedFileRow['uid'])); + GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_registry')->insert( + 'sys_registry', + [ + 'entry_namespace' => 'ProcessedFileChecksumUpdate', + 'entry_key' => $processedFileRow['uid'] + ] + ); continue; } @@ -132,8 +139,13 @@ This can either happen on demand, when the processed file is first needed, or by // if the rename of the file failed, keep the record, but do not bother with it again } - // remember we finished this record - $db->exec_INSERTquery('sys_registry', array('entry_namespace' => 'ProcessedFileChecksumUpdate', 'entry_key' => $processedFileRow['uid'])); + GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_registry')->insert( + 'sys_registry', + [ + 'entry_namespace' => 'ProcessedFileChecksumUpdate', + 'entry_key' => $processedFileRow['uid'] + ] + ); } $db->exec_DELETEquery('sys_registry', 'entry_namespace = \'ProcessedFileChecksumUpdate\''); -- GitLab