[TASK] Doctrine: Migrate CategoryBasedFileCollection 56/49556/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 23 Aug 2016 13:06:20 +0000 (15:06 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Tue, 23 Aug 2016 15:44:51 +0000 (17:44 +0200)
Change-Id: I2aa9ef2c26d8f55112bb1017803bb27650d1afb5
Resolves: #77608
Releases: master
Reviewed-on: https://review.typo3.org/49556
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/core/Classes/Resource/Collection/CategoryBasedFileCollection.php

index c8e2333..3da7c97 100644 (file)
@@ -13,7 +13,10 @@ namespace TYPO3\CMS\Core\Resource\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * A collection containing a set files belonging to certain categories.
@@ -48,31 +51,36 @@ class CategoryBasedFileCollection extends AbstractFileCollection
      */
     public function loadContents()
     {
-        $resource = $this->getDatabaseConnection()->exec_SELECT_mm_query(
-            'sys_file_metadata.file',
-            'sys_category',
-            'sys_category_record_mm',
-            'sys_file_metadata',
-            'AND sys_category.uid=' . (int)$this->getItemsCriteria() .
-            ' AND sys_category_record_mm.tablenames = \'sys_file_metadata\''
-        );
-
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category');
+        $queryBuilder->getRestrictions()->removeAll();
+        $statement = $queryBuilder->select('sys_file_metadata.file')
+            ->from('sys_category')
+            ->join(
+                'sys_category',
+                'sys_category_record_mm',
+                'sys_category_record_mm',
+                $queryBuilder->expr()->eq(
+                    'sys_category_record_mm.uid_local',
+                    $queryBuilder->quoteIdentifier('sys_category.uid')
+                )
+            )
+            ->join(
+                'sys_category_record_mm',
+                'sys_file_metadata',
+                'sys_file_metadata',
+                $queryBuilder->expr()->eq(
+                    'sys_category_record_mm.uid_foreign',
+                    $queryBuilder->quoteIdentifier('sys_file_metadata.uid')
+                )
+            )
+            ->where(
+                $queryBuilder->expr()->eq('sys_category.uid', (int)$this->getItemsCriteria()),
+                $queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('sys_file_metadata'))
+            )
+            ->execute();
         $resourceFactory = ResourceFactory::getInstance();
-        if ($resource) {
-            while (($record = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) !== false) {
-                $this->add($resourceFactory->getFileObject((int)$record['file']));
-            }
-            $this->getDatabaseConnection()->sql_free_result($resource);
+        while ($record = $statement->fetch()) {
+            $this->add($resourceFactory->getFileObject((int)$record['file']));
         }
     }
-
-    /**
-     * Gets the database object.
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }