You are here

search_api_elasticsearch_elastica.install in Search API Elasticsearch 7

Install/Uninstall tasks for the Search API Elasticsearch Elastica module.

File

modules/elastica/search_api_elasticsearch_elastica.install
View source
<?php

/**
 * @file
 * Install/Uninstall tasks for the Search API Elasticsearch Elastica module.
 */

/**
 * Implements hook_requirements().
 *
 * Check Elastica installation.
 */
function search_api_elasticsearch_elastica_requirements($phase) {
  if ($phase === 'install') {
    $t = get_t();
    module_load_include('module', 'search_api_elasticsearch_elastica');
    spl_autoload_register('_search_api_elasticsearch_elastica_autoload');
    if (class_exists('Elastica\\Client')) {
      return array(
        'search_api_elasticsearch_elastica' => array(
          'title' => $t('Elastica PHP library'),
          'description' => $t('The library was correctly installed.'),
          'severity' => REQUIREMENT_OK,
        ),
      );
    }
    else {
      return array(
        'search_api_elasticsearch_elastica' => array(
          'title' => $t('Elastica PHP library'),
          'description' => $t('The library was not correctly installed. Please see INSTALL.txt for instructions.'),
          'severity' => REQUIREMENT_WARNING,
        ),
      );
    }
  }
}

/**
 * Implements hook_disable().
 *
 * Disable Search API servers and associated indexes using the Elastica client.
 */
function search_api_elasticsearch_elastica_disable() {
  if (module_exists('search_api')) {
    module_load_include('module', 'search_api');
    foreach (search_api_server_load_multiple(FALSE, array(
      'class' => 'search_api_elasticsearch_elastica_service',
    ), TRUE) as $server) {
      $server
        ->update(array(
        'enabled' => 0,
      ));
    }
  }
}

/**
 * Implements hook_uninstall().
 *
 * Delete Search API servers using the Elastica client.
 */
function search_api_elasticsearch_uninstall() {
  if (module_exists('search_api')) {
    db_delete('search_api_server')
      ->condition('class', 'search_api_elasticsearch_elastica_service')
      ->execute();
  }
}