src/Core/Framework/Store/Subscriber/LicenseHostChangedSubscriber.php line 29

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Store\Subscriber;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Shopware\Core\Framework\Store\Authentication\StoreRequestOptionsProvider;
  6. use Shopware\Core\System\SystemConfig\Event\SystemConfigChangedEvent;
  7. use Shopware\Core\System\SystemConfig\SystemConfigService;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10.  * @internal
  11.  */
  12. #[Package('merchant-services')]
  13. class LicenseHostChangedSubscriber implements EventSubscriberInterface
  14. {
  15.     public function __construct(private readonly SystemConfigService $systemConfigService, private readonly Connection $connection)
  16.     {
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             SystemConfigChangedEvent::class => 'onLicenseHostChanged',
  22.         ];
  23.     }
  24.     public function onLicenseHostChanged(SystemConfigChangedEvent $event): void
  25.     {
  26.         if ($event->getKey() !== StoreRequestOptionsProvider::CONFIG_KEY_STORE_LICENSE_DOMAIN) {
  27.             return;
  28.         }
  29.         // The shop secret is unique for each license host and thus cannot remain the same
  30.         $this->systemConfigService->delete(StoreRequestOptionsProvider::CONFIG_KEY_STORE_SHOP_SECRET);
  31.         // Log out all users to enforce re-authentication
  32.         $this->connection->executeStatement('UPDATE user SET store_token = NULL');
  33.     }
  34. }