Skip to content

Commit c64cd7b

Browse files
committed
Fix #143 - Ignore customer validation
1 parent 3382ac9 commit c64cd7b

File tree

2 files changed

+26
-65
lines changed

2 files changed

+26
-65
lines changed

Model/Customer/Anonymize/Processor/CustomerAddressDataProcessor.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,18 @@
99

1010
use Magento\Customer\Api\AddressRepositoryInterface;
1111
use Magento\Framework\Api\SearchCriteriaBuilder;
12+
use Magento\Framework\DataObject;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface;
1415
use Opengento\Gdpr\Service\Erase\ProcessorInterface;
1516

1617
class CustomerAddressDataProcessor implements ProcessorInterface
1718
{
18-
private AnonymizerInterface $anonymizer;
19-
20-
/**
21-
* @var AddressRepositoryInterface
22-
*/
23-
private AddressRepositoryInterface $addressRepository;
24-
25-
private SearchCriteriaBuilder $criteriaBuilder;
26-
2719
public function __construct(
28-
AnonymizerInterface $anonymizer,
29-
AddressRepositoryInterface $addressRepository,
30-
SearchCriteriaBuilder $criteriaBuilder
31-
) {
32-
$this->anonymizer = $anonymizer;
33-
$this->addressRepository = $addressRepository;
34-
$this->criteriaBuilder = $criteriaBuilder;
35-
}
20+
private AnonymizerInterface $anonymizer,
21+
private AddressRepositoryInterface $addressRepository,
22+
private SearchCriteriaBuilder $criteriaBuilder
23+
) {}
3624

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

4634
foreach ($addressList->getItems() as $address) {
47-
$this->addressRepository->save($this->anonymizer->anonymize($address));
35+
$address = $this->anonymizer->anonymize($address);
36+
if ($address instanceof DataObject) {
37+
$address->setData('should_ignore_validation', true);
38+
}
39+
$this->addressRepository->save($address);
4840
}
4941

5042
return true;

Model/Customer/Anonymize/Processor/CustomerDataProcessor.php

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Customer\Model\CustomerRegistry;
1515
use Magento\Framework\Api\SearchCriteriaBuilder;
1616
use Magento\Framework\App\Config\ScopeConfigInterface;
17+
use Magento\Framework\DataObject;
1718
use Magento\Framework\Exception\InputException;
1819
use Magento\Framework\Exception\LocalizedException;
1920
use Magento\Framework\Exception\NoSuchEntityException;
@@ -37,53 +38,16 @@ class CustomerDataProcessor implements ProcessorInterface
3738
{
3839
private const CONFIG_PATH_ERASURE_REMOVE_CUSTOMER = 'gdpr/erasure/remove_customer';
3940

40-
private AnonymizerInterface $anonymizer;
41-
42-
/**
43-
* @var CustomerRepositoryInterface
44-
*/
45-
private CustomerRepositoryInterface $customerRepository;
46-
47-
private OrderRepositoryInterface $orderRepository;
48-
49-
private SearchCriteriaBuilder $criteriaBuilder;
50-
51-
/**
52-
* @var CustomerRegistry
53-
*/
54-
private CustomerRegistry $customerRegistry;
55-
56-
/**
57-
* @var OrigDataRegistry
58-
*/
59-
private OrigDataRegistry $origDataRegistry;
60-
61-
/**
62-
* @var SessionCleanerInterface
63-
*/
64-
private SessionCleanerInterface $sessionCleaner;
65-
66-
private ScopeConfigInterface $scopeConfig;
67-
6841
public function __construct(
69-
AnonymizerInterface $anonymizer,
70-
CustomerRepositoryInterface $customerRepository,
71-
OrderRepositoryInterface $orderRepository,
72-
SearchCriteriaBuilder $criteriaBuilder,
73-
CustomerRegistry $customerRegistry,
74-
OrigDataRegistry $origDataRegistry,
75-
SessionCleanerInterface $sessionCleaner,
76-
ScopeConfigInterface $scopeConfig
77-
) {
78-
$this->anonymizer = $anonymizer;
79-
$this->customerRepository = $customerRepository;
80-
$this->orderRepository = $orderRepository;
81-
$this->criteriaBuilder = $criteriaBuilder;
82-
$this->customerRegistry = $customerRegistry;
83-
$this->origDataRegistry = $origDataRegistry;
84-
$this->sessionCleaner = $sessionCleaner;
85-
$this->scopeConfig = $scopeConfig;
86-
}
42+
private AnonymizerInterface $anonymizer,
43+
private CustomerRepositoryInterface $customerRepository,
44+
private OrderRepositoryInterface $orderRepository,
45+
private SearchCriteriaBuilder $criteriaBuilder,
46+
private CustomerRegistry $customerRegistry,
47+
private OrigDataRegistry $origDataRegistry,
48+
private SessionCleanerInterface $sessionCleaner,
49+
private ScopeConfigInterface $scopeConfig
50+
) {}
8751

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

147-
$this->customerRepository->save($this->anonymizer->anonymize($customer));
111+
$customer = $this->anonymizer->anonymize($customer);
112+
if ($customer instanceof DataObject) {
113+
$customer->setData('ignore_validation_flag', true);
114+
}
115+
116+
$this->customerRepository->save($customer);
148117
}
149118

150119
private function shouldRemoveCustomerWithoutOrders(): bool

0 commit comments

Comments
 (0)