vendor/shopware/core/Checkout/Customer/Subscriber/CustomerChangePasswordSubscriber.php line 38

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Customer\Subscriber;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Checkout\Customer\CustomerEvents;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Shopware\Core\Framework\Uuid\Uuid;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10. * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  11. */
  12. #[Package('customer-order')]
  13. class CustomerChangePasswordSubscriber implements EventSubscriberInterface
  14. {
  15. private Connection $connection;
  16. /**
  17. * @internal
  18. */
  19. public function __construct(Connection $connection)
  20. {
  21. $this->connection = $connection;
  22. }
  23. /**
  24. * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  25. */
  26. public static function getSubscribedEvents()
  27. {
  28. return [
  29. CustomerEvents::CUSTOMER_WRITTEN_EVENT => 'onCustomerWritten',
  30. ];
  31. }
  32. public function onCustomerWritten(EntityWrittenEvent $event): void
  33. {
  34. $payloads = $event->getPayloads();
  35. foreach ($payloads as $payload) {
  36. if (!empty($payload['password'])) {
  37. $this->clearLegacyPassword($payload['id']);
  38. }
  39. }
  40. }
  41. private function clearLegacyPassword(string $customerId): void
  42. {
  43. $this->connection->executeStatement(
  44. 'UPDATE `customer` SET `legacy_password` = null, `legacy_encoder` = null WHERE id = :id',
  45. [
  46. 'id' => Uuid::fromHexToBytes($customerId),
  47. ]
  48. );
  49. }
  50. }