[BUGFIX] Reintroduce removed page tree TSconfig settings 86/59586/6
authorSoren Malling <soren@meteko.dk>
Wed, 30 Jan 2019 08:52:51 +0000 (09:52 +0100)
committerFrank Naegler <frank.naegler@typo3.org>
Sun, 3 Mar 2019 19:56:52 +0000 (20:56 +0100)
This patch reintroduces to `excludeDoktypes` to the
pagetree ajax controller

Resolves: #87581
Related: #82919
Releases: master, 9.5
Change-Id: Ib1f4917e016668ff298412fc8906bd881849e13a
Reviewed-on: https://review.typo3.org/c/59586
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Tested-by: Soren Malling <soren@meteko.dk>
Tested-by: Guido Schmechel <guido.schmechel@brandung.de>
Tested-by: Richard Haeser <richard@maxserv.com>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Guido Schmechel <guido.schmechel@brandung.de>
Reviewed-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/Controller/Page/TreeController.php
typo3/sysext/backend/Classes/Tree/Repository/PageTreeRepository.php
typo3/sysext/core/Classes/Database/Query/Restriction/DocumentTypeExclusionRestriction.php [new file with mode: 0644]

index 8a7b2c8..d4b7162 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Backend\Configuration\BackendUserConfiguration;
 use TYPO3\CMS\Backend\Tree\Repository\PageTreeRepository;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Database\Query\Restriction\DocumentTypeExclusionRestriction;
 use TYPO3\CMS\Core\Exception\Page\RootLineException;
 use TYPO3\CMS\Core\Exception\SiteNotFoundException;
 use TYPO3\CMS\Core\Http\JsonResponse;
@@ -323,7 +324,18 @@ class TreeController
     protected function getAllEntryPointPageTrees(): array
     {
         $backendUser = $this->getBackendUser();
-        $repository = GeneralUtility::makeInstance(PageTreeRepository::class, (int)$backendUser->workspace);
+
+        $userTsConfig = $this->getBackendUser()->getTSConfig();
+        $excludedDocumentTypes = GeneralUtility::intExplode(',', $userTsConfig['options.']['pageTree.']['excludeDoktypes'] ?? '', true);
+
+        $additionalPageTreeQueryRestrictions = [];
+        if (!empty($excludedDocumentTypes)) {
+            foreach ($excludedDocumentTypes as $excludedDocumentType) {
+                $additionalPageTreeQueryRestrictions[] = new DocumentTypeExclusionRestriction((int)$excludedDocumentType);
+            }
+        }
+
+        $repository = GeneralUtility::makeInstance(PageTreeRepository::class, (int)$backendUser->workspace, [], $additionalPageTreeQueryRestrictions);
 
         $entryPoints = (int)($backendUser->uc['pageTree_temporaryMountPoint'] ?? 0);
         if ($entryPoints > 0) {
index 885af6c..6f2e764 100644 (file)
@@ -88,15 +88,25 @@ class PageTreeRepository
     protected $fullPageTree = [];
 
     /**
+     * @var array
+     */
+    protected $additionalQueryRestrictions = [];
+
+    /**
      * @param int $workspaceId the workspace ID to be checked for.
      * @param array $additionalFieldsToQuery an array with more fields that should be accessed.
+     * @param array $additionalQueryRestrictions an array with more restrictions to add
      */
-    public function __construct(int $workspaceId = 0, array $additionalFieldsToQuery = [])
+    public function __construct(int $workspaceId = 0, array $additionalFieldsToQuery = [], array $additionalQueryRestrictions = [])
     {
         $this->currentWorkspace = $workspaceId;
         if (!empty($additionalFieldsToQuery)) {
             $this->fields = array_merge($this->fields, $additionalFieldsToQuery);
         }
+
+        if (!empty($additionalQueryRestrictions)) {
+            $this->additionalQueryRestrictions = $additionalQueryRestrictions;
+        }
     }
 
     /**
@@ -158,6 +168,12 @@ class PageTreeRepository
             ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
             ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->currentWorkspace));
 
+        if (!empty($this->additionalQueryRestrictions)) {
+            foreach ($this->additionalQueryRestrictions as $additionalQueryRestriction) {
+                $queryBuilder->getRestrictions()->add($additionalQueryRestriction);
+            }
+        }
+
         $pageRecords = $queryBuilder
             ->select(...$this->fields)
             ->from('pages')
diff --git a/typo3/sysext/core/Classes/Database/Query/Restriction/DocumentTypeExclusionRestriction.php b/typo3/sysext/core/Classes/Database/Query/Restriction/DocumentTypeExclusionRestriction.php
new file mode 100644 (file)
index 0000000..ade165f
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Core\Database\Query\Restriction;
+
+/*
+ * 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!
+ */
+
+use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+
+/**
+ * Restriction to make queries for pages doktype-aware.
+ */
+class DocumentTypeExclusionRestriction implements QueryRestrictionInterface
+{
+    /**
+     * @var int
+     */
+    protected $doktype;
+
+    /**
+     * @param int $doktype
+     */
+    public function __construct(int $doktype)
+    {
+        $this->doktype = (int)$doktype;
+    }
+
+    /**
+     * Main method to build expressions for given tables
+     *
+     * @param array $queriedTables Array of tables, where array key is table alias and value is a table name
+     * @param ExpressionBuilder $expressionBuilder Expression builder instance to add restrictions with
+     * @return CompositeExpression The result of query builder expression(s)
+     */
+    public function buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
+    {
+        $constraints = [];
+
+        foreach ($queriedTables as $tableAlias => $tableName) {
+            if ($tableName !== 'pages') {
+                continue;
+            }
+
+            $constraints[] = $expressionBuilder->neq($tableAlias . '.doktype', $this->doktype);
+        }
+
+        return $expressionBuilder->andX(...$constraints);
+    }
+}