From 7a3e2d0823efe6bd8e18c1662efa92883da1097a Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 20 Mar 2018 16:32:32 +1300 Subject: [PATCH] NEW Allow autoconfigure to be disabled via configuration --- docs/en/index.md | 14 ++++++++++++++ src/Search/Updaters/SearchUpdater.php | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/docs/en/index.md b/docs/en/index.md index dc819d3..f835083 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -30,6 +30,20 @@ common interfaces to fulltext engine functionality, abstracting out common behav offers its own extensions, and there is some behaviour (such as getting the fulltext search engines installed, configured and running) that each connector deals with itself, in a way best suited to that search engine's design. +## Disabling automatic configuration + +If you have this module installed but do not have a Solr server running, you can disable the database manipulation +hooks that trigger automatic index updates: + +```yaml +# File: mysite/_config/search.yml +--- +Name: mysitesearch +--- +SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater: + enabled: false +``` + ## Basic usage Basic usage is a four step process: diff --git a/src/Search/Updaters/SearchUpdater.php b/src/Search/Updaters/SearchUpdater.php index dbb24f0..5d3d614 100644 --- a/src/Search/Updaters/SearchUpdater.php +++ b/src/Search/Updaters/SearchUpdater.php @@ -37,6 +37,14 @@ class SearchUpdater */ private static $flush_on_shutdown = true; + /** + * Whether the updater is enabled. Set to false for local development if you don't have a Solr server. + * + * @config + * @var bool + */ + private static $enabled = true; + public static $registered = false; /** @var SearchUpdateProcessor */ public static $processor = null; @@ -53,6 +61,10 @@ class SearchUpdater */ public static function handle_manipulation($manipulation) { + if (!static::config()->get('enabled')) { + return; + } + // First, extract any state that is in the manipulation itself foreach ($manipulation as $table => $details) { if (!isset($manipulation[$table]['class'])) {