silverstripe-environmentcheck/code/checks/SolrIndexCheck.php
Christopher Pitt 53aafd97ba Made supported
2015-09-14 09:12:12 +12:00

54 lines
1.1 KiB
PHP

<?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".
*/
class SolrIndexCheck implements EnvironmentCheck {
/**
* @var null|string
*/
protected $indexClass;
/**
* @param string $indexClass Limit the index checks to the specified class and all its subclasses.
*/
function __construct($indexClass = null) {
$this->indexClass = $indexClass;
}
/**
* @inheritdoc
*
* @return array
*/
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.');
}
}