You are here

acquia_search.install in Acquia Connector 7.3

Install file.

File

acquia_search/acquia_search.install
View source
<?php

/**
 * @file
 * Install file.
 */

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

  // Ensure translations don't break at install time.
  $t = get_t();

  // 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 (module_invoke('acquia_agent', 'has_credentials')) {
      $severity = REQUIREMENT_OK;
    }
    else {
      $severity = REQUIREMENT_ERROR;
    }
    $requirements['acquia_search_credentials'] = array(
      'description' => $t('In order to use Acquia search module you must have an Acquia subscription. Please enter your Acquia subscription keys.'),
      'severity' => $severity,
      'value' => '',
    );
  }
  if ($phase == 'runtime') {

    // Check SSL support.
    if (in_array('ssl', stream_get_transports(), TRUE)) {
      $severity = REQUIREMENT_OK;
      $requirements['acquia_search_ssl'] = array(
        'description' => $t('The Acquia Search module is using SSL to protect the privacy of your content.'),
      );
    }
    else {
      $severity = REQUIREMENT_WARNING;
      $requirements['acquia_search_ssl'] = array(
        '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');
    $requirements['acquia_search_ssl']['severity'] = $severity;
    $requirements['acquia_search_ssl']['value'] = '';

    // Show available search indexes.
    $environments = apachesolr_load_all_environments();
    foreach ($environments as $env_id => $environment) {

      // Flag when read-only mode was forced because of not finding the right
      // index.
      if (isset($environment['overridden_by_acquia_search']) && $environment['overridden_by_acquia_search'] == ACQUIA_SEARCH_AUTO_OVERRIDE_READ_ONLY) {
        $msg = acquia_search_get_read_only_mode_warning($environment, $t);
        $requirements['acquia_search_read_only']['title'] = $t('Acquia Search');
        $requirements['acquia_search_read_only']['severity'] = REQUIREMENT_WARNING;
        $requirements['acquia_search_read_only']['value'] = $msg;
        break;
      }
    }

    // Flag if acquia_search_multi_subs module is enabled.
    if (module_exists('acquia_search_multi_subs')) {
      $requirements['acquia_search_read_only']['title'] = $t('Acquia Search');
      $requirements['acquia_search_read_only']['severity'] = REQUIREMENT_WARNING;
      $requirements['acquia_search_read_only']['value'] = $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>.', array(
        '@url' => 'https://docs.acquia.com/acquia-search/multiple-cores',
      ));
    }

    // Check Apache Solr API version.
    if (!defined('APACHESOLR_API_VERSION') || version_compare(APACHESOLR_API_VERSION, '3.0', '<')) {
      $requirements['acquia_search_apachesolr']['title'] = $t('Acquia Search');
      $requirements['acquia_search_apachesolr']['severity'] = REQUIREMENT_ERROR;
      $requirements['acquia_search_apachesolr']['description'] = $t('Apache Solr API Integration requires  API version 3.0.  Please upgrade your Apache Solr Search Integration module');
      $requirements['acquia_search_apachesolr']['value'] = $t('Incompatible API version');
    }
  }

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

/**
 * Implements hook_enable().
 */
function acquia_search_enable() {

  // Send a heartbeat so the Acquia Subscription 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.
  _acquia_search_set_version();
  acquia_agent_check_subscription();
}

/**
 * Implements hook_disable().
 */
function acquia_search_disable() {

  // Remove the base Acquia Search environment we added.
  apachesolr_environment_delete(ACQUIA_SEARCH_ENVIRONMENT_ID);
  apachesolr_environment_delete(ACQUIA_SEARCH_V3_ENVIRONMENT_ID);

  // Unset all other acquia search environments.
  $environments = apachesolr_load_all_environments();
  foreach ($environments as $environment) {
    if (!empty($environment['service_class']) && $environment['service_class'] === AcquiaSearchSolrService::class) {

      // Remove traces of acquia_search.
      // Unset our acquia url and set it back to default.
      $environment['url'] = 'http://localhost:8983/solr';

      // Emptying the service class, unsetting it would not work, since it would
      // not overwrite the old value.
      $environment['service_class'] = '';
      apachesolr_environment_save($environment);
    }
  }
  variable_del('acquia_search_derived_key_salt');
  variable_del('apachesolr_default_environment');

  // Make sure apachesolr search is the default search module.
  variable_set('search_default_module', 'apachesolr_search');
}

/**
 * Helper function for hook_install().
 */
function _acquia_search_find_block_region($block_regions = array()) {
  $regions_to_look_for = array(
    'left',
    /* garland & zen */
    'sidebar_first',
  );
  if ($matches = array_intersect($block_regions, $regions_to_look_for)) {
    return array_shift($matches);
  }
}

/**
 * Helper function for hook_install().
 */
function _acquia_search_get_default_facets() {
  $default_enabled_facets['apachesolr_search']['bundle'] = 'bundle';
  $default_enabled_facets['apachesolr_search']['is_uid'] = 'is_uid';
  return $default_enabled_facets;
}

/**
 * Implements hook_uninstall().
 */
function acquia_search_uninstall() {
  variable_del('acquia_search_derived_key_salt');
  variable_del('acquia_search_solr_core');
}

/**
 * Clear out old variables.
 */
function acquia_search_update_7000() {
  variable_del('acquia_search_host');
  variable_del('acquia_search_port');
  variable_del('acquia_search_path');
}

/**
 * Removing acquia_search_url variable as it has been split up.
 *
 * To acquia_search_base_url and acquia_search_path.
 */
function acquia_search_update_7001() {
  variable_del('acquia_search_url');
}

/**
 * Remove apachesolr_service_class if it was set to AcquiaSearchService.
 *
 * This can be left set incorrectly when upgrading from Drupal 6 to Drupal 7.
 */
function acquia_search_update_7002() {

  // No need to set apachesolr_service_class for Acquia, since each
  // environment can have a separate class.
  $class = variable_get('apachesolr_service_class', '');
  if ($class && strpos($class, 'Acquia') === 0) {
    variable_del('apachesolr_service_class');
  }
}

Functions

Namesort descending Description
acquia_search_disable Implements hook_disable().
acquia_search_enable Implements hook_enable().
acquia_search_requirements Implements hook_requirements().
acquia_search_uninstall Implements hook_uninstall().
acquia_search_update_7000 Clear out old variables.
acquia_search_update_7001 Removing acquia_search_url variable as it has been split up.
acquia_search_update_7002 Remove apachesolr_service_class if it was set to AcquiaSearchService.
_acquia_search_find_block_region Helper function for hook_install().
_acquia_search_get_default_facets Helper function for hook_install().