Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Both IndexEntity & RemoveEntity messages are handled #67

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Message/Handler/AbstractEntityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;

abstract class AbstractEntityHandler

Check failure on line 16 in src/Message/Handler/AbstractEntityHandler.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

Method Setono\SyliusMeilisearchPlugin\Message\Handler\AbstractEntityHandler#__invoke() was removed

Check failure on line 16 in src/Message/Handler/AbstractEntityHandler.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

Method Setono\SyliusMeilisearchPlugin\Message\Handler\AbstractEntityHandler#execute() was removed
{
use ORMTrait;

Expand All @@ -22,17 +22,18 @@
$this->managerRegistry = $managerRegistry;
}

public function __invoke(RemoveEntity|IndexEntity $message): void
/**
* @param callable(IndexableInterface $entity, Index $index):void $action
*/
protected function handle(RemoveEntity|IndexEntity $message, callable $action): void

Check warning on line 28 in src/Message/Handler/AbstractEntityHandler.php

View check run for this annotation

Codecov / codecov/patch

src/Message/Handler/AbstractEntityHandler.php#L28

Added line #L28 was not covered by tests
{
$entity = $this->getManager($message->class)->find($message->class, $message->id);
if (null === $entity) {
throw new UnrecoverableMessageHandlingException(sprintf('Entity (%s) with id %s not found', $message->class, (string) $message->id));
}

foreach ($this->indexRegistry->getByEntity($message->class) as $index) {
$this->execute($entity, $index);
$action($entity, $index);

Check warning on line 36 in src/Message/Handler/AbstractEntityHandler.php

View check run for this annotation

Codecov / codecov/patch

src/Message/Handler/AbstractEntityHandler.php#L36

Added line #L36 was not covered by tests
}
}

abstract protected function execute(IndexableInterface $entity, Index $index): void;
}
5 changes: 3 additions & 2 deletions src/Message/Handler/IndexEntityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace Setono\SyliusMeilisearchPlugin\Message\Handler;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\Message\Command\IndexEntity;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;

final class IndexEntityHandler extends AbstractEntityHandler

Check failure on line 11 in src/Message/Handler/IndexEntityHandler.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

Method Setono\SyliusMeilisearchPlugin\Message\Handler\IndexEntityHandler#execute() was removed
{
protected function execute(IndexableInterface $entity, Index $index): void
public function __invoke(IndexEntity $message): void

Check failure on line 13 in src/Message/Handler/IndexEntityHandler.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

The parameter $message of Setono\SyliusMeilisearchPlugin\Message\Handler\AbstractEntityHandler#__invoke() changed from Setono\SyliusMeilisearchPlugin\Message\Command\RemoveEntity|Setono\SyliusMeilisearchPlugin\Message\Command\IndexEntity to a non-contravariant Setono\SyliusMeilisearchPlugin\Message\Command\IndexEntity

Check warning on line 13 in src/Message/Handler/IndexEntityHandler.php

View check run for this annotation

Codecov / codecov/patch

src/Message/Handler/IndexEntityHandler.php#L13

Added line #L13 was not covered by tests
{
$index->indexer()->indexEntity($entity);
$this->handle($message, static fn (IndexableInterface $entity, Index $index) => $index->indexer()->indexEntity($entity));

Check warning on line 15 in src/Message/Handler/IndexEntityHandler.php

View check run for this annotation

Codecov / codecov/patch

src/Message/Handler/IndexEntityHandler.php#L15

Added line #L15 was not covered by tests
}
}
5 changes: 3 additions & 2 deletions src/Message/Handler/RemoveEntityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace Setono\SyliusMeilisearchPlugin\Message\Handler;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\Message\Command\RemoveEntity;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;

final class RemoveEntityHandler extends AbstractEntityHandler

Check failure on line 11 in src/Message/Handler/RemoveEntityHandler.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

Method Setono\SyliusMeilisearchPlugin\Message\Handler\RemoveEntityHandler#execute() was removed
{
protected function execute(IndexableInterface $entity, Index $index): void
public function __invoke(RemoveEntity $message): void

Check failure on line 13 in src/Message/Handler/RemoveEntityHandler.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

The parameter $message of Setono\SyliusMeilisearchPlugin\Message\Handler\AbstractEntityHandler#__invoke() changed from Setono\SyliusMeilisearchPlugin\Message\Command\RemoveEntity|Setono\SyliusMeilisearchPlugin\Message\Command\IndexEntity to a non-contravariant Setono\SyliusMeilisearchPlugin\Message\Command\RemoveEntity

Check warning on line 13 in src/Message/Handler/RemoveEntityHandler.php

View check run for this annotation

Codecov / codecov/patch

src/Message/Handler/RemoveEntityHandler.php#L13

Added line #L13 was not covered by tests
{
$index->indexer()->removeEntity($entity);
$this->handle($message, static fn (IndexableInterface $entity, Index $index) => $index->indexer()->removeEntity($entity));

Check warning on line 15 in src/Message/Handler/RemoveEntityHandler.php

View check run for this annotation

Codecov / codecov/patch

src/Message/Handler/RemoveEntityHandler.php#L15

Added line #L15 was not covered by tests
}
}
Loading