<?php declare(strict_types=1);
namespace Shopware\Core\Checkout\Customer\Subscriber;
use Doctrine\DBAL\Connection;
use Shopware\Core\Checkout\Customer\CustomerEvents;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Shopware\Core\Framework\Uuid\Uuid;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
*/
class CustomerChangePasswordSubscriber implements EventSubscriberInterface
{
private Connection $connection;
/**
* @internal
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
/**
* @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
*/
public static function getSubscribedEvents()
{
return [
CustomerEvents::CUSTOMER_WRITTEN_EVENT => 'onCustomerWritten',
];
}
public function onCustomerWritten(EntityWrittenEvent $event): void
{
$payloads = $event->getPayloads();
foreach ($payloads as $payload) {
if (!empty($payload['password'])) {
$this->clearLegacyPassword($payload['id']);
}
}
}
private function clearLegacyPassword(string $customerId): void
{
$this->connection->executeStatement(
'UPDATE `customer` SET `legacy_password` = null, `legacy_encoder` = null WHERE id = :id',
[
'id' => Uuid::fromHexToBytes($customerId),
]
);
}
}