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

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