From 90ce80e3ff87fdabd92bb22b41a2e953c995fab0 Mon Sep 17 00:00:00 2001
From: Mathias Schreiber <mathias.schreiber@wmdb.de>
Date: Mon, 18 Apr 2016 22:55:16 +0200
Subject: [PATCH] [TASK] Doctrine: Replace occurrences of
 exec_INSERTmultipleRows

Resolves: #75758
Releases: master
Change-Id: I9ef426583b6c24369446c7736931ef3beb6b7b6f
Reviewed-on: https://review.typo3.org/47764
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
---
 .../Cache/Backend/Typo3DatabaseBackend.php    |  6 ++-
 .../Backend/Typo3DatabaseBackendTest.php      | 46 ++++++++++---------
 .../Utility/Importer/ExtensionListUtility.php | 18 +++++++-
 .../sysext/indexed_search/Classes/Indexer.php |  5 +-
 4 files changed, 50 insertions(+), 25 deletions(-)

diff --git a/typo3/sysext/core/Classes/Cache/Backend/Typo3DatabaseBackend.php b/typo3/sysext/core/Classes/Cache/Backend/Typo3DatabaseBackend.php
index f6d9df283ecb..aedce8d1928f 100644
--- a/typo3/sysext/core/Classes/Cache/Backend/Typo3DatabaseBackend.php
+++ b/typo3/sysext/core/Classes/Cache/Backend/Typo3DatabaseBackend.php
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Core\Cache\Backend;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * A caching backend which stores cache entries in database tables
@@ -157,7 +159,9 @@ class Typo3DatabaseBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend
                 $tagRow[] = $tag;
                 $tagRows[] = $tagRow;
             }
-            $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows($this->tagsTable, $fields, $tagRows);
+            GeneralUtility::makeInstance(ConnectionPool::class)
+                ->getConnectionForTable($this->tagsTable)
+                ->bulkInsert($this->tagsTable, $tagRows, $fields);
         }
     }
 
diff --git a/typo3/sysext/core/Tests/Unit/Cache/Backend/Typo3DatabaseBackendTest.php b/typo3/sysext/core/Tests/Unit/Cache/Backend/Typo3DatabaseBackendTest.php
index 4ce6d1100e59..80b5318c53f8 100644
--- a/typo3/sysext/core/Tests/Unit/Cache/Backend/Typo3DatabaseBackendTest.php
+++ b/typo3/sysext/core/Tests/Unit/Cache/Backend/Typo3DatabaseBackendTest.php
@@ -13,6 +13,9 @@ namespace TYPO3\CMS\Core\Tests\Unit\Cache\Backend;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Test case
@@ -130,27 +133,28 @@ class Typo3DatabaseBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, array('dummy'), array('Testing'));
         $this->setUpMockFrontendOfBackend($backend);
         $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, array(), array(), '', false);
-        $GLOBALS['TYPO3_DB']
-            ->expects($this->once())
-            ->method('exec_INSERTmultipleRows')
-            ->with(
-                'cf_Testing_tags',
-                $this->callback(function (array $data) {
-                    if ($data[0] === 'identifier' && $data[1] === 'tag') {
-                        return true;
-                    }
+        $connectionPool = $this->getMock(ConnectionPool::class);
+        $connection = $this->getMock(Connection::class, array(), array(), '', false);
+        $connectionPool->expects($this->once())->method('getConnectionForTable')->willReturn($connection);
+        $connection->expects($this->once())->method('bulkInsert')->with(
+            'cf_Testing_tags',
+            $this->callback(function (array $data) {
+                if ($data[0][0] !== 'anIdentifier' || $data[0][1] !== 'UnitTestTag%tag1') {
                     return false;
-                }),
-                $this->callback(function (array $data) {
-                    if ($data[0][0] !== 'anIdentifier' || $data[0][1] !== 'UnitTestTag%tag1') {
-                        return false;
-                    }
-                    if ($data[1][0] !== 'anIdentifier' || $data[1][1] !== 'UnitTestTag%tag2') {
-                        return false;
-                    }
+                }
+                if ($data[1][0] !== 'anIdentifier' || $data[1][1] !== 'UnitTestTag%tag2') {
+                    return false;
+                }
+                return true;
+            }),
+            $this->callback(function (array $data) {
+                if ($data[0] === 'identifier' && $data[1] === 'tag') {
                     return true;
-                })
-            );
+                }
+                return false;
+            })
+        );
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPool);
         $backend->set('anIdentifier', 'someData', array('UnitTestTag%tag1', 'UnitTestTag%tag2'));
     }
 
