Completed
Push — master ( 152c11...b89aef )
by
unknown
10:16
created

SolrIndexCheck::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace SilverStripe\EnvironmentCheck\Checks;
4
5
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
6
use SilverStripe\FullTextSearch\Solr\Solr;
7
use SilverStripe\FullTextSearch\Solr\SolrIndex;
8
9
/**
10
 * Check the availability of all Solr indexes
11
 *
12
 * If there are no indexes of given class found, the returned status will still be "OK".
13
 *
14
 * @package environmentcheck
15
 */
16
class SolrIndexCheck implements EnvironmentCheck
17
{
18
    /**
19
     * {@inheritDoc}
20
     *
21
     * @return array
22
     */
23
    public function check()
24
    {
25
        $brokenCores = [];
26
27
        if (!class_exists(Solr::class)) {
28
            return [
29
                EnvironmentCheck::ERROR,
30
                'Class `' . Solr::class . '` not found. Is the fulltextsearch module installed?'
31
            ];
32
        }
33
34
        $service = Solr::service();
35
        foreach (Solr::get_indexes() as $index) {
36
            /** @var SolrIndex $core */
37
            $core = $index->getIndexName();
38
            if (!$service->coreIsActive($core)) {
39
                $brokenCores[] = $core;
40
            }
41
        }
42
43
        if (!empty($brokenCores)) {
44
            return [
45
                EnvironmentCheck::ERROR,
46
                'The following indexes are unavailable: ' . implode($brokenCores, ', ')
47
            ];
48
        }
49
50
        return [EnvironmentCheck::OK, 'Expected indexes are available.'];
51
    }
52
}
53