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

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