[CLEANUP] Add class-imports in Extbase Persistence classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Storage / Typo3DbBackend.php
index c54cd11..d4db9f6 100644 (file)
@@ -17,7 +17,9 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Storage;
 use Doctrine\DBAL\DBALException;
 use Doctrine\DBAL\Platforms\SQLServerPlatform;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\PreparedStatement;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
 use TYPO3\CMS\Core\SingletonInterface;
@@ -25,9 +27,17 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\DomainObject\AbstractValueObject;
+use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
+use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
 use TYPO3\CMS\Extbase\Persistence\Generic\Qom;
+use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
+use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException;
 use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException;
 use TYPO3\CMS\Extbase\Persistence\QueryInterface;
+use TYPO3\CMS\Extbase\Service\CacheService;
+use TYPO3\CMS\Extbase\Service\EnvironmentService;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
  * A Storage backend
@@ -40,34 +50,34 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     protected $connectionPool;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
+     * @var DataMapper
      */
     protected $dataMapper;
 
     /**
      * The TYPO3 page repository. Used for language and workspace overlay
      *
-     * @var \TYPO3\CMS\Frontend\Page\PageRepository
+     * @var PageRepository
      */
     protected $pageRepository;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
+     * @var ConfigurationManagerInterface
      */
     protected $configurationManager;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Service\CacheService
+     * @var CacheService
      */
     protected $cacheService;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
+     * @var EnvironmentService
      */
     protected $environmentService;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
+     * @var ObjectManagerInterface
      */
     protected $objectManager;
 
@@ -80,15 +90,15 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     protected $hasPidColumn = [];
 
     /**
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper
+     * @param DataMapper $dataMapper
      */
-    public function injectDataMapper(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper)
+    public function injectDataMapper(DataMapper $dataMapper)
     {
         $this->dataMapper = $dataMapper;
     }
 
     /**
-     * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
+     * @param ConfigurationManagerInterface $configurationManager
      */
     public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
     {
@@ -96,25 +106,25 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     }
 
     /**
-     * @param \TYPO3\CMS\Extbase\Service\CacheService $cacheService
+     * @param CacheService $cacheService
      */
-    public function injectCacheService(\TYPO3\CMS\Extbase\Service\CacheService $cacheService)
+    public function injectCacheService(CacheService $cacheService)
     {
         $this->cacheService = $cacheService;
     }
 
     /**
-     * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
+     * @param EnvironmentService $environmentService
      */
-    public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
+    public function injectEnvironmentService(EnvironmentService $environmentService)
     {
         $this->environmentService = $environmentService;
     }
 
     /**
-     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
+     * @param ObjectManagerInterface $objectManager
      */
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
+    public function injectObjectManager(ObjectManagerInterface $objectManager)
     {
         $this->objectManager = $objectManager;
     }
@@ -174,9 +184,9 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
      * @param string $tableName The database table name
      * @param array $fieldValues The row to be updated
      * @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default
+     * @return bool
      * @throws \InvalidArgumentException
      * @throws SqlErrorException
-     * @return bool
      */
     public function updateRow($tableName, array $fieldValues, $isRelation = false)
     {
@@ -218,9 +228,9 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
      *
      * @param string $tableName The database relation table name
      * @param array $fieldValues The row to be updated
-     * @throws \InvalidArgumentException
      * @return bool
      * @throws SqlErrorException
+     * @throws \InvalidArgumentException
      */
     public function updateRelationTableRow($tableName, array $fieldValues)
     {
@@ -246,8 +256,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
         }
 
         try {
-            $this->connectionPool->getConnectionForTable($tableName)
-                ->update($tableName, $fieldValues, $where);
+            $this->connectionPool->getConnectionForTable($tableName)->update($tableName, $fieldValues, $where);
         } catch (DBALException $e) {
             throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230768);
         }
@@ -417,7 +426,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
                 throw new SqlErrorException($e->getPrevious()->getMessage(), 1481281404);
             }
             $rows = $realStatement->fetchAll();
