7
7
8
8
namespace Opengento \Gdpr \Model \Customer \Anonymize \Processor ;
9
9
10
+ use DateTime ;
10
11
use Magento \Customer \Api \CustomerRepositoryInterface ;
12
+ use Magento \Customer \Api \SessionCleanerInterface ;
11
13
use Magento \Customer \Model \CustomerRegistry ;
12
14
use Magento \Framework \Api \SearchCriteriaBuilder ;
13
15
use Magento \Framework \App \Config \ScopeConfigInterface ;
14
16
use Magento \Framework \Exception \InputException ;
15
17
use Magento \Framework \Exception \LocalizedException ;
16
18
use Magento \Framework \Exception \NoSuchEntityException ;
17
19
use Magento \Framework \Exception \State \InputMismatchException ;
20
+ use Magento \Framework \Stdlib \DateTime as DateTimeFormat ;
18
21
use Magento \Sales \Api \Data \OrderInterface ;
19
22
use Magento \Sales \Api \Data \OrderSearchResultInterface ;
20
23
use Magento \Sales \Api \OrderRepositoryInterface ;
21
24
use Magento \Store \Model \ScopeInterface ;
22
25
use Opengento \Gdpr \Service \Anonymize \AnonymizerInterface ;
23
26
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 ;
24
31
25
32
final class CustomerDataProcessor implements ProcessorInterface
26
33
{
@@ -51,6 +58,11 @@ final class CustomerDataProcessor implements ProcessorInterface
51
58
*/
52
59
private $ customerRegistry ;
53
60
61
+ /**
62
+ * @var SessionCleanerInterface
63
+ */
64
+ private $ sessionCleaner ;
65
+
54
66
/**
55
67
* @var ScopeConfigInterface
56
68
*/
@@ -62,13 +74,15 @@ public function __construct(
62
74
OrderRepositoryInterface $ orderRepository ,
63
75
SearchCriteriaBuilder $ criteriaBuilder ,
64
76
CustomerRegistry $ customerRegistry ,
77
+ SessionCleanerInterface $ sessionCleaner ,
65
78
ScopeConfigInterface $ scopeConfig
66
79
) {
67
80
$ this ->anonymizer = $ anonymizer ;
68
81
$ this ->customerRepository = $ customerRepository ;
69
82
$ this ->orderRepository = $ orderRepository ;
70
83
$ this ->criteriaBuilder = $ criteriaBuilder ;
71
84
$ this ->customerRegistry = $ customerRegistry ;
85
+ $ this ->sessionCleaner = $ sessionCleaner ;
72
86
$ this ->scopeConfig = $ scopeConfig ;
73
87
}
74
88
@@ -91,6 +105,8 @@ public function execute(int $customerId): bool
91
105
return false ;
92
106
}
93
107
108
+ $ this ->sessionCleaner ->clearFor ($ customerId );
109
+
94
110
return true ;
95
111
}
96
112
@@ -111,6 +127,12 @@ private function fetchOrdersList(int $customerId): OrderSearchResultInterface
111
127
private function anonymizeCustomer (int $ customerId ): void
112
128
{
113
129
$ 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
+
114
136
$ this ->customerRepository ->save (
115
137
$ this ->anonymizer ->anonymize ($ this ->customerRepository ->getById ($ customerId ))
116
138
);
0 commit comments