From 3bc81866dc47ce28905225ed279a30ea389bf252 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Thu, 11 May 2017 14:19:11 +0200
Subject: [PATCH] [BUGFIX] Indexed Search should use
 FrontendRestrictionsContainer

Indexed Search still uses enableFields for querying page records,
unlike most other places in the TYPO3 Core. This should be streamlined
because it was forgotten in the initial migration.

Resolves: #81194
Releases: master, 8.7
Change-Id: I0712f6811eefba6d2cb46ed06ff4b1d31ac7fa0b
Reviewed-on: https://review.typo3.org/52768
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
---
 .../Repository/IndexSearchRepository.php      | 28 +++----------------
 1 file changed, 4 insertions(+), 24 deletions(-)

diff --git a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php
index 160597cbe574..cbcf2f6211a2 100644
--- a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php
+++ b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php
@@ -478,7 +478,7 @@ class IndexSearchRepository
         if ($hookObj = &$this->hookRequest('execFinalQuery_idList')) {
             $pageWhere = $hookObj->execFinalQuery_idList('');
             $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($pageWhere));
-        } elseif ($this->getJoinPagesForQuery()) {
+        } elseif ($this->joinPagesForQuery) {
             // Alternative to getting all page ids by ->getTreeList() where "excludeSubpages" is NOT respected.
             $queryBuilder
                 ->join(
@@ -502,7 +502,7 @@ class IndexSearchRepository
             $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
         } elseif ($searchRootPageIdList[0] >= 0) {
             // Collecting all pages IDs in which to search;
-            // filtering out ALL pages that are not accessible due to enableFields. Does NOT look for "no_search" field!
+            // filtering out ALL pages that are not accessible due to restriction containers. Does NOT look for "no_search" field!
             $idList = [];
             foreach ($searchRootPageIdList as $rootId) {
                 /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
@@ -1043,11 +1043,10 @@ class IndexSearchRepository
         } elseif ($this->joinPagesForQuery) {
             // Alternative to getting all page ids by ->getTreeList() where
             // "excludeSubpages" is NOT respected.
-            $queryBuilder->getRestrictions()->removeAll();
+            $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
             $queryBuilder->from('pages');
             $queryBuilder->andWhere(
                 $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('ISEC.page_id')),
-                QueryHelper::stripLogicalOperatorPrefix($this->enableFields('pages')),
                 $queryBuilder->expr()->eq(
                     'pages.no_search',
                     $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
@@ -1059,7 +1058,7 @@ class IndexSearchRepository
             );
         } elseif ($this->searchRootPageIdList >= 0) {
             // Collecting all pages IDs in which to search;
-            // filtering out ALL pages that are not accessible due to enableFields.
+            // filtering out ALL pages that are not accessible due to restriction containers.
             // Does NOT look for "no_search" field!
             $siteIdNumbers = GeneralUtility::intExplode(',', $this->searchRootPageIdList);
             $pageIdList = [];
@@ -1228,25 +1227,6 @@ class IndexSearchRepository
         return !$desc ? ' DESC' : '';
     }
 
-    /**
-     * Returns a part of a WHERE clause which will filter out records with start/end times or hidden/fe_groups fields
-     * set to values that should de-select them according to the current time, preview settings or user login.
-     * Definitely a frontend function.
-     * THIS IS A VERY IMPORTANT FUNCTION: Basically you must add the output from this function for EVERY select query you create
-     * for selecting records of tables in your own applications - thus they will always be filtered according to the "enablefields"
-     * configured in TCA
-     * Simply calls \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() BUT will send the show_hidden flag along!
-     * This means this function will work in conjunction with the preview facilities of the frontend engine/Admin Panel.
-     *
-     * @param string $table The table for which to get the where clause
-     * @return string The part of the where clause on the form " AND [fieldname]=0 AND ...". Eg. " AND hidden=0 AND starttime < 123345567
-     * @see \TYPO3\CMS\Frontend\Page\PageRepository::enableFields()
-     */
-    protected function enableFields($table)
-    {
-        return $this->getTypoScriptFrontendController()->sys_page->enableFields($table, $table === 'pages' ? $this->getTypoScriptFrontendController()->showHiddenPage : $this->getTypoScriptFrontendController()->showHiddenRecords);
-    }
-
     /**
      * Returns if an item type is a multipage item type
      *
-- 
GitLab