src/Core/Framework/MessageQueue/Subscriber/PluginLifecycleSubscriber.php line 36

  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(private readonly TaskRegistry $registry, private readonly CacheItemPoolInterface $restartSignalCachePool)
  21.     {
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             PluginPostActivateEvent::class => 'afterPluginStateChange',
  27.             PluginPostDeactivateEvent::class => 'afterPluginStateChange',
  28.             PluginPostUpdateEvent::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. }