<?php declare(strict_types=1);
namespace Swag\EnterpriseSearch\Category;
use Shopware\Core\Content\Category\Event\CategoryIndexerEvent;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Elasticsearch\Framework\Indexing\ElasticsearchIndexer;
use Swag\EnterpriseSearch\Common\VersionHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CategoryUpdater implements EventSubscriberInterface
{
/**
* @var ElasticsearchIndexer
*/
private $indexer;
/**
* @var EntityDefinition
*/
private $definition;
public function __construct(ElasticsearchIndexer $indexer, EntityDefinition $definition)
{
$this->indexer = $indexer;
$this->definition = $definition;
}
public static function getSubscribedEvents(): array
{
return [
CategoryIndexerEvent::class => 'update',
];
}
public function update(CategoryIndexerEvent $event): void
{
if (VersionHelper::isShopware64X()) {
$this->indexer->updateIds(
$this->definition,
$event->getIds()
);
return;
}
$this->indexer->sendIndexingMessages(
$this->definition,
$event->getIds()
);
}
}