From 8afa34421b5b9c81a76e9dc75442cc19310e6e16 Mon Sep 17 00:00:00 2001
From: Wouter Wolters <typo3@wouterwolters.nl>
Date: Sat, 3 Sep 2016 11:27:48 +0200
Subject: [PATCH] [TASK] Cleanup and deprecate TYPO3_DB occurrences

All instances of $GLOBALS[TYPO3_DB] in the TYPO3 Core classes
except for certain highly used functionalities have been removed.

The places where the TYPO3 Core is expected to have subclasses
within extensions have been marked for deprecation.

Resolves: #78224
Releases: master
Change-Id: Ie65878264679b93940ac9fb86c4758576d98c550
Reviewed-on: https://review.typo3.org/49824
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
---
 .../Classes/Module/AbstractFunctionModule.php |  2 +
 .../Classes/Module/BaseScriptClass.php        |  2 +
 .../backend/Classes/View/PageLayoutView.php   |  9 ---
 .../FormDataProvider/DatabaseEditRowTest.php  |  3 -
 .../Collection/CategoryCollection.php         | 10 ---
 .../Collection/StaticRecordCollection.php     | 10 ---
 .../core/Classes/DataHandling/DataHandler.php |  9 ---
 .../Resource/Index/MetaDataRepository.php     | 10 ---
 .../Resource/ProcessedFileRepository.php      |  6 --
 .../core/Classes/Resource/ResourceFactory.php |  9 ---
 .../core/Classes/Resource/ResourceStorage.php |  9 ---
 .../Deprecation-78224-TYPO3_DBOccurrences.rst | 40 ++++++++++++
 .../Unit/DataHandling/DataHandlerTest.php     |  9 ---
 .../FrontendRestrictionContainerTest.php      |  7 ---
 .../Domain/Repository/ExtensionRepository.php |  2 +-
 .../Classes/Utility/InstallUtility.php        |  8 ---
 .../feedit/Classes/FrontendEditPanel.php      | 13 +---
 .../Collection/CategoryCollection.php         | 10 ---
 .../ContentObject/ContentContentObject.php    | 11 ----
 .../Classes/Plugin/AbstractPlugin.php         |  3 +-
 .../frontend/Classes/View/AdminPanelView.php  | 10 ---
 .../Controller/Action/Tool/CleanUp.php        |  3 -
 .../Controller/Action/Tool/TestSetup.php      | 17 -----
 .../Controller/Action/Tool/UpgradeWizard.php  | 12 ----
 .../Database/DatabaseConnectionMock.php       | 63 -------------------
 .../sysext/sys_action/Classes/ActionTask.php  | 10 ---
 .../Classes/Domain/Record/AbstractRecord.php  |  8 ---
 .../Classes/ExtDirect/ExtDirectServer.php     |  9 ---
 .../Classes/Service/StagesService.php         |  8 ---
 29 files changed, 49 insertions(+), 273 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-78224-TYPO3_DBOccurrences.rst
 delete mode 100644 typo3/sysext/install/Classes/Database/DatabaseConnectionMock.php

diff --git a/typo3/sysext/backend/Classes/Module/AbstractFunctionModule.php b/typo3/sysext/backend/Classes/Module/AbstractFunctionModule.php
index ff30d772f5f5..d6b9b7fac785 100644
--- a/typo3/sysext/backend/Classes/Module/AbstractFunctionModule.php
+++ b/typo3/sysext/backend/Classes/Module/AbstractFunctionModule.php
@@ -297,9 +297,11 @@ abstract class AbstractFunctionModule
 
     /**
      * @return DatabaseConnection
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use the Doctrine DBAL layer via the ConnectionPool class
      */
     protected function getDatabaseConnection()
     {
+        GeneralUtility::logDeprecatedFunction();
         return $GLOBALS['TYPO3_DB'];
     }
 
