You are here

acquia_search.install in Acquia Connector 8

Install, update, and uninstall functions for the Acquia Connector module.

File

acquia_search/acquia_search.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Acquia Connector module.
 */
use Drupal\acquia_connector\Subscription;
use Drupal\search_api\Entity\Server;

/**
 * Implements hook_install().
 */
function acquia_search_install() {

  // Send a heartbeat so the Acquia Network knows the module is enabled.
  // This causes an invocation of hook_acquia_subscription_status() which is
  // implemented in this module to set up the environment.
  // Rebuild data about all currently available modules.
  \Drupal::service('extension.list.module')
    ->reset();
  _acquia_search_set_version();
  $subscription = new Subscription();
  $subscription
    ->update();
}

/**
 * Implements hook_requirements().
 */
function acquia_search_requirements($phase) {
  $requirements = [];

  // Ensure translations don't break at install time
  // Skip install checks if install.php is running. The weak install profile
  // API means install.php calls hook_requirements for every module in
  // a profile.
  if ($phase == 'install' && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'install')) {
    if (class_exists('Drupal\\acquia_connector\\Subscription')) {
      $subscription = new Subscription();
      if ($subscription
        ->hasCredentials()) {
        $severity = REQUIREMENT_OK;
      }
      else {
        $severity = REQUIREMENT_ERROR;
      }
      $requirements['acquia_search_credentials'] = [
        'description' => t('In order to use Acquia search module you must have an Acquia Subscription. Please enter your Acquia Subscription keys.'),
        'severity' => $severity,
        'value' => '',
      ];
    }
    else {
      $severity = REQUIREMENT_ERROR;
      $requirements['acquia_search_credentials'] = [
        'description' => t('In order to use Acquia search module you must enable and configure the Acquia Connector module.'),
        'severity' => $severity,
        'value' => '',
      ];
    }
  }
  if ($phase == 'runtime') {

    // Check SSL support.
    if (in_array('ssl', stream_get_transports(), TRUE)) {
      $severity = REQUIREMENT_OK;
      $requirements['acquia_search_ssl'] = [
        'description' => t('The Acquia Search module is using SSL to protect the privacy of your content.'),
      ];
    }
    else {
      $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.'),
      ];
    }
    $requirements['acquia_search_ssl']['title'] = t('Acquia Search security');
    $requirements['acquia_search_ssl']['severity'] = $severity;
    $requirements['acquia_search_ssl']['value'] = '';
    $servers = Server::loadMultiple();
    $acquia_servers = array_filter($servers, function ($server) {
      return acquia_search_is_acquia_server($server
        ->getBackendConfig());
    });

    // Show available Acquia search 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' => acquia_search_get_search_status_message($server),
        ],
      ];
    }

    // Flag when read-only mode was forced because of not finding the right
    // index.
    if (acquia_search_should_set_read_only_mode()) {
      $requirements['acquia_search_read_only'] = [
        'title' => t('Acquia Search read-only warning'),
        'severity' => REQUIREMENT_WARNING,
        'value' => acquia_search_get_read_only_mode_warning(),
      ];
    }

    // Flag if acquia_search_multi_subs module is enabled.
    if (\Drupal::moduleHandler()
      ->moduleExists('acquia_search_multi_subs')) {
      $requirements['acquia_search_asms'] = [
        'title' => t('Acquia Search module warning'),
        'severity' => REQUIREMENT_WARNING,
        'description' => t('Warning: acquia_search_multi_subs.module is enabled, but most of its functionality is now included in the Acquia Search module. Please read <a href="@url">our documentation</a>.', [
          '@url' => 'https://docs.acquia.com/acquia-search/multiple-cores/',
        ]),
      ];
    }
  }

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

/**
 * Helper function to cache the Acquia Search version.
 */
function _acquia_search_set_version() {

  // Cache the version in a variable so we can send it at not extra cost.
  $version = \Drupal::config('acquia_search.settings')
    ->get('version');
  $info = \Drupal::service('extension.list.module')
    ->getExtensionInfo('acquia_search');

  // Send the version, or at least the core compatibility as a fallback.
  $new_version = isset($info['version']) ? (string) $info['version'] : (string) \Drupal::VERSION;
  if ($version != $new_version) {
    \Drupal::configFactory()
      ->getEditable('acquia_search.settings')
      ->set('version', $new_version)
      ->save();
  }
}

/**
 * Implements hook_uninstall().
 */
function acquia_search_uninstall() {
  \Drupal::state()
    ->deleteMultiple([
    'acquia_search.v3_api_host',
    'acquia_search.v3_api_key',
  ]);
}

Functions

Namesort descending Description
acquia_search_install Implements hook_install().
acquia_search_requirements Implements hook_requirements().
acquia_search_uninstall Implements hook_uninstall().
_acquia_search_set_version Helper function to cache the Acquia Search version.