vendor/pimcore/portal-engine/src/EventSubscriber/DeleteElementSubscriber.php line 56

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\EventSubscriber;
  12. use Pimcore\Bundle\PortalEngineBundle\Service\Collection\CollectionService;
  13. use Pimcore\Event\AssetEvents;
  14. use Pimcore\Event\DataObjectEvents;
  15. use Pimcore\Event\Model\AssetEvent;
  16. use Pimcore\Event\Model\DataObjectEvent;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. /**
  19.  * @package Pimcore\Bundle\PortalEngineBundle\EventListener
  20.  */
  21. class DeleteElementSubscriber implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @var CollectionService
  25.      */
  26.     protected $collectionService;
  27.     /**
  28.      * @param CollectionService $collectionService
  29.      */
  30.     public function __construct(CollectionService $collectionService)
  31.     {
  32.         $this->collectionService $collectionService;
  33.     }
  34.     /**
  35.      * @return array
  36.      */
  37.     public static function getSubscribedEvents()
  38.     {
  39.         return [
  40.             DataObjectEvents::POST_DELETE => 'onDataObjectPostDelete',
  41.             AssetEvents::POST_DELETE => 'onAssetPostDelete',
  42.         ];
  43.     }
  44.     /**
  45.      * @param DataObjectEvent $dataObjectEvent
  46.      *
  47.      * @throws \Exception
  48.      */
  49.     public function onDataObjectPostDelete(DataObjectEvent $dataObjectEvent)
  50.     {
  51.         $object $dataObjectEvent->getElement();
  52.         $this->collectionService->cleanupDeletedElement($object);
  53.     }
  54.     /**
  55.      * @param AssetEvent $assetEvent
  56.      *
  57.      * @return void
  58.      *
  59.      * @throws \Doctrine\DBAL\DBALException
  60.      */
  61.     public function onAssetPostDelete(AssetEvent $assetEvent)
  62.     {
  63.         $asset $assetEvent->getElement();
  64.         $this->collectionService->cleanupDeletedElement($asset);
  65.     }
  66. }