You are here

function elasticsearch_watchdog_uninstall in Elasticsearch Connector 7.2

Same name and namespace in other branches
  1. 7.5 modules/elasticsearch_watchdog/elasticsearch_watchdog.install \elasticsearch_watchdog_uninstall()
  2. 7 modules/elasticsearch_watchdog/elasticsearch_watchdog.install \elasticsearch_watchdog_uninstall()

Implements hook_uninstall().

File

modules/elasticsearch_watchdog/elasticsearch_watchdog.install, line 11
Created on Jan 08, 2014

Code

function elasticsearch_watchdog_uninstall() {
  if (!module_exists('elasticsearch_connector')) {
    module_load_include('module', 'elasticsearch_connector');
  }
  module_load_include('module', 'elasticsearch_watchdog');
  $client_id = elasticsearch_watchdog_get_cluster_id();
  if (!empty($client_id)) {
    $client = elasticsearch_connector_get_client_by_id($client_id);
    if ($client) {
      $index = elasticsearch_watchdog_get_realindex_name();
      $type = elasticsearch_watchdog_get_type_name();
      $alias_name = elasticsearch_watchdog_get_index_name();
      $index_exists = $client
        ->indices()
        ->exists(array(
        'index' => $index,
      ));
      if ($index_exists) {
        $client
          ->indices()
          ->deleteAlias(array(
          'index' => $index,
          'name' => $alias_name,
        ));
        $client
          ->indices()
          ->deleteMapping(array(
          'index' => $index,
          'type' => $type,
        ));
        $result = $client
          ->indices()
          ->getMapping(array(
          'index' => $index,
        ));
        if (empty($result)) {
          $client
            ->indices()
            ->delete(array(
            'index' => $index,
          ));
        }
      }
    }
  }
  variable_del('elasticsearch_watchdog_cluster_id');
  variable_del('elasticsearch_watchdog_ttl');
  variable_del('elasticsearch_watchdog_index');
  variable_del('elasticsearch_watchdog_type');
  variable_del('elasticsearch_watchdog_types_view');
}