You are here

function elasticsearch_watchdog_clear_log_submit in Elasticsearch Connector 7.2

Same name and namespace in other branches
  1. 7.5 modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc \elasticsearch_watchdog_clear_log_submit()
  2. 7 modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc \elasticsearch_watchdog_clear_log_submit()

Form submission handler for elasticsearch_watchdog_clear_log_form().

1 string reference to 'elasticsearch_watchdog_clear_log_submit'
elasticsearch_watchdog_clear_log_form in modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc
Form constructor for the form that clears out the log.

File

modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc, line 877
Created on Jan 06, 2014

Code

function elasticsearch_watchdog_clear_log_submit() {
  $_SESSION['elasticsearch_watchdog_overview_filter'] = array();

  // Delete the index and recreate it.
  $client_id = elasticsearch_watchdog_get_cluster_id();
  $index = elasticsearch_watchdog_get_index_name();
  $type = elasticsearch_watchdog_get_type_name_for_view();
  if (!empty($client_id)) {
    $client = elasticsearch_connector_get_client_by_id($client_id);
    if ($client) {
      try {
        $result = $client
          ->indices()
          ->deleteMapping(array(
          'index' => $index,
          'type' => $type,
        ));

        // Create the type if not exists.
        elasticsearch_watchdog_create_type($client, $index, $type);
        drupal_set_message(t('Elasticsearch logs has been cleared.'));
      } catch (Exception $e) {
        drupal_set_message($e
          ->getMessage(), 'error');
      }
    }
  }
}