vendor/shopware/core/Framework/MessageQueue/ScheduledTask/Subscriber/PluginLifecycleSubscriber.php line 42

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\Log\Package;
  5. use Shopware\Core\Framework\MessageQueue\ScheduledTask\Registry\TaskRegistry;
  6. use Shopware\Core\Framework\Plugin\Event\PluginPostActivateEvent;
  7. use Shopware\Core\Framework\Plugin\Event\PluginPostDeactivateEvent;
  8. use Shopware\Core\Framework\Plugin\Event\PluginPostUpdateEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\Messenger\EventListener\StopWorkerOnRestartSignalListener;
  11. /**
  12.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  13.  */
  14. #[Package('system-settings')]
  15. class PluginLifecycleSubscriber implements EventSubscriberInterface
  16. {
  17.     private TaskRegistry $registry;
  18.     private CacheItemPoolInterface $restartSignalCachePool;
  19.     /**
  20.      * @internal
  21.      */
  22.     public function __construct(TaskRegistry $registryCacheItemPoolInterface $restartSignalCachePool)
  23.     {
  24.         $this->registry $registry;
  25.         $this->restartSignalCachePool $restartSignalCachePool;
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             PluginPostActivateEvent::class => 'afterPluginStateChange',
  31.             PluginPostDeactivateEvent::class => 'afterPluginStateChange',
  32.             PluginPostUpdateEvent::class => 'afterPluginStateChange',
  33.         ];
  34.     }
  35.     public function afterPluginStateChange(): void
  36.     {
  37.         $this->registry->registerTasks();
  38.         // signal worker restart
  39.         $cacheItem $this->restartSignalCachePool->getItem(StopWorkerOnRestartSignalListener::RESTART_REQUESTED_TIMESTAMP_KEY);
  40.         $cacheItem->set(microtime(true));
  41.         $this->restartSignalCachePool->save($cacheItem);
  42.     }
  43. }