[TASK] Doctrine: migrate tstemplate/TypoScriptTemplateModuleController 19/47819/5
authorChristoph Kratz <ckr@rtp.ch>
Wed, 20 Apr 2016 16:48:43 +0000 (18:48 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Mon, 6 Jun 2016 12:21:17 +0000 (14:21 +0200)
Resolves: #75824
Releases: master
Change-Id: Iae855b27058a366d0e4ee691d8cfd259ba66991e
Reviewed-on: https://review.typo3.org/47819
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateModuleController.php

index 04e0dfa..1d99851 100755 (executable)
@@ -20,6 +20,9 @@ use TYPO3\CMS\Backend\Module\BaseScriptClass;
 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
 use TYPO3\CMS\Backend\Template\ModuleTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
+use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
@@ -209,20 +212,28 @@ class TypoScriptTemplateModuleController extends BaseScriptClass
             $this->generateMenu();
             $this->content .= '</form>';
         } else {
-            // Template pages:
-            $records = $this->getDatabaseConnection()->exec_SELECTgetRows(
-                'pages.uid, count(*) AS count, max(sys_template.root) AS root_max_val, min(sys_template.root) AS root_min_val',
-                'pages,sys_template',
-                'pages.uid=sys_template.pid'
-                    . BackendUtility::deleteClause('pages')
-                    . BackendUtility::versioningPlaceholderClause('pages')
-                    . BackendUtility::deleteClause('sys_template')
-                    . BackendUtility::versioningPlaceholderClause('sys_template'),
-                'pages.uid',
-                'pages.pid, pages.sorting'
-            );
+            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
+            $queryBuilder->getRestrictions()
+                ->removeAll()
+                ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
+                ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
+
+            $result = $queryBuilder->select('pages.uid')
+                ->addSelectLiteral(
+                    $queryBuilder->expr()->count('*', 'count'),
+                    $queryBuilder->expr()->max('sys_template.root', 'root_max_val'),
+                    $queryBuilder->expr()->min('sys_template.root', 'root_min_val')
+                )
+                ->from('pages')
+                ->from('sys_template')
+                ->where($queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('sys_template.pid')))
+                ->groupBy('pages.uid')
+                ->orderBy('pages.pid')
+                ->addOrderBy('pages.sorting')
+                ->execute();
+
             $pArray = array();
-            foreach ($records as $record) {
+            while ($record = $result->fetch()) {
                 $this->setInPageArray($pArray, BackendUtility::BEgetRootLine($record['uid'], 'AND 1=1'), $record);
             }