Skip to content

Commit

Permalink
Merge pull request #147 from tripal/fix-146
Browse files Browse the repository at this point in the history
Fix error spamming issue #146
  • Loading branch information
almasaeed2010 authored Jan 29, 2018
2 parents 96df3fb + c5d5004 commit 77e4f3d
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions tripal_elasticsearch.module
Original file line number Diff line number Diff line change
Expand Up @@ -756,14 +756,19 @@ function tripal_elasticsearch_form_tripal_elasticsearch_build_search_block_form_
* Implements hook_node_update().
*/
function tripal_elasticsearch_node_update($node) {
static $tripal_elasticsearch_errors = FALSE;

try {
$es = new ESInstance();
$indices = $es->getIndices();
if (!in_array('website', $indices)) {
return;
}
} catch (Exception $exception) {
watchdog('tripal_elasticsearch', $exception->getMessage(), [], WATCHDOG_ERROR);
if (!$tripal_elasticsearch_errors) {
watchdog('tripal_elasticsearch', $exception->getMessage(), [], WATCHDOG_ERROR);
$tripal_elasticsearch_errors = TRUE;
}
}

// Delete entity if it's status changed
Expand All @@ -788,14 +793,17 @@ function tripal_elasticsearch_node_insert($node) {
* Implements hook_node_delete().
*/
function tripal_elasticsearch_node_delete($node) {
static $tripal_elasticsearch_errors = FALSE;

try {
$es = new ESInstance();
$es->deleteEntry('website', 'website', $node->nid);
$message = 'Removed document ' . $node->nid . 'from index "website"';
watchdog('tripal_elasticsearch', $message);
} catch (\Exception $e) {
$message = $e->getMessage() . ' Failed to delete indexed node ' . $node->nid;
watchdog('tripal_elasticsearch', $message, WATCHDOG_WARNING);
if (!$tripal_elasticsearch_errors) {
$message = $e->getMessage() . ' Failed to delete indexed node ' . $node->nid;
watchdog('tripal_elasticsearch', $message, WATCHDOG_WARNING);
$tripal_elasticsearch_errors = TRUE;
}
}
}

Expand All @@ -810,14 +818,19 @@ function tripal_elasticsearch_entity_update($entity, $entity_type) {
return;
}

static $tripal_elasticsearch_errors = FALSE;

try {
$es = new ESInstance();
$indices = $es->getIndices();
if (!in_array('entities', $indices)) {
return;
}
} catch (Exception $exception) {
watchdog('tripal_elasticsearch', $exception->getMessage(), [], WATCHDOG_ERROR);
if (!$tripal_elasticsearch_errors) {
watchdog('tripal_elasticsearch', $exception->getMessage(), [], WATCHDOG_ERROR);
$tripal_elasticsearch_errors = TRUE;
}
}

// Delete entity if it's status changed
Expand Down Expand Up @@ -862,14 +875,19 @@ function tripal_elasticsearch_entity_delete($entity, $type) {
return;
}

static $tripal_elasticsearch_errors = FALSE;

try {
$es = new ESInstance();
$es->deleteEntry('entities', 'entities', $entity->id);
$message = 'Removed document ' . $entity->id . 'from index "entities"';
watchdog('tripal_elasticsearch', $message, WATCHDOG_INFO);
} catch (\Exception $e) {
$message = $e->getMessage() . ' Failed to delete indexed entity ' . $entity->id;
watchdog('tripal_elasticsearch', $message, WATCHDOG_WARNING);
if (!$tripal_elasticsearch_errors) {
$message = $e->getMessage() . ' Failed to delete indexed entity ' . $entity->id;
watchdog('tripal_elasticsearch', $message, WATCHDOG_WARNING);
$tripal_elasticsearch_errors = TRUE;
}
}
}

Expand Down

0 comments on commit 77e4f3d

Please sign in to comment.