platform/src/Core/Framework/MessageQueue/ScheduledTask/Subscriber/PluginLifecycleSubscriber.php line 38

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\MessageQueue\ScheduledTask\Subscriber;
  3. use Psr\Cache\CacheItemPoolInterface;
  4. use Shopware\Core\Framework\MessageQueue\ScheduledTask\Registry\TaskRegistry;
  5. use Shopware\Core\Framework\Plugin\Event\PluginPostActivateEvent;
  6. use Shopware\Core\Framework\Plugin\Event\PluginPostDeactivateEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Messenger\EventListener\StopWorkerOnRestartSignalListener;
  9. class PluginLifecycleSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var TaskRegistry
  13.      */
  14.     private $registry;
  15.     /**
  16.      * @var CacheItemPoolInterface
  17.      */
  18.     private $restartSignalCachePool;
  19.     public function __construct(TaskRegistry $registryCacheItemPoolInterface $restartSignalCachePool)
  20.     {
  21.         $this->registry $registry;
  22.         $this->restartSignalCachePool $restartSignalCachePool;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             PluginPostActivateEvent::class => 'afterPluginStateChange',
  28.             PluginPostDeactivateEvent::class => 'afterPluginStateChange',
  29.         ];
  30.     }
  31.     public function afterPluginStateChange(): void
  32.     {
  33.         $this->registry->registerTasks();
  34.         // signal worker restart
  35.         $cacheItem $this->restartSignalCachePool->getItem(StopWorkerOnRestartSignalListener::RESTART_REQUESTED_TIMESTAMP_KEY);
  36.         $cacheItem->set(microtime(true));
  37.         $this->restartSignalCachePool->save($cacheItem);
  38.     }
  39. }