You are here

function search_api_solr_requirements in Search API Solr 7

Same name and namespace in other branches
  1. 8.3 search_api_solr.install \search_api_solr_requirements()
  2. 8 search_api_solr.install \search_api_solr_requirements()
  3. 8.2 search_api_solr.install \search_api_solr_requirements()
  4. 4.x search_api_solr.install \search_api_solr_requirements()

Implements hook_requirements().

1 call to search_api_solr_requirements()
search_api_solr_help in ./search_api_solr.module
Implements hook_help().

File

./search_api_solr.install, line 17

Code

function search_api_solr_requirements($phase) {
  $ret = array();
  if ($phase == 'runtime') {
    $servers = search_api_server_load_multiple(FALSE, array(
      'class' => 'search_api_solr_service',
      'enabled' => TRUE,
    ));
    $count = 0;
    $unavailable = 0;
    $last = NULL;
    foreach ($servers as $server) {
      if (!$server
        ->ping()) {
        ++$unavailable;
        $last = $server;
      }
      ++$count;
    }
    if (!$count) {
      return array();
    }
    $ret['search_api_solr'] = array(
      'title' => t('Solr servers'),
      'value' => format_plural($count, '1 server', '@count servers'),
    );
    if ($unavailable) {
      if ($unavailable == 1) {
        $ret['search_api_solr']['description'] = t('The Solr server of <a href="!url">%name</a> could not be reached.', array(
          '!url' => url('admin/config/search/search_api/server/' . $last->machine_name),
          '%name' => $last->name,
        ));
      }
      else {
        $ret['search_api_solr']['description'] = t('@count Solr servers could not be reached.', array(
          '@count' => $unavailable,
        ));
      }
      $ret['search_api_solr']['severity'] = REQUIREMENT_ERROR;
    }
    else {
      $ret['search_api_solr']['description'] = format_plural($count, 'The Solr server could be reached.', 'All @count Solr servers could be reached.');
      $ret['search_api_solr']['severity'] = REQUIREMENT_OK;
    }
  }
  return $ret;
}