Skip to content

Commit

Permalink
Fix #143 - Ignore customer validation
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Jun 27, 2024
1 parent 3382ac9 commit c64cd7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 65 deletions.
28 changes: 10 additions & 18 deletions Model/Customer/Anonymize/Processor/CustomerAddressDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,18 @@

use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface;
use Opengento\Gdpr\Service\Erase\ProcessorInterface;

class CustomerAddressDataProcessor implements ProcessorInterface
{
private AnonymizerInterface $anonymizer;

/**
* @var AddressRepositoryInterface
*/
private AddressRepositoryInterface $addressRepository;

private SearchCriteriaBuilder $criteriaBuilder;

public function __construct(
AnonymizerInterface $anonymizer,
AddressRepositoryInterface $addressRepository,
SearchCriteriaBuilder $criteriaBuilder
) {
$this->anonymizer = $anonymizer;
$this->addressRepository = $addressRepository;
$this->criteriaBuilder = $criteriaBuilder;
}
private AnonymizerInterface $anonymizer,
private AddressRepositoryInterface $addressRepository,
private SearchCriteriaBuilder $criteriaBuilder
) {}

/**
* @inheritdoc
Expand All @@ -44,7 +32,11 @@ public function execute(int $customerId): bool
$addressList = $this->addressRepository->getList($this->criteriaBuilder->create());

foreach ($addressList->getItems() as $address) {
$this->addressRepository->save($this->anonymizer->anonymize($address));
$address = $this->anonymizer->anonymize($address);
if ($address instanceof DataObject) {
$address->setData('should_ignore_validation', true);
}
$this->addressRepository->save($address);
}

return true;
Expand Down
63 changes: 16 additions & 47 deletions Model/Customer/Anonymize/Processor/CustomerDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Customer\Model\CustomerRegistry;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
Expand All @@ -37,53 +38,16 @@ class CustomerDataProcessor implements ProcessorInterface
{
private const CONFIG_PATH_ERASURE_REMOVE_CUSTOMER = 'gdpr/erasure/remove_customer';

private AnonymizerInterface $anonymizer;

/**
* @var CustomerRepositoryInterface
*/
private CustomerRepositoryInterface $customerRepository;

private OrderRepositoryInterface $orderRepository;

private SearchCriteriaBuilder $criteriaBuilder;

/**
* @var CustomerRegistry
*/
private CustomerRegistry $customerRegistry;

/**
* @var OrigDataRegistry
*/
private OrigDataRegistry $origDataRegistry;

/**
* @var SessionCleanerInterface
*/
private SessionCleanerInterface $sessionCleaner;

private ScopeConfigInterface $scopeConfig;

public function __construct(
AnonymizerInterface $anonymizer,
CustomerRepositoryInterface $customerRepository,
OrderRepositoryInterface $orderRepository,
SearchCriteriaBuilder $criteriaBuilder,
CustomerRegistry $customerRegistry,
OrigDataRegistry $origDataRegistry,
SessionCleanerInterface $sessionCleaner,
ScopeConfigInterface $scopeConfig
) {
$this->anonymizer = $anonymizer;
$this->customerRepository = $customerRepository;
$this->orderRepository = $orderRepository;
$this->criteriaBuilder = $criteriaBuilder;
$this->customerRegistry = $customerRegistry;
$this->origDataRegistry = $origDataRegistry;
$this->sessionCleaner = $sessionCleaner;
$this->scopeConfig = $scopeConfig;
}
private AnonymizerInterface $anonymizer,
private CustomerRepositoryInterface $customerRepository,
private OrderRepositoryInterface $orderRepository,
private SearchCriteriaBuilder $criteriaBuilder,
private CustomerRegistry $customerRegistry,
private OrigDataRegistry $origDataRegistry,
private SessionCleanerInterface $sessionCleaner,
private ScopeConfigInterface $scopeConfig
) {}

/**
* @inheritdoc
Expand Down Expand Up @@ -144,7 +108,12 @@ private function anonymizeCustomer(CustomerInterface $customer): void
$secureData->setData('lock_expires', $dateTime->format(DateTimeFormat::DATETIME_PHP_FORMAT));
$secureData->setPasswordHash(sha1(uniqid((string) mt_rand(), true)));

$this->customerRepository->save($this->anonymizer->anonymize($customer));
$customer = $this->anonymizer->anonymize($customer);
if ($customer instanceof DataObject) {
$customer->setData('ignore_validation_flag', true);
}

$this->customerRepository->save($customer);
}

private function shouldRemoveCustomerWithoutOrders(): bool
Expand Down

0 comments on commit c64cd7b

Please sign in to comment.