2015-03-11 05:22:24 +01:00
|
|
|
<?php
|
2015-09-10 23:13:48 +02:00
|
|
|
|
2017-01-04 23:16:12 +01:00
|
|
|
namespace SilverStripe\EnvironmentCheck\Checks;
|
|
|
|
|
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
|
|
|
|
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".
|
2017-01-04 23:16:12 +01:00
|
|
|
*
|
|
|
|
* @package environmentcheck
|
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
|
|
|
/**
|
2017-01-04 23:16:12 +01:00
|
|
|
* {@inheritDoc}
|
2015-11-21 07:18:35 +01:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function check()
|
|
|
|
{
|
2017-03-21 11:57:07 +01:00
|
|
|
$brokenCores = [];
|
2015-03-11 05:22:24 +01:00
|
|
|
|
2017-01-04 23:16:12 +01:00
|
|
|
/**
|
|
|
|
* @todo Revisit this when silverstripe/fulltextsearch has 4.x compat
|
|
|
|
*/
|
|
|
|
if (!class_exists('\\Solr')) {
|
2017-03-21 11:57:07 +01:00
|
|
|
return [
|
2015-11-21 07:18:35 +01:00
|
|
|
EnvironmentCheck::ERROR,
|
|
|
|
'Class `Solr` not found. Is the fulltextsearch module installed?'
|
2017-03-21 11:57:07 +01:00
|
|
|
];
|
2015-11-21 07:18:35 +01:00
|
|
|
}
|
2015-03-11 05:22:24 +01:00
|
|
|
|
2017-01-04 23:16:12 +01:00
|
|
|
$service = \Solr::service();
|
|
|
|
foreach (\Solr::get_indexes($this->indexClass) as $index) {
|
2015-11-21 07:18:35 +01:00
|
|
|
$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)) {
|
2017-03-21 11:57:07 +01:00
|
|
|
return [
|
2015-11-21 07:18:35 +01:00
|
|
|
EnvironmentCheck::ERROR,
|
|
|
|
'The following indexes are unavailable: ' . implode($brokenCores, ', ')
|
2017-03-21 11:57:07 +01:00
|
|
|
];
|
2015-11-21 07:18:35 +01:00
|
|
|
}
|
2015-03-11 05:22:24 +01:00
|
|
|
|
2017-03-21 11:57:07 +01:00
|
|
|
return [EnvironmentCheck::OK, 'Expected indexes are available.'];
|
2015-11-21 07:18:35 +01:00
|
|
|
}
|
2015-03-11 05:22:24 +01:00
|
|
|
}
|