From aa11b2f24a2dd68b202a2884eb3bb90611e63bfc Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 1 May 2026 16:03:09 +0200 Subject: [PATCH] Refactor delete methods for index operations --- .../IndexBundle/Worker/OpenSearchWorker.php | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/CoreShop/Bundle/IndexBundle/Worker/OpenSearchWorker.php b/src/CoreShop/Bundle/IndexBundle/Worker/OpenSearchWorker.php index a0c333d190..dd5347f5ef 100644 --- a/src/CoreShop/Bundle/IndexBundle/Worker/OpenSearchWorker.php +++ b/src/CoreShop/Bundle/IndexBundle/Worker/OpenSearchWorker.php @@ -162,12 +162,17 @@ public function renameIndexStructures(IndexInterface $index, string $oldName, st */ public function deleteFromIndexById(IndexInterface $index, int $id): void { - $this->getClient($index) - ->delete([ - 'index' => $this->getIndexName($index->getName()), - 'id' => (string) $id, - ]) - ; + $client = $this->getClient($index); + $indexName = $this->getIndexName($index->getName()); + + if (!$client->exists(['index' => $indexName, 'id' => (string) $id])) { + return; + } + + $client->delete([ + 'index' => $indexName, + 'id' => (string) $id, + ]); } /** @@ -175,12 +180,13 @@ public function deleteFromIndexById(IndexInterface $index, int $id): void */ public function deleteFromIndex(IndexInterface $index, IndexableInterface $object): void { - $this->getClient($index) - ->delete([ - 'index' => $this->getIndexName($index->getName()), - 'id' => (string) $object->getId(), - ]) - ; + $id = $object->getId(); + + if (!is_int($id)) { + return; + } + + $this->deleteFromIndexById($index, $id); } /**