vendor/pimcore/portal-engine/src/EventSubscriber/AssetUpdateSubscriber.php line 54

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\StatisticsTracker\Elasticsearch\AssetUpdateTracker;
  13. use Pimcore\Event\AssetEvents;
  14. use Pimcore\Event\Model\AssetEvent;
  15. use Pimcore\Model\Asset;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. /**
  18.  * Class AssetUpdateSubscriber
  19.  *
  20.  * @package Pimcore\Bundle\PortalEngineBundle\EventSubscriber
  21.  */
  22. class AssetUpdateSubscriber implements EventSubscriberInterface
  23. {
  24.     /** @var AssetUpdateTracker */
  25.     protected $assetUpdateTracker;
  26.     /**
  27.      * AssetUpdateSubscriber constructor.
  28.      *
  29.      * @param AssetUpdateTracker $assetUpdateTracker
  30.      */
  31.     public function __construct(AssetUpdateTracker $assetUpdateTracker)
  32.     {
  33.         $this->assetUpdateTracker $assetUpdateTracker;
  34.     }
  35.     /**
  36.      * @return array
  37.      */
  38.     public static function getSubscribedEvents()
  39.     {
  40.         return [
  41.             AssetEvents::POST_UPDATE => 'updateAsset',
  42.         ];
  43.     }
  44.     /**
  45.      * @param AssetEvent $event
  46.      */
  47.     public function updateAsset(AssetEvent $event)
  48.     {
  49.         $asset $event->getAsset();
  50.         if ($asset instanceof Asset) {
  51.             $this->assetUpdateTracker->trackEvent(['asset' => $asset]);
  52.         }
  53.     }
  54. }