[TASK] Doctrine: Migrate exec_INSERTquery 83/49383/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 4 Aug 2016 15:06:01 +0000 (17:06 +0200)
committerBenni Mack <benni@typo3.org>
Thu, 4 Aug 2016 15:43:06 +0000 (17:43 +0200)
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>
typo3/sysext/core/Classes/Database/RelationHandler.php
typo3/sysext/core/Classes/Tests/Testbase.php
typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php
typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php
typo3/sysext/install/Classes/Updates/ProcessedFileChecksumUpdate.php

index f632fcf..f2f8e0f 100644 (file)
@@ -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']);
                     }
index 199c478..5ffdfda 100644 (file)
@@ -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();
             }
         }
     }
index 8b2ef91..8b31cd6 100644 (file)
@@ -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();
     }
 }
index d7e28ce..aaa99d3 100644 (file)
@@ -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());
                 }
             }
         }
index 0bbf81a..2d9f18f 100644 (file)
@@ -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);
index 5cd291a..5b92272 100644 (file)
@@ -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')
index aed94af..1df4ae7 100644 (file)
@@ -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\'');