<?php declare(strict_types=1);
namespace ShopStudio\Blog\ElasticSearch\BlogPost;
use ShopStudio\Blog\Content\BlogPost\Events\BlogPostIndexerEvent;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Elasticsearch\Framework\Indexing\ElasticsearchIndexer;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @since 2.9.0
*/
class BlogPostUpdater implements EventSubscriberInterface
{
/**
* @since 2.9.0
*/
private ElasticsearchIndexer $indexer;
/**
* @since 2.9.0
*/
private EntityDefinition $definition;
/**
* @since 2.9.0
*/
public function __construct(ElasticsearchIndexer $indexer, EntityDefinition $definition)
{
$this->indexer = $indexer;
$this->definition = $definition;
}
/**
* @since 2.9.0
*
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
BlogPostIndexerEvent::class => 'update',
];
}
/**
* @since 2.9.0
*/
public function update(BlogPostIndexerEvent $event): void
{
$this->indexer->updateIds(
$this->definition,
array_unique($event->getIds())
);
}
}