From 8e062d6e42813821f9ed1438665588df1abb83cf Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 26 Jan 2017 14:37:17 +0100 Subject: [PATCH] BUGFIX: Respect additionalWhereClause and rootline * Use constants instead of setup. * Grap configuration from path. * Add where clause. --- .../NoConfigurationException.php | 0 .../Domain/Index/NoRecordFoundException.php | 0 .../Index/TcaIndexer/TcaTableService.php | 24 +++++++++------ Configuration/TypoScript/constants.txt | 29 +++++++++++++++++++ Configuration/TypoScript/setup.txt | 12 +++----- Documentation/source/configuration.rst | 12 ++++---- 6 files changed, 55 insertions(+), 22 deletions(-) mode change 100755 => 100644 Classes/Configuration/NoConfigurationException.php mode change 100755 => 100644 Classes/Domain/Index/NoRecordFoundException.php mode change 100644 => 100755 Configuration/TypoScript/constants.txt mode change 100644 => 100755 Configuration/TypoScript/setup.txt diff --git a/Classes/Configuration/NoConfigurationException.php b/Classes/Configuration/NoConfigurationException.php old mode 100755 new mode 100644 diff --git a/Classes/Domain/Index/NoRecordFoundException.php b/Classes/Domain/Index/NoRecordFoundException.php old mode 100755 new mode 100644 diff --git a/Classes/Domain/Index/TcaIndexer/TcaTableService.php b/Classes/Domain/Index/TcaIndexer/TcaTableService.php index 3f2d697..936d425 100644 --- a/Classes/Domain/Index/TcaIndexer/TcaTableService.php +++ b/Classes/Domain/Index/TcaIndexer/TcaTableService.php @@ -151,9 +151,9 @@ class TcaTableService . ' AND pages.no_search = 0' ; - $userDefinedWhere = $this->configuration->getIfExists('indexer.tca.' . $this->tableName); + $userDefinedWhere = $this->configuration->getIfExists('indexer.tca.' . $this->tableName . '.additionalWhereClause'); if (is_string($userDefinedWhere)) { - $whereClause .= $userDefinedWhere; + $whereClause .= ' AND ' . $userDefinedWhere; } if ($this->isBlacklistedRootLineConfigured()) { @@ -236,20 +236,26 @@ class TcaTableService * Checks whether the given record was blacklisted by root line. * This can be configured by typoscript as whole root lines can be black listed. * + * NOTE: Does not support pages yet. We have to add a switch once we + * support them to use uid instead. + * * @param array &$record * @return bool */ protected function isRecordBlacklistedByRootline(array &$record) { - // NOTE: Does not support pages yet. We have to add a switch once we - // support them to use uid instead. - if (! $this->isBlackListedRootLineConfigured()) { - return false; + // If no rootline exists, the record is on a unreachable page and therefore blacklisted. + $rootline = BackendUtility::BEgetRootLine($record['pid']); + if (!isset($rootline[0])) { + return true; } - foreach (BackendUtility::BEgetRootLine($record['uid']) as $pageInRootLine) { - if (in_array($pageInRootLine['uid'], $this->getBlackListedRootLine())) { - return true; + // Check configured black list if present. + if ($this->isBlackListedRootLineConfigured()) { + foreach ($rootline as $pageInRootLine) { + if (in_array($pageInRootLine['uid'], $this->getBlackListedRootLine())) { + return true; + } } } diff --git a/Configuration/TypoScript/constants.txt b/Configuration/TypoScript/constants.txt old mode 100644 new mode 100755 index e69de29..50f57c3 --- a/Configuration/TypoScript/constants.txt +++ b/Configuration/TypoScript/constants.txt @@ -0,0 +1,29 @@ +plugin { + tx_searchcore { + settings { + connections { + elasticsearch { + host = localhost + port = 9200 + } + } + + indexer { + tca { + # Pages are not supported yet, see + # https://github.com/DanielSiepmann/search_core/issues/24 but + # should also be added, together with additionalWhereClause + # based on doktypes + allowedTables = tt_content + + tt_content { + additionalWhereClause ( + pages.doktype NOT IN (3, 199) + AND tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu', 'shortcut', 'search', 'login') + ) + } + } + } + } + } +} diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt old mode 100644 new mode 100755 index 0e5bd20..afa15be --- a/Configuration/TypoScript/setup.txt +++ b/Configuration/TypoScript/setup.txt @@ -3,21 +3,17 @@ plugin { settings { connections { elasticsearch { - host = localhost - port = 9200 + host = {$plugin.tx_searchcore.settings.connections.elasticsearch.host} + port = {$plugin.tx_searchcore.settings.connections.elasticsearch.port} } } indexer { tca { - # Pages are not supported yet, see - # https://github.com/DanielSiepmann/search_core/issues/24 but - # should also be added, together with additionalWhereClause - # based on doktypes - allowedTables = tt_content + allowedTables = {$plugin.tx_searchcore.settings.indexer.tca.allowedTables} tt_content { - additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu') + additionalWhereClause = {$plugin.tx_searchcore.settings.indexer.tca.tt_content.additionalWhereClause} } } } diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index b41a0d1..fb51d11 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -15,14 +15,16 @@ mode of TYPO3. Do so by placing the following line at the end:: We will use references inside the extension to make the above unnecessary in the future. -Currently no constants are available, but this will change in the near future to make configuration -easier. - The structure is following TYPO3 Extbase conventions. All settings are placed inside of:: plugin.tx_searchcore.settings -Here is the example default configuration that's provided through static setup: +Here is the example default configuration that's provided through static include: + +.. literalinclude:: ../../Configuration/TypoScript/constants.txt + :language: typoscript + :linenos: + :caption: Static TypoScript Constants .. literalinclude:: ../../Configuration/TypoScript/setup.txt :language: typoscript @@ -145,7 +147,7 @@ The following settings are available. For each setting its documented which inde The page attribute *No Search* is also taken into account to prevent indexing records from only one page without recursion. - Contains a comma separated list of table names. Spaces are trimmed. + Contains a comma separated list of page uids. Spaces are trimmed. Example::