Skip to content

Commit 6a0059f

Browse files
author
Jan Petr
authored
Fail "Remove Algolia products" silently on non-existent index (#1111)
1 parent 843e308 commit 6a0059f

File tree

1 file changed

+20
-10
lines changed
  • app/code/community/Algolia/Algoliasearch/Helper

1 file changed

+20
-10
lines changed

app/code/community/Algolia/Algoliasearch/Helper/Data.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -735,20 +735,30 @@ public function deleteInactiveProducts($storeId)
735735

736736
$objectIds = array();
737737
$counter = 0;
738-
foreach ($index->browse('', array('attributesToRetrieve' => array('objectID'))) as $hit) {
739-
$objectIds[] = $hit['objectID'];
740-
$counter++;
741738

742-
if ($counter === 1000) {
743-
$this->deleteInactiveIds($storeId, $objectIds, $indexName);
739+
try {
740+
foreach ($index->browse('', array('attributesToRetrieve' => array('objectID'))) as $hit) {
741+
$objectIds[] = $hit['objectID'];
742+
$counter++;
743+
744+
if ($counter === 1000) {
745+
$this->deleteInactiveIds($storeId, $objectIds, $indexName);
744746

745-
$objectIds = array();
746-
$counter = 0;
747+
$objectIds = array();
748+
$counter = 0;
749+
}
747750
}
748-
}
749751

750-
if (!empty($objectIds)) {
751-
$this->deleteInactiveIds($storeId, $objectIds, $indexName);
752+
if (!empty($objectIds)) {
753+
$this->deleteInactiveIds($storeId, $objectIds, $indexName);
754+
}
755+
} catch (\AlgoliaSearch\AlgoliaException $e) {
756+
$message = $e->getMessage();
757+
758+
// Fail silently if the exception tells that Index does not exist
759+
if (!preg_match('/^Index (.*) does not exist$/', $message)) {
760+
throw $e;
761+
}
752762
}
753763
}
754764

0 commit comments

Comments
 (0)