These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Check the availability of all Solr indexes of given class. |
||
5 | * |
||
6 | * If there are no indexes of given class found, the returned status will still be "OK". |
||
7 | */ |
||
8 | class SolrIndexCheck implements EnvironmentCheck { |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
9 | /** |
||
10 | * @var null|string |
||
11 | */ |
||
12 | protected $indexClass; |
||
13 | |||
14 | /** |
||
15 | * @param string $indexClass Limit the index checks to the specified class and all its subclasses. |
||
16 | */ |
||
17 | function __construct($indexClass = null) { |
||
0 ignored issues
–
show
|
|||
18 | $this->indexClass = $indexClass; |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * @inheritdoc |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | function check() { |
||
0 ignored issues
–
show
|
|||
27 | $brokenCores = array(); |
||
28 | |||
29 | if (!class_exists('Solr')) { |
||
30 | return array( |
||
31 | EnvironmentCheck::ERROR, |
||
32 | 'Class `Solr` not found. Is the fulltextsearch module installed?' |
||
33 | ); |
||
34 | } |
||
35 | |||
36 | $service = Solr::service(); |
||
37 | foreach (Solr::get_indexes($this->indexClass) as $index) { |
||
38 | $core = $index->getIndexName(); |
||
39 | if (!$service->coreIsActive($core)) { |
||
40 | $brokenCores[] = $core; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | if (!empty($brokenCores)) { |
||
45 | return array( |
||
46 | EnvironmentCheck::ERROR, |
||
47 | 'The following indexes are unavailable: ' . implode($brokenCores, ', ') |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | return array(EnvironmentCheck::OK, 'Expected indexes are available.'); |
||
52 | } |
||
53 | } |
||
54 |