You are here

function acquia_search_requirements in Acquia Search 3.x

Same name and namespace in other branches
  1. 6.3 acquia_search.install \acquia_search_requirements()
  2. 6 acquia_search.install \acquia_search_requirements()
  3. 2.x acquia_search.install \acquia_search_requirements()

Implements hook_requirements().

File

./acquia_search.install, line 16
Install, update, and uninstall functions for the Acquia Search Solr module.

Code

function acquia_search_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $requirements['acquia_search_ssl'] = [
      'title' => t('Acquia Search Solr'),
      'value' => 'Security',
    ];

    // Check SSL support.
    if (in_array('ssl', stream_get_transports(), TRUE)) {
      $requirements['acquia_search_ssl']['severity'] = REQUIREMENT_OK;
      $requirements['acquia_search_ssl']['description'] = t('The Acquia Search module is using SSL to protect the privacy of your content.');
    }
    else {
      $requirements['acquia_search_ssl']['severity'] = REQUIREMENT_WARNING;
      $requirements['acquia_search_ssl']['description'] = t('In order to protect the privacy of your content with the Acquia Search module you must have SSL support enabled in PHP on your host.');
    }

    /** @var \Drupal\search_api\Entity\Server[] $servers */
    $servers = Server::loadMultiple();
    $acquia_servers = array_filter($servers, function (Server $server) {
      return Runtime::isAcquiaServer($server);
    });

    // Show available Acquia Search Solr indexes.
    foreach ($acquia_servers as $server_id => $server) {
      $requirements['acquia_search_status_' . $server_id] = [
        'title' => t('Acquia Search connection status'),
        'severity' => REQUIREMENT_OK,
        'description' => [
          '#markup' => Messages::getSearchStatusMessage($server),
        ],
      ];
    }

    // Flag when read-only mode was forced because of not finding the right
    // index.
    if (Runtime::shouldEnforceReadOnlyMode()) {
      $requirements['acquia_search_read_only'] = [
        'title' => t('Acquia Search Solr'),
        'value' => t('Read-only warning'),
        'severity' => REQUIREMENT_WARNING,
        'description' => [
          '#markup' => Messages::getReadOnlyModeWarning(),
        ],
      ];
    }
    if (!Runtime::getPreferredSearchCoreService()
      ->isPreferredCoreAvailable()) {
      $requirements['acquia_search_read_only'] = [
        'title' => t('Acquia Search Solr'),
        'value' => t('No preferred search core'),
        'severity' => REQUIREMENT_ERROR,
        'description' => [
          '#markup' => Messages::getNoPreferredCoreError(),
        ],
      ];
    }
  }

  // Update the cached version whenever we may be updating the module.
  if ($phase == 'runtime' || $phase == 'update') {
    Storage::getVersion();
  }
  return $requirements;
}