custom/plugins/PixelLexikonSW6/src/Entities/Categories/DataAbstractionLayer/LexikonCategoriesIndexer.php line 84

Open in your IDE?
  1. <?php
  2. namespace Pixel\LexikonSW6\Entities\Categories\DataAbstractionLayer;
  3. use Pixel\LexikonSW6\Entities\Categories\Events\LexikonCategoriesIndexerEvent;
  4. use Pixel\LexikonSW6\Entities\Categories\LexikonCategoriesDefinition;
  5. use Shopware\Core\Framework\Adapter\Cache\CacheClearer;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\IteratorFactory;
  7. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexer;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexingMessage;
  11. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  12. class LexikonCategoriesIndexer extends EntityIndexer
  13. {
  14.     /** @var IteratorFactory */
  15.     private $iteratorFactory;
  16.     /** @var CacheClearer */
  17.     private $cacheClearer;
  18.     /** @var EventDispatcherInterface */
  19.     private $eventDispatcher;
  20.     /**
  21.      * @var EntityRepositoryInterface
  22.      */
  23.     private $repository;
  24.     public function __construct(
  25.         IteratorFactory $iteratorFactory,
  26.         EntityRepositoryInterface $repository,
  27.         CacheClearer $cacheClearer,
  28.         EventDispatcherInterface $eventDispatcher
  29.     ) {
  30.         $this->iteratorFactory $iteratorFactory;
  31.         $this->repository $repository;
  32.         $this->cacheClearer $cacheClearer;
  33.         $this->eventDispatcher $eventDispatcher;
  34.     }
  35.     public function getName(): string
  36.     {
  37.         return 'lexikon.listing.indexer';
  38.     }
  39.     public function iterate($offset): ?EntityIndexingMessage
  40.     {
  41.         $iterator $this->iteratorFactory->createIterator($this->repository->getDefinition(), $offset);
  42.         $ids $iterator->fetch();
  43.         // loop end? return null
  44.         if (empty($ids)) {
  45.             return null;
  46.         }
  47.         return new EntityIndexingMessage(array_values($ids), $iterator->getOffset());
  48.     }
  49.     public function update(EntityWrittenContainerEvent $event): ?EntityIndexingMessage
  50.     {
  51.         $updates $event->getPrimaryKeys(LexikonCategoriesDefinition::ENTITY_NAME);
  52.         if (empty($updates)) {
  53.             return null;
  54.         }
  55.         return new EntityIndexingMessage(array_values($updates), null$event->getContext());
  56.     }
  57.     public function handle(EntityIndexingMessage $message): void
  58.     {
  59.         $ids $message->getData();
  60. // 19.12
  61.         $ids array_unique(array_filter($ids));
  62.         if (empty($ids)) {
  63.             return;
  64.         }
  65.         // update all required data
  66.         $this->eventDispatcher->dispatch(new LexikonCategoriesIndexerEvent($ids$message->getContext()));
  67.         //$this->cacheClearer->invalidateIds($ids, LexikonCategoriesDefinition::ENTITY_NAME);
  68.     }
  69. }