Skip to content

Commit 7f06d99

Browse files
committed
Merge branch 'magento2.4.x'
2 parents f0bbc19 + 47f334c commit 7f06d99

File tree

4 files changed

+33
-117
lines changed

4 files changed

+33
-117
lines changed

Model/Customer/Anonymize/Processor/CustomerDataProcessor.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,27 @@
77

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

10+
use DateTime;
1011
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Api\SessionCleanerInterface;
1113
use Magento\Customer\Model\CustomerRegistry;
1214
use Magento\Framework\Api\SearchCriteriaBuilder;
1315
use Magento\Framework\App\Config\ScopeConfigInterface;
1416
use Magento\Framework\Exception\InputException;
1517
use Magento\Framework\Exception\LocalizedException;
1618
use Magento\Framework\Exception\NoSuchEntityException;
1719
use Magento\Framework\Exception\State\InputMismatchException;
20+
use Magento\Framework\Stdlib\DateTime as DateTimeFormat;
1821
use Magento\Sales\Api\Data\OrderInterface;
1922
use Magento\Sales\Api\Data\OrderSearchResultInterface;
2023
use Magento\Sales\Api\OrderRepositoryInterface;
2124
use Magento\Store\Model\ScopeInterface;
2225
use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface;
2326
use Opengento\Gdpr\Service\Erase\ProcessorInterface;
27+
use function mt_rand;
28+
use function sha1;
29+
use function uniqid;
30+
use const PHP_INT_MAX;
2431

2532
final class CustomerDataProcessor implements ProcessorInterface
2633
{
@@ -51,6 +58,11 @@ final class CustomerDataProcessor implements ProcessorInterface
5158
*/
5259
private $customerRegistry;
5360

61+
/**
62+
* @var SessionCleanerInterface
63+
*/
64+
private $sessionCleaner;
65+
5466
/**
5567
* @var ScopeConfigInterface
5668
*/
@@ -62,13 +74,15 @@ public function __construct(
6274
OrderRepositoryInterface $orderRepository,
6375
SearchCriteriaBuilder $criteriaBuilder,
6476
CustomerRegistry $customerRegistry,
77+
SessionCleanerInterface $sessionCleaner,
6578
ScopeConfigInterface $scopeConfig
6679
) {
6780
$this->anonymizer = $anonymizer;
6881
$this->customerRepository = $customerRepository;
6982
$this->orderRepository = $orderRepository;
7083
$this->criteriaBuilder = $criteriaBuilder;
7184
$this->customerRegistry = $customerRegistry;
85+
$this->sessionCleaner = $sessionCleaner;
7286
$this->scopeConfig = $scopeConfig;
7387
}
7488

@@ -91,6 +105,8 @@ public function execute(int $customerId): bool
91105
return false;
92106
}
93107

108+
$this->sessionCleaner->clearFor($customerId);
109+
94110
return true;
95111
}
96112

@@ -111,6 +127,12 @@ private function fetchOrdersList(int $customerId): OrderSearchResultInterface
111127
private function anonymizeCustomer(int $customerId): void
112128
{
113129
$this->customerRegistry->remove($customerId);
130+
131+
$secureData = $this->customerRegistry->retrieveSecureData($customerId);
132+
$dateTime = (new DateTime())->setTimestamp(PHP_INT_MAX);
133+
$secureData->setData('lock_expires', $dateTime->format(DateTimeFormat::DATETIME_PHP_FORMAT));
134+
$secureData->setPasswordHash(sha1(uniqid(mt_rand(), true)));
135+
114136
$this->customerRepository->save(
115137
$this->anonymizer->anonymize($this->customerRepository->getById($customerId))
116138
);

Model/Customer/Delete/Processor/CustomerDataProcessor.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Opengento\Gdpr\Model\Customer\Delete\Processor;
99

1010
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Customer\Api\SessionCleanerInterface;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Exception\NoSuchEntityException;
1314
use Opengento\Gdpr\Service\Erase\ProcessorInterface;
@@ -19,10 +20,17 @@ final class CustomerDataProcessor implements ProcessorInterface
1920
*/
2021
private $customerRepository;
2122

23+
/**
24+
* @var SessionCleanerInterface
25+
*/
26+
private $sessionCleaner;
27+
2228
public function __construct(
23-
CustomerRepositoryInterface $customerRepository
29+
CustomerRepositoryInterface $customerRepository,
30+
SessionCleanerInterface $sessionCleaner
2431
) {
2532
$this->customerRepository = $customerRepository;
33+
$this->sessionCleaner = $sessionCleaner;
2634
}
2735

2836
/**
@@ -31,6 +39,8 @@ public function __construct(
3139
*/
3240
public function execute(int $customerId): bool
3341
{
42+
$this->sessionCleaner->clearFor($customerId);
43+
3444
try {
3545
$this->customerRepository->deleteById($customerId);
3646
} catch (NoSuchEntityException $e) {

Plugin/SessionChecker.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

etc/frontend/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,4 @@
7878
<argument name="action" xsi:type="object">Opengento\Gdpr\Model\Action\ExportCreateAction</argument>
7979
</arguments>
8080
</type>
81-
<type name="Magento\Framework\App\ActionInterface">
82-
<plugin name="opengento_gdpr_customer_session_checker" type="Opengento\Gdpr\Plugin\SessionChecker" sortOrder="10"/>
83-
</type>
8481
</config>

0 commit comments

Comments
 (0)