From 5989b65ae0534734e57f814dbd4332a14e562c1f Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 20 Dec 2016 10:04:44 +0100 Subject: [PATCH] FEATURE: Split configuration to support the concepts * Add a further level in configurations to support multiple connections and indexer. Relates: #31 --- Classes/Command/IndexCommandController.php | 2 +- .../Configuration/ConfigurationContainer.php | 31 +++++------ .../ConfigurationContainerInterface.php | 12 ++--- .../Connection/Elasticsearch/Connection.php | 4 +- .../Index/TcaIndexer/TcaTableService.php | 6 +-- Classes/Domain/Service/DataHandler.php | 2 +- Configuration/TypoScript/setup.txt | 26 ++++++---- Documentation/source/configuration.rst | 51 +++++++++++-------- Documentation/source/development.rst | 18 +++++++ Tests/Functional/Fixtures/BasicSetup.ts | 14 +++-- .../DataHandler/MultipleAllowedTables.ts | 6 ++- .../TcaIndexer/RespectRootLineBlacklist.ts | 6 ++- .../Fixtures/Indexing/UserWhereClause.ts | 8 +-- 13 files changed, 110 insertions(+), 76 deletions(-) diff --git a/Classes/Command/IndexCommandController.php b/Classes/Command/IndexCommandController.php index 01c6eed..c1ade27 100644 --- a/Classes/Command/IndexCommandController.php +++ b/Classes/Command/IndexCommandController.php @@ -57,7 +57,7 @@ class IndexCommandController extends CommandController { // TODO: Allow to index multiple tables at once? // TODO: Also allow to index everything? - if (! in_array($table, GeneralUtility::trimExplode(',', $this->configuration->get('index', 'allowedTables')))) { + if (! in_array($table, GeneralUtility::trimExplode(',', $this->configuration->get('indexer.tca.allowedTables')))) { $this->outputLine('Table is not allowed for indexing.'); $this->quit(1); } diff --git a/Classes/Configuration/ConfigurationContainer.php b/Classes/Configuration/ConfigurationContainer.php index 79496b9..56de674 100644 --- a/Classes/Configuration/ConfigurationContainer.php +++ b/Classes/Configuration/ConfigurationContainer.php @@ -21,6 +21,7 @@ namespace Leonmrni\SearchCore\Configuration; */ use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; +use TYPO3\CMS\Extbase\Utility\ArrayUtility; /** * Container of all configurations for extension. @@ -29,14 +30,14 @@ use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; class ConfigurationContainer implements ConfigurationContainerInterface { /** - * Plaint TypoScript array from extbase for extension / plugin. + * Plain TypoScript array from extbase for extension / plugin. * * @var array */ protected $settings; /** - * Inject news settings via ConfigurationManager. + * Inject settings via ConfigurationManager. * * @param ConfigurationManagerInterface $configurationManager */ @@ -50,34 +51,30 @@ class ConfigurationContainer implements ConfigurationContainerInterface } /** - * @param string $section - * @param string $key + * @param string $path In dot notation. * @return mixed * @throws InvalidArgumentException */ - public function get($section, $key) + public function get($path) { - if (!isset($this->settings[$section]) || !isset($this->settings[$section][$key])) { + $value = ArrayUtility::getValueByPath($this->settings, $path); + + if ($value === null) { throw new InvalidArgumentException( - 'The given configuration option does not exist.', + 'The given configuration option "' . $path . '" does not exist.', InvalidArgumentException::OPTION_DOES_NOT_EXIST ); } - return $this->settings[$section][$key]; + return $value; } /** - * @param string $section - * @param string $key - * @return mixed|null + * @param string $path In dot notation. + * @return mixed */ - public function getIfExists($section, $key) + public function getIfExists($path) { - try { - return $this->get($section, $key); - } catch (InvalidArgumentException $e) { - return null; - } + return ArrayUtility::getValueByPath($this->settings, $path); } } diff --git a/Classes/Configuration/ConfigurationContainerInterface.php b/Classes/Configuration/ConfigurationContainerInterface.php index 2b988c5..7bc45ef 100644 --- a/Classes/Configuration/ConfigurationContainerInterface.php +++ b/Classes/Configuration/ConfigurationContainerInterface.php @@ -30,20 +30,18 @@ interface ConfigurationContainerInterface extends Singleton { /** * Returns the option defined by section and key. - * May throw an exception if it's not set. + * May throw an exception if it's not set or is null. * - * @param string $section - * @param string $key + * @param string $path In dot notation. E.g. indexer.tca.allowedTables * @return mixed */ - public function get($section, $key); + public function get($path); /** * Same as get but will not throw an exception but return null. * - * @param string $section - * @param string $key + * @param string $path In dot notation. * @return mixed|null */ - public function getIfExists($section, $key); + public function getIfExists($path); } diff --git a/Classes/Connection/Elasticsearch/Connection.php b/Classes/Connection/Elasticsearch/Connection.php index 8fb0a64..3d6bf32 100644 --- a/Classes/Connection/Elasticsearch/Connection.php +++ b/Classes/Connection/Elasticsearch/Connection.php @@ -54,8 +54,8 @@ class Connection implements Singleton $this->elasticaClient = $elasticaClient; if ($this->elasticaClient === null) { $this->elasticaClient = new \Elastica\Client([ - 'host' => $this->configuration->get('connection', 'host'), - 'port' => $this->configuration->get('connection', 'port'), + 'host' => $this->configuration->get('connections.elasticsearch.host'), + 'port' => $this->configuration->get('connections.elasticsearch.port'), // TODO: Make configurable // 'log' => 'file', ]); diff --git a/Classes/Domain/Index/TcaIndexer/TcaTableService.php b/Classes/Domain/Index/TcaIndexer/TcaTableService.php index 0f963c0..ddf8e00 100644 --- a/Classes/Domain/Index/TcaIndexer/TcaTableService.php +++ b/Classes/Domain/Index/TcaIndexer/TcaTableService.php @@ -151,7 +151,7 @@ class TcaTableService . ' AND pages.no_search = 0' ; - $userDefinedWhere = $this->configuration->getIfExists('index', $this->tableName); + $userDefinedWhere = $this->configuration->getIfExists('indexer.tca.' . $this->tableName); if (is_string($userDefinedWhere)) { $whereClause .= $userDefinedWhere; } @@ -263,7 +263,7 @@ class TcaTableService */ protected function isBlackListedRootLineConfigured() { - return (bool) $this->configuration->getIfExists('index', 'rootLineBlacklist'); + return (bool) $this->configuration->getIfExists('indexer.tca.rootLineBlacklist'); } /** @@ -273,6 +273,6 @@ class TcaTableService */ protected function getBlackListedRootLine() { - return GeneralUtility::intExplode(',', $this->configuration->getIfExists('index', 'rootLineBlacklist')); + return GeneralUtility::intExplode(',', $this->configuration->getIfExists('indexer.tca.rootLineBlacklist')); } } diff --git a/Classes/Domain/Service/DataHandler.php b/Classes/Domain/Service/DataHandler.php index 752eaa8..213b9cc 100644 --- a/Classes/Domain/Service/DataHandler.php +++ b/Classes/Domain/Service/DataHandler.php @@ -86,7 +86,7 @@ class DataHandler implements Singleton */ public function getAllowedTablesForIndexing() { - return GeneralUtility::trimExplode(',', $this->configuration->get('index', 'allowedTables')); + return GeneralUtility::trimExplode(',', $this->configuration->get('indexer.tca.allowedTables')); } /** diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt index 5e22e71..0e5bd20 100644 --- a/Configuration/TypoScript/setup.txt +++ b/Configuration/TypoScript/setup.txt @@ -1,20 +1,24 @@ plugin { tx_searchcore { settings { - connection { - host = localhost - port = 9200 + connections { + elasticsearch { + host = localhost + port = 9200 + } } - index { - # 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 + 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 = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu') + tt_content { + additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu') + } } } } diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index 793df9c..b41a0d1 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -34,35 +34,36 @@ Here is the example default configuration that's provided through static setup: Options ------- -The following section contain the different options for e.g. -``plugin.tx_searchcore.settings.connection`` or ``plugin.tx_searchcore.settings.index``. - -.. warning:: - - The structure will change as we need to support multiple indexer and connections. - The options will stay the same. - - For further information take a look at :issue:`31`. +The following section contains the different options, e.g. for :ref:`connections` and +:ref:`indexer`: ``plugin.tx_searchcore.settings.connection`` or +``plugin.tx_searchcore.settings.index``. .. _configuration_options_connection: -connection -^^^^^^^^^^ +connections +^^^^^^^^^^^ -Holds settings regarding the connection to search service like Elasticsearch or Solr. +Holds settings regarding the different possible connections for search services like Elasticsearch +or Solr. Configured as:: plugin { tx_searchcore { settings { - connection { - // the settings + connections { + connectionName { + // the settings + } } } } } +Where ``connectionName`` is one of the available :ref:`connections`. + +The following settings are available. For each setting its documented which connection consumes it. + .. _host: ``host`` @@ -75,7 +76,7 @@ Configured as:: Example:: - plugin.tx_searchcore.settings.connection.host = localhost + plugin.tx_searchcore.settings.connections.elasticsearch.host = localhost .. _port: @@ -88,7 +89,7 @@ Configured as:: Example:: - plugin.tx_searchcore.settings.connection.port = 9200 + plugin.tx_searchcore.settings.connections.elasticsearch.port = 9200 .. _configuration_options_index: @@ -96,20 +97,26 @@ Configured as:: index ^^^^^ -Holds settings regarding the indexing of TYPO3 records to search service. +Holds settings regarding the indexing, e.g. of TYPO3 records, to search services. Configured as:: plugin { tx_searchcore { settings { - index { - // the settings + indexer { + indexerName { + // the settings + } } } } } +Where ``indexerName`` is one of the available :ref:`indexer`. + +The following settings are available. For each setting its documented which indexer consumes it. + .. _allowedTables: ``allowedTables`` @@ -124,7 +131,7 @@ Configured as:: Example:: - plugin.tx_searchcore.settings.index.allowedTables = tt_content, fe_users + plugin.tx_searchcore.settings.indexer.tca.allowedTables = tt_content, fe_users .. _rootLineBlacklist: @@ -142,7 +149,7 @@ Configured as:: Example:: - plugin.tx_searchcore.settings.index.rootLineBlacklist = 3, 10, 100 + plugin.tx_searchcore.settings.index.tca.rootLineBlacklist = 3, 10, 100 Also it's possible to define some behaviour for the different document types. In context of TYPO3 tables are used as document types 1:1. It's possible to configure different tables. The following @@ -161,7 +168,7 @@ options are available: Example:: - plugin.tx_searchcore.settings.index.tt_content.additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu') + plugin.tx_searchcore.settings.index.tca.tt_content.additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu') .. attention:: diff --git a/Documentation/source/development.rst b/Documentation/source/development.rst index 0913928..362ca56 100644 --- a/Documentation/source/development.rst +++ b/Documentation/source/development.rst @@ -1,3 +1,5 @@ +.. highlight:: bash + .. _contribution: Contribution @@ -7,6 +9,22 @@ Everyone is welcome to contribute, whether it's code, issues, feature requests o Below is a documentation what to respect during contributions. +.. _contribution_setup: + +Setup +----- + +To start contributions regarding code, make sure to setup your system:: + + git clone git@github.com:DanielSiepmann/search_core.git \ + && cd search_core \ + && make install \ + && make functionalTests + +If all tests are okay, start your work. + +Of course you might need some requirements like running elasticsearch and composer to work before. + .. _contribution_development: Development diff --git a/Tests/Functional/Fixtures/BasicSetup.ts b/Tests/Functional/Fixtures/BasicSetup.ts index a1b143c..510e2a1 100644 --- a/Tests/Functional/Fixtures/BasicSetup.ts +++ b/Tests/Functional/Fixtures/BasicSetup.ts @@ -1,13 +1,17 @@ plugin { tx_searchcore { settings { - connection { - host = localhost - port = 9200 + connections { + elasticsearch { + host = localhost + port = 9200 + } } - index { - allowedTables = tt_content + indexer { + tca { + allowedTables = tt_content + } } } } diff --git a/Tests/Functional/Fixtures/Hooks/DataHandler/MultipleAllowedTables.ts b/Tests/Functional/Fixtures/Hooks/DataHandler/MultipleAllowedTables.ts index 7f91f88..8fd7407 100644 --- a/Tests/Functional/Fixtures/Hooks/DataHandler/MultipleAllowedTables.ts +++ b/Tests/Functional/Fixtures/Hooks/DataHandler/MultipleAllowedTables.ts @@ -1,8 +1,10 @@ plugin { tx_searchcore { settings { - index { - allowedTables = tt_content, fe_user + indexer { + tca { + allowedTables = tt_content, fe_user + } } } } diff --git a/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts b/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts index 4c134e6..44013e7 100644 --- a/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts +++ b/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts @@ -1,8 +1,10 @@ plugin { tx_searchcore { settings { - index { - rootLineBlacklist = 3 + indexer { + tca { + rootLineBlacklist = 3 + } } } } diff --git a/Tests/Functional/Fixtures/Indexing/UserWhereClause.ts b/Tests/Functional/Fixtures/Indexing/UserWhereClause.ts index 641eaf5..d79bb14 100644 --- a/Tests/Functional/Fixtures/Indexing/UserWhereClause.ts +++ b/Tests/Functional/Fixtures/Indexing/UserWhereClause.ts @@ -1,9 +1,11 @@ plugin { tx_searchcore { settings { - index { - tt_content { - additionalWhereClause = tt_content.CType NOT IN ('div') + indexer { + tca { + tt_content { + additionalWhereClause = tt_content.CType NOT IN ('div') + } } } }