pimcore/lib/Pimcore/Targeting/EventListener/MaintenanceListener.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Enterprise License (PEL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  14.  */
  15. namespace Pimcore\Targeting\EventListener;
  16. use Pimcore\Event\System\MaintenanceEvent;
  17. use Pimcore\Event\SystemEvents;
  18. use Pimcore\Model\Schedule\Maintenance\Job;
  19. use Pimcore\Targeting\Storage\MaintenanceStorageInterface;
  20. use Pimcore\Targeting\Storage\TargetingStorageInterface;
  21. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  22. class MaintenanceListener implements EventSubscriberInterface
  23. {
  24.     /**
  25.      * @var TargetingStorageInterface|MaintenanceStorageInterface
  26.      */
  27.     private $targetingStorage;
  28.     public function __construct(TargetingStorageInterface $targetingStorage)
  29.     {
  30.         $this->targetingStorage $targetingStorage;
  31.     }
  32.     public static function getSubscribedEvents()
  33.     {
  34.         return [
  35.             SystemEvents::MAINTENANCE => 'onPimcoreMaintenance'
  36.         ];
  37.     }
  38.     public function onPimcoreMaintenance(MaintenanceEvent $event)
  39.     {
  40.         if (!$this->targetingStorage instanceof MaintenanceStorageInterface) {
  41.             return;
  42.         }
  43.         $event->getManager()->registerJob(Job::fromClosure('targetingMaintenance', function () {
  44.             $this->targetingStorage->maintenance();
  45.         }));
  46.     }
  47. }