src/Core/Checkout/Customer/Subscriber/CustomerChangePasswordSubscriber.php line 35

  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.  * @internal
  11.  */
  12. #[Package('customer-order')]
  13. class CustomerChangePasswordSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @internal
  17.      */
  18.     public function __construct(private readonly Connection $connection)
  19.     {
  20.     }
  21.     /**
  22.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  23.      */
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             CustomerEvents::CUSTOMER_WRITTEN_EVENT => 'onCustomerWritten',
  28.         ];
  29.     }
  30.     public function onCustomerWritten(EntityWrittenEvent $event): void
  31.     {
  32.         $payloads $event->getPayloads();
  33.         foreach ($payloads as $payload) {
  34.             if (!empty($payload['password'])) {
  35.                 $this->clearLegacyPassword($payload['id']);
  36.             }
  37.         }
  38.     }
  39.     private function clearLegacyPassword(string $customerId): void
  40.     {
  41.         $this->connection->executeStatement(
  42.             'UPDATE `customer` SET `legacy_password` = null, `legacy_encoder` = null WHERE id = :id',
  43.             [
  44.                 'id' => Uuid::fromHexToBytes($customerId),
  45.             ]
  46.         );
  47.     }
  48. }