silverstripe-environmentcheck/src/Checks/SolrIndexCheck.php

53 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2015-09-10 23:13:48 +02:00
namespace SilverStripe\EnvironmentCheck\Checks;
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
use SilverStripe\FullTextSearch\Solr\Solr;
use SilverStripe\FullTextSearch\Solr\SolrIndex;
/**
* Check the availability of all Solr indexes
*
2015-09-10 23:13:48 +02:00
* If there are no indexes of given class found, the returned status will still be "OK".
*
* @package environmentcheck
*/
2015-11-21 07:18:35 +01:00
class SolrIndexCheck implements EnvironmentCheck
{
/**
* {@inheritDoc}
2015-11-21 07:18:35 +01:00
*
* @return array
*/
public function check()
{
$brokenCores = [];
if (!class_exists(Solr::class)) {
return [
2015-11-21 07:18:35 +01:00
EnvironmentCheck::ERROR,
'Class `' . Solr::class . '` not found. Is the fulltextsearch module installed?'
];
2015-11-21 07:18:35 +01:00
}
$service = Solr::service();
foreach (Solr::get_indexes() as $index) {
/** @var SolrIndex $core */
2015-11-21 07:18:35 +01:00
$core = $index->getIndexName();
if (!$service->coreIsActive($core)) {
$brokenCores[] = $core;
}
}
2015-11-21 07:18:35 +01:00
if (!empty($brokenCores)) {
return [
2015-11-21 07:18:35 +01:00
EnvironmentCheck::ERROR,
2022-04-13 00:29:17 +02:00
'The following indexes are unavailable: ' . implode($brokenCores ?? '', ', ')
];
2015-11-21 07:18:35 +01:00
}
return [EnvironmentCheck::OK, 'Expected indexes are available.'];
2015-11-21 07:18:35 +01:00
}
}