@@ -182,7 +186,7 @@ class Typo3DatabaseBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                     }
                     return false;
                 }
-            ));
+                ));
 
         $backend->set('anIdentifier', 'someData');
     }
@@ -209,7 +213,7 @@ class Typo3DatabaseBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                     }
                     return false;
                 }
-            ));
+                ));
 
         $backend->set('aIdentifier', 'someData', array(), 0);
     }
diff --git a/typo3/sysext/extensionmanager/Classes/Utility/Importer/ExtensionListUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/Importer/ExtensionListUtility.php
index 136360c084d9..f653712f7c74 100644
--- a/typo3/sysext/extensionmanager/Classes/Utility/Importer/ExtensionListUtility.php
+++ b/typo3/sysext/extensionmanager/Classes/Utility/Importer/ExtensionListUtility.php
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Extensionmanager\Utility\Importer;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Importer object for extension list
@@ -139,7 +141,13 @@ class ExtensionListUtility implements \SplObserver
         $this->parser->parseXml($zlibStream . $localExtensionListFile);
         // flush last rows to database if existing
         if (!empty($this->arrRows)) {
-            $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('tx_extensionmanager_domain_model_extension', self::$fieldNames, $this->arrRows, self::$fieldIndicesNoQuote);
+            GeneralUtility::makeInstance(ConnectionPool::class)
+                ->getConnectionForTable('tx_extensionmanager_domain_model_extension')
+                ->bulkInsert(
+                    'tx_extensionmanager_domain_model_extension',
+                    $this->arrRows,
+                    self::$fieldNames
+                );
         }
         $extensions = $this->extensionRepository->insertLastVersion($this->repositoryUid);
         $this->repositoryRepository->updateRepositoryCount($extensions, $this->repositoryUid);
@@ -156,7 +164,13 @@ class ExtensionListUtility implements \SplObserver
     {
         // flush every 50 rows to database
         if ($this->sumRecords !== 0 && $this->sumRecords % 50 === 0) {
-            $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('tx_extensionmanager_domain_model_extension', self::$fieldNames, $this->arrRows, self::$fieldIndicesNoQuote);
+            GeneralUtility::makeInstance(ConnectionPool::class)
+                ->getConnectionForTable('tx_extensionmanager_domain_model_extension')
+                ->bulkInsert(
+                    'tx_extensionmanager_domain_model_extension',
+                    $this->arrRows,
+                    self::$fieldNames
+                );
             $this->arrRows = array();
         }
         $versionRepresentations = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionStringToArray($subject->getVersion());
diff --git a/typo3/sysext/indexed_search/Classes/Indexer.php b/typo3/sysext/indexed_search/Classes/Indexer.php
index 18f043190c3d..e4b09284df78 100644
--- a/typo3/sysext/indexed_search/Classes/Indexer.php
+++ b/typo3/sysext/indexed_search/Classes/Indexer.php
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\IndexedSearch;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
@@ -2016,7 +2017,9 @@ class Indexer
                     $val['cmp'] & $this->flagBitMask
                 );
             }
-            $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('index_rel', $fields, $rows);
+            GeneralUtility::makeInstance(ConnectionPool::class)
+                ->getConnectionForTable('index_rel')
+                ->bulkInsert('index_rel', $rows, $fields);
         }
     }
 
-- 
GitLab