vendor/shopware/core/Framework/MessageQueue/Subscriber/PluginLifecycleSubscriber.php line 38

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\MessageQueue\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.  * @internal
  13.  */
  14. #[Package('system-settings')]
  15. final class PluginLifecycleSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(
  21.         private readonly TaskRegistry $registry,
  22.         private readonly CacheItemPoolInterface $restartSignalCachePool
  23.     ) {
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             PluginPostActivateEvent::class => 'afterPluginStateChange',
  29.             PluginPostDeactivateEvent::class => 'afterPluginStateChange',
  30.             PluginPostUpdateEvent::class => 'afterPluginStateChange',
  31.         ];
  32.     }
  33.     public function afterPluginStateChange(): void
  34.     {
  35.         $this->registry->registerTasks();
  36.         // signal worker restart
  37.         $cacheItem $this->restartSignalCachePool->getItem(StopWorkerOnRestartSignalListener::RESTART_REQUESTED_TIMESTAMP_KEY);
  38.         $cacheItem->set(microtime(true));
  39.         $this->restartSignalCachePool->save($cacheItem);
  40.     }
  41. }