function elasticsearch_watchdog_settings_validate in Elasticsearch Connector 7.2
Same name and namespace in other branches
- 7.5 modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc \elasticsearch_watchdog_settings_validate()
- 7 modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc \elasticsearch_watchdog_settings_validate()
Validate the setting form submission.
_state
Parameters
array $form:
1 string reference to 'elasticsearch_watchdog_settings_validate'
- elasticsearch_watchdog_settings in modules/
elasticsearch_watchdog/ elasticsearch_watchdog.admin.inc - Building a settings form for the Elasticsearch watchdog functionality.
File
- modules/
elasticsearch_watchdog/ elasticsearch_watchdog.admin.inc, line 57 - Created on Jan 06, 2014
Code
function elasticsearch_watchdog_settings_validate($form, &$form_state) {
$values = $form_state['values'];
if (!empty($form_state['triggering_element']['#ajax']) || empty($values['elasticsearch_watchdog_cluster_id']['index'])) {
return;
}
$client = elasticsearch_connector_get_client_by_id($values['elasticsearch_watchdog_cluster_id']['cluster_id']);
$index_name = elasticsearch_watchdog_get_realindex_name($values['elasticsearch_watchdog_cluster_id']['index']);
$alias_name = elasticsearch_watchdog_get_index_name($values['elasticsearch_watchdog_cluster_id']['index']);
$old_type_name = variable_get('elasticsearch_watchdog_type', NULL);
$type_name = elasticsearch_watchdog_get_type_name($values['elasticsearch_watchdog_type']);
if ($client) {
if (!$client
->indices()
->exists(array(
'index' => $index_name,
))) {
form_set_error('elasticsearch_watchdog_cluster_id', t('The index doesn\'t exists. Please created it before continue.'));
}
else {
if (!$client
->indices()
->existsType(array(
'index' => $index_name,
'type' => $type_name,
))) {
elasticsearch_watchdog_create_type($client, $index_name, $type_name);
}
// Alias
if (!$client
->indices()
->existsAlias(array(
'index' => $index_name,
'name' => $alias_name,
))) {
try {
elasticsearch_watchdog_create_alias($client, $index_name, $alias_name);
} catch (Exception $e) {
error_log($e
->getMessage());
}
}
if (isset($old_type_name) && $old_type_name != $type_name) {
try {
$client
->indices()
->deleteMapping(array(
'index' => $index_name,
'type' => $old_type_name,
));
drupal_set_message(t('The old type @type has been successfully deleted.', array(
'@type' => $old_type_name,
)));
} catch (Exception $e) {
error_log($e
->getMessage());
}
}
}
}
else {
form_set_error('elasticsearch_watchdog_cluster_id', t('Cannot connect to the cluster for some reason! Please contact your system administrator.'));
}
}