silverstripe-environmentcheck/code/checks/SolrIndexCheck.php

54 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2015-09-10 23:13:48 +02:00
/**
* Check the availability of all Solr indexes of given class.
*
2015-09-10 23:13:48 +02:00
* If there are no indexes of given class found, the returned status will still be "OK".
*/
class SolrIndexCheck implements EnvironmentCheck {
2015-09-10 23:13:48 +02:00
/**
* @var null|string
*/
protected $indexClass;
2015-09-10 23:13:48 +02:00
/**
* @param string $indexClass Limit the index checks to the specified class and all its subclasses.
*/
function __construct($indexClass = null) {
$this->indexClass = $indexClass;
}
2015-09-10 23:13:48 +02:00
/**
* @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.');
}
}