-
Notifications
You must be signed in to change notification settings - Fork 14
/
search_api_solr.install
46 lines (43 loc) · 1.68 KB
/
search_api_solr.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* Implements hook_requirements().
*/
function search_api_solr_requirements($phase) {
$ret = array();
if ($phase == 'runtime') {
/** @var \Drupal\search_api\ServerInterface[] $servers */
$servers = entity_load_multiple_by_properties('search_api_server', array('backend' => 'search_api_solr', 'status' => TRUE));
$count = 0;
$unavailable = 0;
$last = NULL;
foreach ($servers as $server) {
if (!$server->getBackend()->ping()) {
++$unavailable;
$last = $server;
}
++$count;
}
if (!$count) {
return array();
}
$ret['search_api_solr'] = array(
'title' => \Drupal::translation()->translate('Solr servers'),
'value' => \Drupal::translation()->formatPlural($count, '1 server', '@count servers'),
);
if ($unavailable) {
if ($unavailable == 1) {
$ret['search_api_solr']['description'] = \Drupal::translation()->translate('The Solr server of <a href="!url">%name</a> could not be reached.',
array('!url' => \Drupal\Core\Url::fromRoute('entity.search_api_server.canonical', array('search_api_server' => $last->id()))->toString(), '%name' => $last->label()));
}
else {
$ret['search_api_solr']['description'] = \Drupal::translation()->translate('@count Solr servers could not be reached.', array('@count' => $unavailable));
}
$ret['search_api_solr']['severity'] = REQUIREMENT_ERROR;
}
else {
$ret['search_api_solr']['description'] = \Drupal::translation()->formatPlural($count, 'The Solr server could be reached.', 'All @count Solr servers could be reached.');
$ret['search_api_solr']['severity'] = REQUIREMENT_OK;
}
}
return $ret;
}