vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/EventListener/IndexUpdateListener.php line 49

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\EcommerceFrameworkBundle\EventListener;
  15. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  16. use Pimcore\Bundle\EcommerceFrameworkBundle\Model\IndexableInterface;
  17. use Pimcore\Event\DataObjectEvents;
  18. use Pimcore\Event\Model\DataObjectEvent;
  19. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20. class IndexUpdateListener implements EventSubscriberInterface
  21. {
  22.     /**
  23.      * @return array
  24.      */
  25.     #[\ReturnTypeWillChange]
  26.     public static function getSubscribedEvents()//: array
  27.     {
  28.         return [
  29.             DataObjectEvents::POST_ADD => 'onObjectUpdate',
  30.             DataObjectEvents::POST_UPDATE => 'onObjectUpdate',
  31.             DataObjectEvents::PRE_DELETE => 'onObjectDelete',
  32.         ];
  33.     }
  34.     public function onObjectUpdate(DataObjectEvent $event)
  35.     {
  36.         $object $event->getObject();
  37.         if ($object instanceof IndexableInterface && (!$event->hasArgument('saveVersionOnly') || !$event->getArgument('saveVersionOnly'))) {
  38.             $indexService Factory::getInstance()->getIndexService();
  39.             $indexService->updateIndex($object);
  40.         }
  41.     }
  42.     public function onObjectDelete(DataObjectEvent $event)
  43.     {
  44.         $object $event->getObject();
  45.         if ($object instanceof IndexableInterface) {
  46.             $indexService Factory::getInstance()->getIndexService();
  47.             $indexService->deleteFromIndex($object);
  48.         }
  49.         // Delete tokens when a a configuration object gets removed.
  50.         if ($object instanceof \Pimcore\Model\DataObject\OnlineShopVoucherSeries) {
  51.             $voucherService Factory::getInstance()->getVoucherService();
  52.             $voucherService->cleanUpVoucherSeries($object);
  53.         }
  54.     }
  55. }