You are here

function apachesolr_requirements in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 apachesolr.install \apachesolr_requirements()
  2. 5.2 apachesolr.install \apachesolr_requirements()
  3. 5 apachesolr.module \apachesolr_requirements()
  4. 6 apachesolr.install \apachesolr_requirements()
  5. 6.2 apachesolr.install \apachesolr_requirements()
  6. 7 apachesolr.install \apachesolr_requirements()

Implements hook_requirements().

File

./apachesolr.install, line 11
Install and related hooks for apachesolr_search.

Code

function apachesolr_requirements($phase) {
  $requirements = array();
  if ($phase != 'runtime') {
    return $requirements;
  }

  // Ensure translations don't break at install time
  $t = get_t();
  $has_settings = FALSE;
  $id = apachesolr_default_environment();
  $environment = apachesolr_environment_load($id);
  if (!$environment || empty($environment['url'])) {
    $requirements['apachesolr'] = array(
      'title' => $t('Apache Solr'),
      'value' => $t('Missing environment configuration'),
      'description' => $t('Missing or invalid Solr environment record for the default environment ID %id.', array(
        '%id' => $id,
      )),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  else {
    $has_settings = TRUE;
  }
  if ($has_settings) {
    $ping = FALSE;
    try {
      $solr = apachesolr_get_solr($id);
      $ping = @$solr
        ->ping(variable_get('apachesolr_ping_timeout', 4));

      // If there is no $solr object, there is no instance available, so don't continue.
      if (!$ping) {
        throw new Exception(t('No Solr instance available when checking requirements.'));
      }
    } catch (Exception $e) {
      watchdog('Apache Solr', nl2br(check_plain($e
        ->getMessage())), NULL, WATCHDOG_ERROR);
    }
    $value = $ping ? $t('Your site has contacted the Apache Solr server.') : $t('Your site was unable to contact the Apache Solr server.');
    $severity = $ping ? REQUIREMENT_OK : REQUIREMENT_ERROR;
    $requirements['apachesolr'] = array(
      'title' => $t('Apache Solr'),
      'value' => $value,
      'description' => $t('Default environment url: <br/> %url', array(
        '%url' => $environment['url'],
      )),
      'severity' => $severity,
    );
  }
  return $requirements;
}