Skip to content

Commit

Permalink
Merge pull request #227 from delyriand/fix/avoid-excption-during-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran authored Dec 23, 2024
2 parents 9eb493c + 26dc782 commit f4b3036
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/MessageHandler/ProductToDeleteFromIdsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

namespace MonsieurBiz\SyliusSearchPlugin\MessageHandler;

use Exception;
use MonsieurBiz\SyliusSearchPlugin\Index\IndexerInterface;
use MonsieurBiz\SyliusSearchPlugin\Message\ProductToDeleteFromIds;
use MonsieurBiz\SyliusSearchPlugin\Model\Documentable\DocumentableInterface;
use Psr\Log\LoggerInterface;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

Expand All @@ -25,22 +27,32 @@ class ProductToDeleteFromIdsHandler implements MessageHandlerInterface

private ServiceRegistryInterface $documentableRegistry;

private LoggerInterface $logger;

public function __construct(
IndexerInterface $indexer,
ServiceRegistryInterface $documentableRegistry
ServiceRegistryInterface $documentableRegistry,
LoggerInterface $logger
) {
$this->indexer = $indexer;
$this->documentableRegistry = $documentableRegistry;
$this->logger = $logger;
}

public function __invoke(ProductToDeleteFromIds $message): void
{
/** @var DocumentableInterface $documentable */
$documentable = $this->documentableRegistry->get('search.documentable.monsieurbiz_product');

$this->indexer->deleteByDocumentIds(
$documentable,
$message->getProductIds()
);
try {
$this->indexer->deleteByDocumentIds(
$documentable,
$message->getProductIds()
);
} catch (Exception $e) {
$this->logger->error('An error occurred while deleting products from search index', [
'exception' => $e,
]);
}
}
}

0 comments on commit f4b3036

Please sign in to comment.