Skip to content

Commit b257209

Browse files
Merge pull request #3028 from aarongerig/patch-3
[IndexBundle] OpenSearchWorker: Refactor delete methods for index operations
2 parents fcc261a + aa11b2f commit b257209

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/CoreShop/Bundle/IndexBundle/Worker/OpenSearchWorker.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,31 @@ public function renameIndexStructures(IndexInterface $index, string $oldName, st
162162
*/
163163
public function deleteFromIndexById(IndexInterface $index, int $id): void
164164
{
165-
$this->getClient($index)
166-
->delete([
167-
'index' => $this->getIndexName($index->getName()),
168-
'id' => (string) $id,
169-
])
170-
;
165+
$client = $this->getClient($index);
166+
$indexName = $this->getIndexName($index->getName());
167+
168+
if (!$client->exists(['index' => $indexName, 'id' => (string) $id])) {
169+
return;
170+
}
171+
172+
$client->delete([
173+
'index' => $indexName,
174+
'id' => (string) $id,
175+
]);
171176
}
172177

173178
/**
174179
* @inheritDoc
175180
*/
176181
public function deleteFromIndex(IndexInterface $index, IndexableInterface $object): void
177182
{
178-
$this->getClient($index)
179-
->delete([
180-
'index' => $this->getIndexName($index->getName()),
181-
'id' => (string) $object->getId(),
182-
])
183-
;
183+
$id = $object->getId();
184+
185+
if (!is_int($id)) {
186+
return;
187+
}
188+
189+
$this->deleteFromIndexById($index, $id);
184190
}
185191

186192
/**

0 commit comments

Comments
 (0)