platform/src/Core/Checkout/Customer/Subscriber/CustomerChangePasswordSubscriber.php line 30

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