mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
Add a new check for Solr core availability.
This is intended to be used with the silverstripe/fulltextsearch module.
This commit is contained in:
parent
05758843bc
commit
8485e1b30a
44
code/checks/SolrIndexCheck.php
Normal file
44
code/checks/SolrIndexCheck.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Check the availability of all Solr indexes of given class.
|
||||
* If there are no indexes of given class found, the returned status will still be "OK".
|
||||
*
|
||||
* @param $indexClass Limit the index checks to the specified class and all its subclasses.
|
||||
*/
|
||||
class SolrIndexCheck implements EnvironmentCheck {
|
||||
|
||||
protected $indexClass;
|
||||
|
||||
function __construct($indexClass = null) {
|
||||
$this->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.');
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user