Skip to content

Commit

Permalink
Fix customer route compability with AccountInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Aug 24, 2024
1 parent 79040b7 commit 7bb6f02
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 33 deletions.
9 changes: 1 addition & 8 deletions Api/Data/EraseEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ public function setEraseId(int $eraseId): EraseEntityInterface;

public function getEntityId(): int;

/**
* Set the entity ID
*
* @param int $entityId
* @return EraseEntityInterface
* @todo force type in php7.4
*/
public function setEntityId($entityId): EraseEntityInterface;
public function setEntityId(int $entityId): EraseEntityInterface;

public function getEntityType(): string;

Expand Down
9 changes: 1 addition & 8 deletions Api/Data/ExportEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ public function setExportId(int $exportId): ExportEntityInterface;

public function getEntityId(): int;

/**
* Set the entity ID
*
* @param int $entityId
* @return ExportEntityInterface
* @todo force type in php7.4
*/
public function setEntityId($entityId): ExportEntityInterface;
public function setEntityId(int $entityId): ExportEntityInterface;

public function getEntityType(): string;

Expand Down
2 changes: 1 addition & 1 deletion Controller/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
protected Config $config
) {}

public function execute(): ResultInterface|ResponseInterface
public function execute()
{
return $this->isAllowed() ? $this->executeAction() : $this->forwardNoRoute();
}
Expand Down
21 changes: 5 additions & 16 deletions Model/Customer/Anonymize/Processor/CustomerDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Opengento\Gdpr\Model\Customer\Anonymize\Processor;

use DateTime;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Api\SessionCleanerInterface;
Expand All @@ -19,21 +18,14 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\State\InputMismatchException;
use Magento\Framework\Stdlib\DateTime as DateTimeFormat;
use Magento\Framework\Math\Random;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderSearchResultInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Store\Model\ScopeInterface;
use Opengento\Gdpr\Model\Customer\OrigDataRegistry;
use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface;
use Opengento\Gdpr\Service\Erase\ProcessorInterface;
use Random\RandomException;

use function random_int;
use function sha1;
use function uniqid;

use const PHP_INT_MAX;

class CustomerDataProcessor implements ProcessorInterface
{
Expand All @@ -47,12 +39,12 @@ public function __construct(
private CustomerRegistry $customerRegistry,
private OrigDataRegistry $origDataRegistry,
private SessionCleanerInterface $sessionCleaner,
private ScopeConfigInterface $scopeConfig
private ScopeConfigInterface $scopeConfig,
private Random $random
) {}

/**
* @throws LocalizedException
* @throws RandomException
*/
public function execute(int $entityId): bool
{
Expand All @@ -72,7 +64,6 @@ public function execute(int $entityId): bool
* @throws InputMismatchException
* @throws LocalizedException
* @throws NoSuchEntityException
* @throws RandomException
*/
private function processCustomerData(int $customerId): void
{
Expand Down Expand Up @@ -100,16 +91,14 @@ private function fetchOrdersList(CustomerInterface $customer): OrderSearchResult
* @throws NoSuchEntityException
* @throws InputException
* @throws InputMismatchException
* @throws RandomException
*/
private function anonymizeCustomer(CustomerInterface $customer): void
{
$this->customerRegistry->remove($customer->getId());

$secureData = $this->customerRegistry->retrieveSecureData($customer->getId());
$dateTime = (new DateTime())->setTimestamp(PHP_INT_MAX);
$secureData->setData('lock_expires', $dateTime->format(DateTimeFormat::DATETIME_PHP_FORMAT));
$secureData->setPasswordHash(sha1(uniqid((string)random_int(), true)));
$secureData->setData('lock_expires', '9999-12-31 23:59:59');
$secureData->setPasswordHash($this->random->getUniqueHash());

$customer = $this->anonymizer->anonymize($customer);
if ($customer instanceof DataObject) {
Expand Down

0 comments on commit 7bb6f02

Please sign in to comment.