[BUGFIX] Enable BE search for multiple mountpoints 95/23895/6
authorGeorg Ringer <georg.ringer@gmail.com>
Thu, 19 Sep 2013 05:31:20 +0000 (07:31 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Fri, 18 Oct 2013 04:06:58 +0000 (06:06 +0200)
Backend search now allows search from all mounts of an editor.
If the root page is selected it will search in all mounts of the
backend user.

Change-Id: Ic462725bb4cba8100c5eeca5f7f47b5711ab2869
Resolves: #35073
Releases: 6.2, 6.1, 6.0
Reviewed-on: https://review.typo3.org/23895
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
typo3/sysext/backend/Classes/Controller/BackendController.php
typo3/sysext/backend/Resources/Public/JavaScript/livesearch.js
typo3/sysext/recordlist/Classes/RecordList.php
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php

index d305372..87067ad 100644 (file)
@@ -492,7 +492,6 @@ class BackendController {
                                'width' => 600,
                                'height' => 400
                        ),
-                       'firstWebmountPid' => intval($GLOBALS['WEBMOUNTS'][0])
                );
                $this->js .= '
        TYPO3.configuration = ' . json_encode($t3Configuration) . ';
index 6d54bf7..d271d8f 100644 (file)
@@ -179,8 +179,7 @@ TYPO3.BackendLiveSearch = Ext.extend(Ext.form.ComboBox, {
                                        scope : this,
                                        click : function () {
                                                        // go to db_list.php and search for given search value
-                                                       // @todo the current selected page ID from the page tree is required, also we need the
-                                                       // values of $GLOBALS['BE_USER']->returnWebmounts() to search only during the allowed pages
+                                                       // @todo the current selected page ID from the page tree is required
                                                TYPO3.ModuleMenu.App.showModule('web_list', this.getSearchResultsUrl(this.getValue()));
                                                this.collapse();
                                        }
@@ -319,8 +318,7 @@ Ext.onReady(function() {
                helpTitle: TYPO3.LLL.liveSearch.helpTitle,
                emptyText: TYPO3.LLL.liveSearch.emptyText,
                loadingText: TYPO3.LLL.liveSearch.loadingText,
-               listEmptyText: TYPO3.LLL.liveSearch.listEmptyText,
-               searchResultsPid: TYPO3.configuration.firstWebmountPid
+               listEmptyText: TYPO3.LLL.liveSearch.listEmptyText
        });
 
        TYPO3LiveSearch.applyToMarkup(Ext.get('live-search-box'));
index 2cd5483..3595d07 100644 (file)
@@ -182,12 +182,12 @@ class RecordList {
                $this->MCONF = $GLOBALS['MCONF'];
                $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
                // GPvars:
-               $this->id = (int) GeneralUtility::_GP('id');
+               $this->id = (int)GeneralUtility::_GP('id');
                $this->pointer = GeneralUtility::_GP('pointer');
                $this->imagemode = GeneralUtility::_GP('imagemode');
                $this->table = GeneralUtility::_GP('table');
                $this->search_field = GeneralUtility::_GP('search_field');
-               $this->search_levels = GeneralUtility::_GP('search_levels');
+               $this->search_levels = (int)GeneralUtility::_GP('search_levels');
                $this->showLimit = GeneralUtility::_GP('showLimit');
                $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
                $this->clear_cache = GeneralUtility::_GP('clear_cache');
@@ -317,8 +317,8 @@ class RecordList {
                // This flag will prevent the clipboard panel in being shown.
                // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
                $dblist->dontShowClipControlPanels = $GLOBALS['CLIENT']['FORMSTYLE'] && !$this->MOD_SETTINGS['bigControlPanel'] && $dblist->clipObj->current == 'normal' && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers'];
-               // If there is access to the page, then render the list contents and set up the document template object:
-               if ($access) {
+               // If there is access to the page or root page is used for searching, then render the list contents and set up the document template object:
+               if ($access || ($this->id === 0 && $this->search_levels > 0 && strlen($this->search_field) > 0)) {
                        // Deleting records...:
                        // Has not to do with the clipboard but is simply the delete action. The clipboard object is used to clean up the submitted entries to only the selected table.
                        if ($this->cmd == 'delete') {
index 279faac..4ee47a7 100644 (file)
@@ -361,8 +361,8 @@ class AbstractDatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\AbstractR
                        }
                }
                if ($searchLevels > 0) {
-                       $tree = $this->getTreeObject($this->id, $searchLevels, $this->perms_clause);
-                       $pidList = implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($tree->ids));
+                       $allowedMounts = $this->getSearchableWebmounts($this->id, $searchLevels, $this->perms_clause);
+                       $pidList = implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($allowedMounts));
                        $this->pidSelect = 'pid IN (' . $pidList . ')';
                } elseif ($searchLevels < 0) {
                        // Search everywhere
@@ -933,8 +933,10 @@ class AbstractDatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\AbstractR
         * @param string $perms_clause Select clause
         * @return \TYPO3\CMS\Backend\Tree\View\PageTreeView instance with created list of ids.
         * @todo Define visibility
+        * @deprecated Deprecated since 6.2, will be removed 2 versions later
         */
        public function getTreeObject($id, $depth, $perms_clause) {
+               GeneralUtility::logDeprecatedFunction();
                $tree = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
                $tree->init('AND ' . $perms_clause);
                $tree->makeHTML = 0;
@@ -947,6 +949,37 @@ class AbstractDatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\AbstractR
        }
 
        /**
+        * Get all allowed mount pages to be searched in.
+        *
+        * @param integer $id Page id
+        * @param integer $depth Depth to go down
+        * @param string $perms_clause select clause
+        * @return array
+        */
+       protected function getSearchableWebmounts($id, $depth, $perms_clause) {
+               /** @var \TYPO3\CMS\Backend\Tree\View\PageTreeView $tree */
+               $tree = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
+               $tree->init('AND ' . $perms_clause);
+               $tree->makeHTML = 0;
+               $tree->fieldArray = array('uid', 'php_tree_stop');
+               $idList = array();
+
+               $allowedMounts = !$GLOBALS['BE_USER']->isAdmin() && $id === 0
+                       ? $GLOBALS['BE_USER']->returnWebmounts()
+                       : array($id);
+
+               foreach ($allowedMounts as $allowedMount) {
+                       $idList[] = $allowedMount;
+                       if ($depth) {
+                               $tree->getTree($allowedMount, $depth, '');
+                       }
+                       $idList = array_merge($idList, $tree->ids);
+               }
+
+               return $idList;
+       }
+
+       /**
         * Redirects to TCEforms (alt_doc) if a record is just localized.
         *
         * @param string $justLocalized String with table, orig uid and language separated by ":