[TASK] Doctrine: migrate EXT:filelist 01/47801/2
authorMichael Oehlhof <typo3@oehlhof.de>
Wed, 20 Apr 2016 00:07:53 +0000 (02:07 +0200)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Wed, 20 Apr 2016 10:39:32 +0000 (12:39 +0200)
Resolves: #75800
Releases: master
Change-Id: I70863664d4e127759ef0c9420a8ee81f2aea5250
Reviewed-on: https://review.typo3.org/47801
Reviewed-by: Michiel Roos <michiel@maxserv.com>
Tested-by: Michiel Roos <michiel@maxserv.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
typo3/sysext/filelist/Classes/FileFacade.php
typo3/sysext/filelist/Classes/FileList.php

index fe66ce4..48f89d3 100644 (file)
@@ -15,9 +15,11 @@ namespace TYPO3\CMS\Filelist;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Resource\FileInterface;
 
 /**
  * Class FileFacade
@@ -45,7 +47,7 @@ class FileFacade
      * @param \TYPO3\CMS\Core\Resource\FileInterface $resource
      * @internal Do not use outside of EXT:filelist!
      */
-    public function __construct(\TYPO3\CMS\Core\Resource\FileInterface $resource)
+    public function __construct(FileInterface $resource)
     {
         $this->resource = $resource;
         $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
@@ -251,18 +253,14 @@ class FileFacade
         }
 
         if (!isset(static::$referenceCounts[$uid])) {
-            $count = $this->getDatabaseConnection()->exec_SELECTcountRows(
-                '*',
-                'sys_refindex',
-                'ref_table=\'sys_file\''
-                . ' AND ref_uid=' . (int)$this->resource->getProperty('uid')
-                . ' AND deleted=0'
-                . ' AND tablename != \'sys_file_metadata\''
-            );
-
-            if (!is_int($count)) {
-                $count = 0;
-            }
+            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
+            $count = $queryBuilder->count('*')
+                ->from('sys_refindex')
+                ->where($queryBuilder->expr()->eq('ref_table', $queryBuilder->quote('sys_file')))
+                ->andWhere($queryBuilder->expr()->eq('ref_uid', (int)$this->resource->getProperty('uid')))
+                ->andWhere($queryBuilder->expr()->neq('tablename', $queryBuilder->quote('sys_file_metadata')))
+                ->execute()
+                ->fetchColumn();
 
             static::$referenceCounts[$uid] = $count;
         }
@@ -286,14 +284,6 @@ class FileFacade
     }
 
     /**
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
-
-    /**
      * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
      */
     protected function getBackendUser()
index 45b85a2..9ab1c1f 100644 (file)
@@ -18,7 +18,8 @@ use TYPO3\CMS\Backend\Clipboard\Clipboard;
 use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
 use TYPO3\CMS\Backend\RecordList\AbstractRecordList;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\QueryContextType;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
@@ -782,9 +783,15 @@ class FileList extends AbstractRecordList
      */
     protected function getTranslationsForMetaData($metaDataRecord)
     {
-        $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
-            ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
-        $translationRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_metadata');
+        $queryBuilder->getQueryContext()->setContext(QueryContextType::UNRESTRICTED);
+        $translationRecords = $queryBuilder->select('*')
+            ->from('sys_file_metadata')
+            ->where($queryBuilder->expr()->eq($GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'], (int)$metaDataRecord['uid']))
+            ->andWhere($queryBuilder->expr()->gt($GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'], 0))
+            ->execute()
+            ->fetchAll();
+
         $translations = array();
         foreach ($translationRecords as $record) {
             $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
@@ -1034,27 +1041,16 @@ class FileList extends AbstractRecordList
         }
         // Look up the file in the sys_refindex.
         // Exclude sys_file_metadata records as these are no use references
-        $databaseConnection = $this->getDatabaseConnection();
-        $table = 'sys_refindex';
-        $referenceCount = $databaseConnection->exec_SELECTcountRows(
-            '*',
-            $table,
-            'ref_table=' . $databaseConnection->fullQuoteStr('sys_file', $table)
-                . ' AND ref_uid=' . (int)$fileOrFolderObject->getUid()
-                . ' AND deleted=0'
-                . ' AND tablename != ' . $databaseConnection->fullQuoteStr('sys_file_metadata', $table)
-        );
-        return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
-    }
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
+        $referenceCount = $queryBuilder->count('*')
+            ->from('sys_refindex')
+            ->where($queryBuilder->expr()->eq('ref_table', $queryBuilder->quote('sys_file')))
+            ->andWhere($queryBuilder->expr()->eq('ref_uid', (int)$fileOrFolderObject->getUid()))
+            ->andWhere($queryBuilder->expr()->neq('tablename', $queryBuilder->quote('sys_file_metadata')))
+            ->execute()
+            ->fetchColumn();
 
-    /**
-     * Returns the database connection
-     *
-     * @return DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
+        return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
     }
 
     /**