Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Commit

Permalink
fix(indexing): avoid throwing fatal error in admin
Browse files Browse the repository at this point in the history
Closes: #651
  • Loading branch information
rayrutjes committed Aug 9, 2017
1 parent 9dfe812 commit 966d55c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
17 changes: 14 additions & 3 deletions includes/watchers/class-algolia-post-changes-watcher.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use AlgoliaSearch\AlgoliaException;

class Algolia_Post_Changes_Watcher implements Algolia_Changes_Watcher
{
/**
Expand Down Expand Up @@ -46,7 +48,11 @@ public function sync_item( $post_id ) {
return;
}

$this->index->sync( $post );
try {
$this->index->sync( $post );
} catch ( AlgoliaException $exception ) {
error_log( $exception->getMessage() );
}
}

/**
Expand All @@ -58,7 +64,11 @@ public function delete_item( $post_id ) {
return;
}

$this->index->delete_item( $post );
try {
$this->index->delete_item( $post );
} catch ( AlgoliaException $exception ) {
error_log( $exception->getMessage() );
}
}

/**
Expand All @@ -70,6 +80,7 @@ public function on_meta_change( $meta_id, $object_id, $meta_key ) {
if ( '_thumbnail_id' !== $meta_key ) {
return;
}
$this->sync_item( $object_id );

$this->sync_item( $object_id );
}
}
15 changes: 12 additions & 3 deletions includes/watchers/class-algolia-term-changes-watcher.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use AlgoliaSearch\AlgoliaException;

class Algolia_Term_Changes_Watcher implements Algolia_Changes_Watcher
{
/**
Expand Down Expand Up @@ -41,7 +43,11 @@ public function sync_item( $term_id ) {
return;
}

$this->index->sync( $term );
try {
$this->index->sync( $term );
} catch ( AlgoliaException $exception ) {
error_log( $exception->getMessage() );
}
}

/**
Expand All @@ -58,7 +64,6 @@ public function handle_changes( $object_id, $terms, $tt_ids, $taxonomy, $append,
foreach ( $terms_to_sync as $term_id ) {
$this->sync_item( $term_id );
}

}

/**
Expand All @@ -72,6 +77,10 @@ public function on_delete_term( $term, $tt_id, $taxonomy, $deleted_term ) {
return;
}

$this->index->delete_item( $deleted_term );
try {
$this->index->delete_item( $deleted_term );
} catch ( AlgoliaException $exception ) {
error_log( $exception->getMessage() );
}
}
}
14 changes: 12 additions & 2 deletions includes/watchers/class-algolia-user-changes-watcher.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use AlgoliaSearch\AlgoliaException;

class Algolia_User_Changes_Watcher implements Algolia_Changes_Watcher
{
/**
Expand Down Expand Up @@ -46,7 +48,11 @@ public function sync_item( $user_id ) {
return;
}

$this->index->sync( $user );
try {
$this->index->sync( $user );
} catch ( AlgoliaException $exception ) {
error_log( $exception->getMessage() );
}
}

/**
Expand All @@ -59,7 +65,11 @@ public function delete_item( $user_id ) {
return;
}

$this->index->delete_item( $user );
try {
$this->index->delete_item( $user );
} catch ( AlgoliaException $exception ) {
error_log( $exception->getMessage() );
}
}

/**
Expand Down

0 comments on commit 966d55c

Please sign in to comment.