mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-06-27 15:09:32 +02:00
Remove PHP 5.5 from Travis configuration. Dotenv used for environment management now, examples and tests updated to use putenv instead of define. Logger alias update to LoggerInterface. Update mutable config API calls. Replace array declaration with short version: []. Update license year.
66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\EnvironmentCheck\Checks;
|
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
|
|
|
/**
|
|
* 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".
|
|
*
|
|
* @package environmentcheck
|
|
*/
|
|
class SolrIndexCheck implements EnvironmentCheck
|
|
{
|
|
/**
|
|
* @var null|string
|
|
*/
|
|
protected $indexClass;
|
|
|
|
/**
|
|
* @param string $indexClass Limit the index checks to the specified class and all its subclasses.
|
|
*/
|
|
public function __construct($indexClass = null)
|
|
{
|
|
$this->indexClass = $indexClass;
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*
|
|
* @return array
|
|
*/
|
|
public function check()
|
|
{
|
|
$brokenCores = [];
|
|
|
|
/**
|
|
* @todo Revisit this when silverstripe/fulltextsearch has 4.x compat
|
|
*/
|
|
if (!class_exists('\\Solr')) {
|
|
return [
|
|
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 [
|
|
EnvironmentCheck::ERROR,
|
|
'The following indexes are unavailable: ' . implode($brokenCores, ', ')
|
|
];
|
|
}
|
|
|
|
return [EnvironmentCheck::OK, 'Expected indexes are available.'];
|
|
}
|
|
}
|