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

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\Uuid\Uuid;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CustomerChangePasswordSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var Connection
  12.      */
  13.     private $connection;
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(Connection $connection)
  18.     {
  19.         $this->connection $connection;
  20.     }
  21.     /**
  22.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  23.      */
  24.     public static function getSubscribedEvents()
  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->executeUpdate(
  42.             'UPDATE `customer` SET `legacy_password` = null, `legacy_encoder` = null WHERE id = :id',
  43.             [
  44.                 'id' => Uuid::fromHexToBytes($customerId),
  45.             ]
  46.         );
  47.     }
  48. }