-        } elseif ($realStatement instanceof \TYPO3\CMS\Core\Database\PreparedStatement) {
+        } elseif ($realStatement instanceof PreparedStatement) {
             GeneralUtility::deprecationLog('Extbase support for Prepared Statements has been deprecated in TYPO3 v8, and will be removed in TYPO3 v9. Use native Doctrine DBAL Statements or QueryBuilder objects.');
             $realStatement->execute($parameters);
             $rows = $realStatement->fetchAll();
@@ -444,14 +453,14 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
      * Returns the number of tuples matching the query.
      *
      * @param QueryInterface $query
-     * @throws Exception\BadConstraintException
      * @return int The number of matching tuples
+     * @throws BadConstraintException
      * @throws SqlErrorException
      */
     public function getObjectCountByQuery(QueryInterface $query)
     {
         if ($query->getConstraint() instanceof Qom\Statement) {
-            throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException('Could not execute count on queries with a constraint of type TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Statement', 1256661045);
+            throw new BadConstraintException('Could not execute count on queries with a constraint of type TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Statement', 1256661045);
         }
 
         $queryParser = $this->objectManager->get(Typo3DbQueryParser::class);
@@ -537,11 +546,11 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
      *
      * @param Qom\SourceInterface $source The source (selector od join)
      * @param array $rows
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
+     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
      * @param int|null $workspaceUid
      * @return array
      */
-    protected function doLanguageAndWorkspaceOverlay(Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid = null)
+    protected function doLanguageAndWorkspaceOverlay(Qom\SourceInterface $source, array $rows, QuerySettingsInterface $querySettings, $workspaceUid = null)
     {
         if ($source instanceof Qom\SelectorInterface) {
             $tableName = $source->getSelectorName();
@@ -554,13 +563,13 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
         }
 
         $pageRepository = $this->getPageRepository();
-        if (is_object($GLOBALS['TSFE'])) {
+        if (is_object($this->getTSFE())) {
             if ($workspaceUid !== null) {
                 $pageRepository->versioningWorkspaceId = $workspaceUid;
             }
         } else {
             if ($workspaceUid === null) {
-                $workspaceUid = $GLOBALS['BE_USER']->workspace;
+                $workspaceUid = $this->getBeUser()->workspace;
             }
             $pageRepository->versioningWorkspaceId = $workspaceUid;
         }
@@ -644,15 +653,15 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     }
 
     /**
-     * @return \TYPO3\CMS\Frontend\Page\PageRepository
+     * @return PageRepository
      */
     protected function getPageRepository()
     {
-        if (!$this->pageRepository instanceof \TYPO3\CMS\Frontend\Page\PageRepository) {
-            if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) {
-                $this->pageRepository = $GLOBALS['TSFE']->sys_page;
+        if (!$this->pageRepository instanceof PageRepository) {
+            if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($this->getTSFE())) {
+                $this->pageRepository = $this->getTSFE()->sys_page;
             } else {
-                $this->pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
+                $this->pageRepository = GeneralUtility::makeInstance(PageRepository::class);
             }
         }
 
@@ -689,6 +698,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
             $this->hasPidColumn[$tableName] = array_key_exists('pid', $columns);
         }
 
+        $tsfe = $this->getTSFE();
         if ($this->hasPidColumn[$tableName]) {
             $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
             $queryBuilder->getRestrictions()->removeAll();
@@ -706,9 +716,9 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
                 $storagePage = $row['pid'];
                 $pageIdsToClear[] = $storagePage;
             }
-        } elseif (isset($GLOBALS['TSFE'])) {
+        } elseif (isset($tsfe)) {
             // No PID column - we can do a best-effort to clear the cache of the current page if in FE
-            $storagePage = $GLOBALS['TSFE']->id;
+            $storagePage = $tsfe->id;
             $pageIdsToClear[] = $storagePage;
         }
         if ($storagePage === null) {
@@ -730,4 +740,20 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
             $this->cacheService->getPageIdStack()->push($pageIdToClear);
         }
     }
+
+    /**
+     * @return TypoScriptFrontendController|null
+     */
+    protected function getTSFE()
+    {
+        return $GLOBALS['TSFE'] ?? null;
+    }
+
+    /**
+     * @return BackendUserAuthentication|null
+     */
+    protected function getBeUser()
+    {
+        return $GLOBALS['BE_USER'] ?? null;
+    }
 }