From 8485e1b30a869856433e121969eae42fa8c734da Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Wed, 11 Mar 2015 17:22:24 +1300 Subject: [PATCH] Add a new check for Solr core availability. This is intended to be used with the silverstripe/fulltextsearch module. --- code/checks/SolrIndexCheck.php | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 code/checks/SolrIndexCheck.php diff --git a/code/checks/SolrIndexCheck.php b/code/checks/SolrIndexCheck.php new file mode 100644 index 0000000..145641f --- /dev/null +++ b/code/checks/SolrIndexCheck.php @@ -0,0 +1,44 @@ +indexClass = $indexClass; + } + + function check() { + $brokenCores = array(); + + if (!class_exists('Solr')) { + return array( + EnvironmentCheck::ERROR, + 'Class `Solr` not found. Is the fulltextsearch module installed?' + ); + } + + $service = Solr::service(); + foreach (Solr::get_indexes($this->indexClass) as $index) { + $core = $index->getIndexName(); + if (!$service->coreIsActive($core)) { + $brokenCores[] = $core; + } + } + + if (!empty($brokenCores)) { + return array( + EnvironmentCheck::ERROR, + 'The following indexes are unavailable: ' . implode($brokenCores, ', ') + ); + } + + return array(EnvironmentCheck::OK, 'Expected indexes are available.'); + } + +}