custom/plugins/ShopStudioBlog/src/ElasticSearch/BlogPost/BlogPostUpdater.php line 49

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace ShopStudio\Blog\ElasticSearch\BlogPost;
  3. use ShopStudio\Blog\Content\BlogPost\Events\BlogPostIndexerEvent;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
  5. use Shopware\Elasticsearch\Framework\Indexing\ElasticsearchIndexer;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. /**
  8.  * @since 2.9.0
  9.  */
  10. class BlogPostUpdater implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @since 2.9.0
  14.      */
  15.     private ElasticsearchIndexer $indexer;
  16.     /**
  17.      * @since 2.9.0
  18.      */
  19.     private EntityDefinition $definition;
  20.     /**
  21.      * @since 2.9.0
  22.      */
  23.     public function __construct(ElasticsearchIndexer $indexerEntityDefinition $definition)
  24.     {
  25.         $this->indexer $indexer;
  26.         $this->definition $definition;
  27.     }
  28.     /**
  29.      * @since 2.9.0
  30.      *
  31.      * @return string[]
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             BlogPostIndexerEvent::class => 'update',
  37.         ];
  38.     }
  39.     /**
  40.      * @since 2.9.0
  41.      */
  42.     public function update(BlogPostIndexerEvent $event): void
  43.     {
  44.         $this->indexer->updateIds(
  45.             $this->definition,
  46.             array_unique($event->getIds())
  47.         );
  48.     }
  49. }