2015-03-11 05:22:24 +01:00
|
|
|
<?php
|
2015-09-10 23:13:48 +02:00
|
|
|
|
2015-03-11 05:22:24 +01: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".
|
2015-03-11 05:22:24 +01:00
|
|
|
*/
|
2015-11-21 07:18:35 +01:00
|
|
|
class SolrIndexCheck implements EnvironmentCheck
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var null|string
|
|
|
|
*/
|
|
|
|
protected $indexClass;
|
2015-09-10 23:13:48 +02:00
|
|
|
|
2015-11-21 07:18:35 +01:00
|
|
|
/**
|
|
|
|
* @param string $indexClass Limit the index checks to the specified class and all its subclasses.
|
|
|
|
*/
|
|
|
|
public function __construct($indexClass = null)
|
|
|
|
{
|
|
|
|
$this->indexClass = $indexClass;
|
|
|
|
}
|
2015-09-10 23:13:48 +02:00
|
|
|
|
2015-11-21 07:18:35 +01:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function check()
|
|
|
|
{
|
|
|
|
$brokenCores = array();
|
2015-03-11 05:22:24 +01:00
|
|
|
|
2015-11-21 07:18:35 +01:00
|
|
|
if (!class_exists('Solr')) {
|
|
|
|
return array(
|
|
|
|
EnvironmentCheck::ERROR,
|
|
|
|
'Class `Solr` not found. Is the fulltextsearch module installed?'
|
|
|
|
);
|
|
|
|
}
|
2015-03-11 05:22:24 +01:00
|
|
|
|
2015-11-21 07:18:35 +01:00
|
|
|
$service = Solr::service();
|
|
|
|
foreach (Solr::get_indexes($this->indexClass) as $index) {
|
|
|
|
$core = $index->getIndexName();
|
|
|
|
if (!$service->coreIsActive($core)) {
|
|
|
|
$brokenCores[] = $core;
|
|
|
|
}
|
|
|
|
}
|
2015-03-11 05:22:24 +01:00
|
|
|
|
2015-11-21 07:18:35 +01:00
|
|
|
if (!empty($brokenCores)) {
|
|
|
|
return array(
|
|
|
|
EnvironmentCheck::ERROR,
|
|
|
|
'The following indexes are unavailable: ' . implode($brokenCores, ', ')
|
|
|
|
);
|
|
|
|
}
|
2015-03-11 05:22:24 +01:00
|
|
|
|
2015-11-21 07:18:35 +01:00
|
|
|
return array(EnvironmentCheck::OK, 'Expected indexes are available.');
|
|
|
|
}
|
2015-03-11 05:22:24 +01:00
|
|
|
}
|