vendor/shopware/core/Framework/Store/Subscriber/LicenseHostChangedSubscriber.php line 31

  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(
  16.         private readonly SystemConfigService $systemConfigService,
  17.         private readonly Connection $connection
  18.     ) {
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             SystemConfigChangedEvent::class => 'onLicenseHostChanged',
  24.         ];
  25.     }
  26.     public function onLicenseHostChanged(SystemConfigChangedEvent $event): void
  27.     {
  28.         if ($event->getKey() !== StoreRequestOptionsProvider::CONFIG_KEY_STORE_LICENSE_DOMAIN) {
  29.             return;
  30.         }
  31.         // The shop secret is unique for each license host and thus cannot remain the same
  32.         $this->systemConfigService->delete(StoreRequestOptionsProvider::CONFIG_KEY_STORE_SHOP_SECRET);
  33.         // Log out all users to enforce re-authentication
  34.         $this->connection->executeStatement('UPDATE user SET store_token = NULL');
  35.     }
  36. }