diff --git a/typo3/sysext/backend/Classes/Module/BaseScriptClass.php b/typo3/sysext/backend/Classes/Module/BaseScriptClass.php
index 06473463f7ca..7d3b6ad8d2fd 100644
--- a/typo3/sysext/backend/Classes/Module/BaseScriptClass.php
+++ b/typo3/sysext/backend/Classes/Module/BaseScriptClass.php
@@ -391,9 +391,11 @@ class BaseScriptClass
 
     /**
      * @return DatabaseConnection
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use the Doctrine DBAL layer via the ConnectionPool class
      */
     protected function getDatabaseConnection()
     {
+        GeneralUtility::logDeprecatedFunction();
         return $GLOBALS['TYPO3_DB'];
     }
 
diff --git a/typo3/sysext/backend/Classes/View/PageLayoutView.php b/typo3/sysext/backend/Classes/View/PageLayoutView.php
index 2bee52803066..6ede5cb6f05a 100644
--- a/typo3/sysext/backend/Classes/View/PageLayoutView.php
+++ b/typo3/sysext/backend/Classes/View/PageLayoutView.php
@@ -20,7 +20,6 @@ use TYPO3\CMS\Backend\Controller\PageLayoutController;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Database\Query\QueryHelper;
 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
@@ -2547,14 +2546,6 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
         return $GLOBALS['BE_USER'];
     }
 
-    /**
-     * @return DatabaseConnection
-     */
-    protected function getDatabase()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
-
     /**
      * @return PageLayoutController
      */
diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseEditRowTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseEditRowTest.php
index cec193076aec..f431ff4dfce1 100644
--- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseEditRowTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseEditRowTest.php
@@ -37,9 +37,6 @@ class DatabaseEditRowTest extends UnitTestCase
 
     protected function setUp()
     {
-        $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
-
         $this->subject = $this->getMockBuilder(DatabaseEditRow::class)
             ->setMethods(['getDatabaseRow'])
             ->getMock();
diff --git a/typo3/sysext/core/Classes/Category/Collection/CategoryCollection.php b/typo3/sysext/core/Classes/Category/Collection/CategoryCollection.php
index 66750e674075..773c3a610885 100644
--- a/typo3/sysext/core/Classes/Category/Collection/CategoryCollection.php
+++ b/typo3/sysext/core/Classes/Category/Collection/CategoryCollection.php
@@ -331,14 +331,4 @@ class CategoryCollection extends AbstractRecordCollection implements EditableCol
     {
         return self::$storageItemsField;
     }
-
-    /**
-     * Gets the database object.
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected static function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
diff --git a/typo3/sysext/core/Classes/Collection/StaticRecordCollection.php b/typo3/sysext/core/Classes/Collection/StaticRecordCollection.php
index a74cf6474f07..8aca02bc9cdd 100644
--- a/typo3/sysext/core/Classes/Collection/StaticRecordCollection.php
+++ b/typo3/sysext/core/Classes/Collection/StaticRecordCollection.php
@@ -197,14 +197,4 @@ class StaticRecordCollection extends AbstractRecordCollection implements Editabl
         }
         return $relatedRecords;
     }
-
-    /**
-     * Gets the database object.
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index 895e5435839d..51ea6f64c107 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -24,7 +24,6 @@ use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
 use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Database\Query\QueryHelper;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
@@ -664,13 +663,6 @@ class DataHandler
      */
     protected static $recordPidsForDeletedRecords = [];
 
-    /**
-     * Database layer. Identical to $GLOBALS['TYPO3_DB']
-     *
-     * @var DatabaseConnection
-     */
-    protected $databaseConnection;
-
     /**
      * Runtime Cache to store and retrieve data computed for a single request
      *
@@ -690,7 +682,6 @@ class DataHandler
      */
     public function __construct()
     {
-        $this->databaseConnection = $GLOBALS['TYPO3_DB'];
         $this->runtimeCache = $this->getRuntimeCache();
     }
 
diff --git a/typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php b/typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php
index f4a2c8add811..7bdd56836cf6 100644
--- a/typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php
+++ b/typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php
@@ -45,16 +45,6 @@ class MetaDataRepository implements SingletonInterface
      */
     protected $tableFields = [];
 
-    /**
-     * Wrapper method for getting DatabaseConnection
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
-
     /**
      * Returns array of meta-data properties
      *
diff --git a/typo3/sysext/core/Classes/Resource/ProcessedFileRepository.php b/typo3/sysext/core/Classes/Resource/ProcessedFileRepository.php
index d1fcfd8532c3..5068248e593e 100644
--- a/typo3/sysext/core/Classes/Resource/ProcessedFileRepository.php
+++ b/typo3/sysext/core/Classes/Resource/ProcessedFileRepository.php
@@ -41,18 +41,12 @@ class ProcessedFileRepository extends AbstractRepository
      */
     protected $table = 'sys_file_processedfile';
 
-    /**
-     * @var \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected $databaseConnection;
-
     /**
      * Creates this object.
      */
     public function __construct()
     {
         parent::__construct();
-        $this->databaseConnection = $GLOBALS['TYPO3_DB'];
     }
 
     /**
diff --git a/typo3/sysext/core/Classes/Resource/ResourceFactory.php b/typo3/sysext/core/Classes/Resource/ResourceFactory.php
index c8692fb89d4f..82f61b131aae 100644
--- a/typo3/sysext/core/Classes/Resource/ResourceFactory.php
+++ b/typo3/sysext/core/Classes/Resource/ResourceFactory.php
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Core\Resource;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -691,12 +690,4 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
     {
         return GeneralUtility::makeInstance(Index\Indexer::class, $storage);
     }
-
-    /**
-     * @return DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
diff --git a/typo3/sysext/core/Classes/Resource/ResourceStorage.php b/typo3/sysext/core/Classes/Resource/ResourceStorage.php
index eaa191da51fd..c2fddce139fb 100644
--- a/typo3/sysext/core/Classes/Resource/ResourceStorage.php
+++ b/typo3/sysext/core/Classes/Resource/ResourceStorage.php
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Resource;
  */
 
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
@@ -2999,12 +2998,4 @@ class ResourceStorage implements ResourceStorageInterface
     {
         return $this->isDefault;
     }
-
-    /**
-     * @return DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-78224-TYPO3_DBOccurrences.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-78224-TYPO3_DBOccurrences.rst
new file mode 100644
index 000000000000..79cfceb8c0fd
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-78224-TYPO3_DBOccurrences.rst
@@ -0,0 +1,40 @@
+.. include:: ../../Includes.txt
+
+==========================================
+Deprecation: #78224 - TYPO3_DB occurrences
+==========================================
+
+See :forge:`78224`
+
+Description
+===========
+
+The TYPO3_DB shorthand functionality has been removed for most of the TYPO3 Core PHP classes, excepted for the following locations:
+
+* AbstractPlugin->databaseConnection (protected property)
+* AbstractFunctionModule::getDatabaseConnection()
+* BaseScriptClass::getDatabaseConnection()
+
+For these occurrences extensions might extend the base functionality (e.g. for plugins or modules) and the call to the property and
+protected methods still work.
+
+Calling `$GLOBALS[TYPO3_DB]` is still possible but discouraged.
+
+
+Impact
+======
+
+Calling any of the methods above will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any TYPO3 instances with references to TYPO3_DB or references to the occurrences mentioned above.
+
+
+Migration
+=========
+
+Use the ConnectionPool and the QueryBuilder classes to achieve future-proof and proper database abstraction for future TYPO3
+versions.
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
index 0e2c1f5e1644..599ecbf03eb8 100644
--- a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
+++ b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\DataHandler;
  */
 
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\Tests\AccessibleObjectInterface;
 use TYPO3\CMS\Core\Tests\Unit\DataHandling\Fixtures\AllowAccessHookFixture;
@@ -42,11 +41,6 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     protected $backEndUser;
 
-    /**
-     * @var DatabaseConnection|\PHPUnit_Framework_MockObject_MockObject
-     */
-    protected $mockDatabaseConnection;
-
     /**
      * Set up the tests
      */
@@ -55,8 +49,6 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $GLOBALS['TCA'] = [];
         $this->singletonInstances = GeneralUtility::getSingletonInstances();
         $this->backEndUser = $this->createMock(BackendUserAuthentication::class);
-        $this->mockDatabaseConnection = $this->createMock(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $this->mockDatabaseConnection;
         $this->subject = $this->getAccessibleMock(DataHandler::class, ['dummy']);
         $this->subject->start([], '', $this->backEndUser);
     }
@@ -275,7 +267,6 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function inputValueCheckDoesNotCallGetDateTimeFormatsForNonDatetimeFields($tcaFieldConf)
     {
-        $this->mockDatabaseConnection->expects($this->never())->method('getDateTimeFormats');
         $this->subject->_call('checkValueForInput', '', $tcaFieldConf, '', 0, 0, '');
     }
 
diff --git a/typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendRestrictionContainerTest.php b/typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendRestrictionContainerTest.php
index 12087a8fbbae..2cf9c8381385 100644
--- a/typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendRestrictionContainerTest.php
+++ b/typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendRestrictionContainerTest.php
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
 use TYPO3\CMS\Frontend\Page\PageRepository;
 
@@ -171,14 +170,8 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
         $typoScriptFrontendController->gr_list = $feGroupList;
         $typoScriptFrontendController->sys_page = $pageRepository;
 
-        $dbMock = $this->getMockBuilder(DatabaseConnection::class)
-            ->setMethods(['quoteStr'])
-            ->getMock();
-        $dbMock->expects($this->any())->method('quoteStr')->willReturnArgument(0);
-
         $GLOBALS['TSFE'] = $typoScriptFrontendController;
         $GLOBALS['SIM_ACCESS_TIME'] = 42;
-        $GLOBALS['TYPO3_DB'] = $dbMock;
 
         $subject = new FrontendRestrictionContainer();
         $expression = $subject->buildExpression([$tableName => ''], $this->expressionBuilder);
diff --git a/typo3/sysext/extensionmanager/Classes/Domain/Repository/ExtensionRepository.php b/typo3/sysext/extensionmanager/Classes/Domain/Repository/ExtensionRepository.php
index ea9e90d22e44..509036a1fa9f 100644
--- a/typo3/sysext/extensionmanager/Classes/Domain/Repository/ExtensionRepository.php
+++ b/typo3/sysext/extensionmanager/Classes/Domain/Repository/ExtensionRepository.php
@@ -320,7 +320,7 @@ class ExtensionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
     /**
      * Sets current_version = 1 for all extensions where the extension version is maximal.
      *
-     * For performance reasons, the "native" TYPO3_DB is used here directly.
+     * For performance reasons, the "native" database connection is used here directly.
      *
      * @param int $repositoryUid
      * @return void
diff --git a/typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
index f08f7929a298..5beccb2ea46f 100644
--- a/typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
+++ b/typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
@@ -718,12 +718,4 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
     {
         $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionFileImport', [$destinationAbsolutePath, $this]);
     }
-
-    /**
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
diff --git a/typo3/sysext/feedit/Classes/FrontendEditPanel.php b/typo3/sysext/feedit/Classes/FrontendEditPanel.php
index ee15e6935301..9cda05037666 100644
--- a/typo3/sysext/feedit/Classes/FrontendEditPanel.php
+++ b/typo3/sysext/feedit/Classes/FrontendEditPanel.php
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Feedit;
  */
 use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
@@ -45,13 +44,6 @@ class FrontendEditPanel
      */
     protected $frontendController;
 
-    /**
-     * Property for accessing DatabaseConnection centrally
-     *
-     * @var DatabaseConnection
-     */
-    protected $databaseConnection;
-
     /**
      * @var FrontendBackendUserAuthentication
      */
@@ -65,13 +57,12 @@ class FrontendEditPanel
     /**
      * Constructor for the edit panel
      *
-     * @param DatabaseConnection $databaseConnection
+     * @param mixed $_ Previous the database connection
      * @param TypoScriptFrontendController $frontendController
      * @param FrontendBackendUserAuthentication $backendUser
      */
-    public function __construct(DatabaseConnection $databaseConnection = null, TypoScriptFrontendController $frontendController = null, FrontendBackendUserAuthentication $backendUser = null)
+    public function __construct($_ = null, TypoScriptFrontendController $frontendController = null, FrontendBackendUserAuthentication $backendUser = null)
     {
-        $this->databaseConnection = $databaseConnection ?: $GLOBALS['TYPO3_DB'];
         $this->frontendController = $frontendController ?: $GLOBALS['TSFE'];
         $this->backendUser = $backendUser ?: $GLOBALS['BE_USER'];
         $this->cObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
diff --git a/typo3/sysext/frontend/Classes/Category/Collection/CategoryCollection.php b/typo3/sysext/frontend/Classes/Category/Collection/CategoryCollection.php
index f01c19fba46d..5bd8c96ad660 100644
--- a/typo3/sysext/frontend/Classes/Category/Collection/CategoryCollection.php
+++ b/typo3/sysext/frontend/Classes/Category/Collection/CategoryCollection.php
@@ -176,14 +176,4 @@ class CategoryCollection extends \TYPO3\CMS\Core\Category\Collection\CategoryCol
     {
         return $GLOBALS['TSFE'];
     }
-
-    /**
-     * Returns the database connection
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected static function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php
index d210d8f3b4e0..cf962e462f3d 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Frontend\ContentObject;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
@@ -134,16 +133,6 @@ class ContentContentObject extends AbstractContentObject
         return $theValue;
     }
 
-    /**
-     * Returns the database connection
-     *
-     * @return DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
-
     /**
      * Returns the frontend controller
      *
diff --git a/typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php b/typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php
index 56477a76e63e..96fea2a99390 100644
--- a/typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php
+++ b/typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php
@@ -229,6 +229,7 @@ class AbstractPlugin
      * Property for accessing DatabaseConnection centrally
      *
      * @var DatabaseConnection
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use the Doctrine DBAL layer via the ConnectionPool class
      */
     protected $databaseConnection;
 
@@ -237,7 +238,7 @@ class AbstractPlugin
      * Initializes $this->piVars if $this->prefixId is set to any value
      * Will also set $this->LLkey based on the config.language setting.
      *
-     * @param DatabaseConnection $databaseConnection
+     * @param DatabaseConnection $databaseConnection, deprecated in TYPO3 v8, will be removed in TYPO3 v9
      * @param TypoScriptFrontendController $frontendController
      */
     public function __construct(DatabaseConnection $databaseConnection = null, TypoScriptFrontendController $frontendController = null)
diff --git a/typo3/sysext/frontend/Classes/View/AdminPanelView.php b/typo3/sysext/frontend/Classes/View/AdminPanelView.php
index eaafce3775f5..f2383aa5939c 100644
--- a/typo3/sysext/frontend/Classes/View/AdminPanelView.php
+++ b/typo3/sysext/frontend/Classes/View/AdminPanelView.php
@@ -789,16 +789,6 @@ class AdminPanelView
         return $GLOBALS['BE_USER'];
     }
 
-    /**
-     * Returns the database connection
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
-
     /**
      * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
      */
diff --git a/typo3/sysext/install/Classes/Controller/Action/Tool/CleanUp.php b/typo3/sysext/install/Classes/Controller/Action/Tool/CleanUp.php
index 2112cf88e6e2..f2fbc3ca5fda 100644
--- a/typo3/sysext/install/Classes/Controller/Action/Tool/CleanUp.php
+++ b/typo3/sysext/install/Classes/Controller/Action/Tool/CleanUp.php
@@ -302,9 +302,6 @@ class CleanUp extends Action\AbstractAction
      */
     protected function clearProcessedFiles()
     {
-        // make the DB available
-        $GLOBALS['TYPO3_DB'] = $this->getDatabaseConnection();
-
         $repository = GeneralUtility::makeInstance(ProcessedFileRepository::class);
         $failedDeletions = $repository->removeAll();
         if ($failedDeletions) {
diff --git a/typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php b/typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php
index 82e1b6f458a1..2b81cccd3dfd 100644
--- a/typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php
+++ b/typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php
@@ -223,7 +223,6 @@ class TestSetup extends Action\AbstractAction
      */
     protected function convertImageFormatsToJpg()
     {
-        $this->setUpDatabaseConnectionMock();
         $imageProcessor = $this->initializeImageProcessor();
         $parseTimeStart = GeneralUtility::milliseconds();
 
@@ -266,7 +265,6 @@ class TestSetup extends Action\AbstractAction
      */
     protected function writeGifAndPng()
     {
-        $this->setUpDatabaseConnectionMock();
         $imageProcessor = $this->initializeImageProcessor();
         $parseTimeStart = GeneralUtility::milliseconds();
 
@@ -332,7 +330,6 @@ class TestSetup extends Action\AbstractAction
      */
     protected function scaleImages()
     {
-        $this->setUpDatabaseConnectionMock();
         $imageProcessor = $this->initializeImageProcessor();
         $parseTimeStart = GeneralUtility::milliseconds();
 
@@ -392,7 +389,6 @@ class TestSetup extends Action\AbstractAction
      */
     protected function combineImages()
     {
-        $this->setUpDatabaseConnectionMock();
         $imageProcessor = $this->initializeImageProcessor();
         $parseTimeStart = GeneralUtility::milliseconds();
 
@@ -445,7 +441,6 @@ class TestSetup extends Action\AbstractAction
      */
     protected function gdlib()
     {
-        $this->setUpDatabaseConnectionMock();
         $imageProcessor = $this->initializeImageProcessor();
         $parseTimeStart = GeneralUtility::milliseconds();
         $gifOrPng = $imageProcessor->gifExtension;
@@ -696,16 +691,4 @@ class TestSetup extends Action\AbstractAction
         list($version) = explode(' ', trim($version));
         return trim($version);
     }
-
-    /**
-     * Instantiate a dummy instance for $GLOBALS['TYPO3_DB'] to
-     * prevent real database calls
-     *
-     * @return void
-     */
-    protected function setUpDatabaseConnectionMock()
-    {
-        $database = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Database\DatabaseConnectionMock::class);
-        $GLOBALS['TYPO3_DB'] = $database;
-    }
 }
diff --git a/typo3/sysext/install/Classes/Controller/Action/Tool/UpgradeWizard.php b/typo3/sysext/install/Classes/Controller/Action/Tool/UpgradeWizard.php
index 4b219e28bc2a..8b9a0c5eedd6 100644
--- a/typo3/sysext/install/Classes/Controller/Action/Tool/UpgradeWizard.php
+++ b/typo3/sysext/install/Classes/Controller/Action/Tool/UpgradeWizard.php
@@ -325,16 +325,4 @@ class UpgradeWizard extends Action\AbstractAction
         $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
         $schemaMigrationService->install($createTableStatements);
     }
-
-    /**
-     * Overwrite getDatabase method of abstract!
-     *
-     * Returns $GLOBALS['TYPO3_DB'] directly, since this global is instantiated properly in update wizards
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
diff --git a/typo3/sysext/install/Classes/Database/DatabaseConnectionMock.php b/typo3/sysext/install/Classes/Database/DatabaseConnectionMock.php
deleted file mode 100644
index 1803cbef5a9a..000000000000
--- a/typo3/sysext/install/Classes/Database/DatabaseConnectionMock.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-namespace TYPO3\CMS\Install\Database;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-/**
- * A "mock" to suppress database calls on $GLOBALS['TYPO3_DB'].
- * Used in TestSetup install tool action to prevent caching in \TYPO3\CMS\Core\Imaging\GraphicalFunctions
- */
-class DatabaseConnectionMock
-{
-    /**
-     * Get single row mock
-     *
-     * @return NULL
-     */
-    public function exec_SELECTgetSingleRow()
-    {
-        return null;
-    }
-
-    /**
-     * Insert row mock
-     *
-     * @return bool TRUE
-     */
-    public function exec_INSERTquery()
-    {
-        return true;
-    }
-
-    /**
-     * Quote string mock
-     *
-     * @param string $string
-     * @return string
-     */
-    public function fullQuoteStr($string)
-    {
-        return $string;
-    }
-
-    /**
-     * Error mock
-     *
-     * @return string Empty string
-     */
-    public function sql_error()
-    {
-        return '';
-    }
-}
diff --git a/typo3/sysext/sys_action/Classes/ActionTask.php b/typo3/sysext/sys_action/Classes/ActionTask.php
index f6631ac750f5..fe2cbda45724 100644
--- a/typo3/sysext/sys_action/Classes/ActionTask.php
+++ b/typo3/sysext/sys_action/Classes/ActionTask.php
@@ -1053,14 +1053,4 @@ class ActionTask implements \TYPO3\CMS\Taskcenter\TaskInterface
     {
         return $GLOBALS['BE_USER'];
     }
-
-    /**
-     * Returns the database connection
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
diff --git a/typo3/sysext/workspaces/Classes/Domain/Record/AbstractRecord.php b/typo3/sysext/workspaces/Classes/Domain/Record/AbstractRecord.php
index b29e1edbb7d9..65b59fa36eb2 100644
--- a/typo3/sysext/workspaces/Classes/Domain/Record/AbstractRecord.php
+++ b/typo3/sysext/workspaces/Classes/Domain/Record/AbstractRecord.php
@@ -44,14 +44,6 @@ abstract class AbstractRecord
         return $record;
     }
 
-    /**
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected static function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
-
     /**
      * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
      */
diff --git a/typo3/sysext/workspaces/Classes/ExtDirect/ExtDirectServer.php b/typo3/sysext/workspaces/Classes/ExtDirect/ExtDirectServer.php
index d623eaf01add..3a17da79ae8e 100644
--- a/typo3/sysext/workspaces/Classes/ExtDirect/ExtDirectServer.php
+++ b/typo3/sysext/workspaces/Classes/ExtDirect/ExtDirectServer.php
@@ -18,7 +18,6 @@ use TYPO3\CMS\Backend\Backend\Avatar\Avatar;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Html\RteHtmlParser;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
@@ -456,14 +455,6 @@ class ExtDirectServer extends AbstractHandler
         return $GLOBALS['LANG'];
     }
 
-    /**
-     * @return DatabaseConnection;
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
-
     /**
      * Gets the Grid Data Service.
      *
diff --git a/typo3/sysext/workspaces/Classes/Service/StagesService.php b/typo3/sysext/workspaces/Classes/Service/StagesService.php
index beaefabd7789..4fcafb785de1 100644
--- a/typo3/sysext/workspaces/Classes/Service/StagesService.php
+++ b/typo3/sysext/workspaces/Classes/Service/StagesService.php
@@ -789,12 +789,4 @@ class StagesService implements \TYPO3\CMS\Core\SingletonInterface
     {
         return $GLOBALS['BE_USER'];
     }
-
-    /**
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
-- 
GitLab