Skip to content

Commit bab0c43

Browse files
committed
Virtual replica No index found issue
1 parent b54a4da commit bab0c43

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

Model/Observer/SaveSettings.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,26 @@ public function __construct(
6262
*/
6363
public function execute(Observer $observer)
6464
{
65-
$storeIds = array_keys($this->storeManager->getStores());
66-
foreach ($storeIds as $storeId) {
67-
$indexName = $this->helper->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId);
68-
$currentSettings = $this->algoliaHelper->getSettings($indexName);
69-
if (array_key_exists('replicas', $currentSettings)) {
70-
$this->algoliaHelper->setSettings($indexName, ['replicas' => []]);
71-
$setReplicasTaskId = $this->algoliaHelper->getLastTaskId();
72-
$this->algoliaHelper->waitLastTask($indexName, $setReplicasTaskId);
73-
if (count($currentSettings['replicas']) > 0) {
74-
foreach ($currentSettings['replicas'] as $replicaIndex) {
75-
$this->algoliaHelper->deleteIndex($replicaIndex);
65+
try {
66+
$storeIds = array_keys($this->storeManager->getStores());
67+
foreach ($storeIds as $storeId) {
68+
$indexName = $this->helper->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId);
69+
$currentSettings = $this->algoliaHelper->getSettings($indexName);
70+
if (array_key_exists('replicas', $currentSettings)) {
71+
$this->algoliaHelper->setSettings($indexName, ['replicas' => []]);
72+
$setReplicasTaskId = $this->algoliaHelper->getLastTaskId();
73+
$this->algoliaHelper->waitLastTask($indexName, $setReplicasTaskId);
74+
if (count($currentSettings['replicas']) > 0) {
75+
foreach ($currentSettings['replicas'] as $replicaIndex) {
76+
$this->algoliaHelper->deleteIndex($replicaIndex);
77+
}
7678
}
7779
}
7880
}
81+
} catch (\Exception $e) {
82+
if ($e->getMessage() !== 'Index does not exist') {
83+
throw $e;
84+
}
7985
}
8086
foreach ($storeIds as $storeId) {
8187
$this->indicesConfigurator->saveConfigurationToAlgolia($storeId);

0 commit comments

Comments
 (0)