7
7
8
8
namespace Opengento \Gdpr \Model \Customer \Anonymize \Processor ;
9
9
10
- use DateTime ;
11
10
use Magento \Customer \Api \CustomerRepositoryInterface ;
12
11
use Magento \Customer \Api \Data \CustomerInterface ;
13
12
use Magento \Customer \Api \SessionCleanerInterface ;
19
18
use Magento \Framework \Exception \LocalizedException ;
20
19
use Magento \Framework \Exception \NoSuchEntityException ;
21
20
use Magento \Framework \Exception \State \InputMismatchException ;
22
- use Magento \Framework \Stdlib \ DateTime as DateTimeFormat ;
21
+ use Magento \Framework \Math \ Random ;
23
22
use Magento \Sales \Api \Data \OrderInterface ;
24
23
use Magento \Sales \Api \Data \OrderSearchResultInterface ;
25
24
use Magento \Sales \Api \OrderRepositoryInterface ;
26
25
use Magento \Store \Model \ScopeInterface ;
27
26
use Opengento \Gdpr \Model \Customer \OrigDataRegistry ;
28
27
use Opengento \Gdpr \Service \Anonymize \AnonymizerInterface ;
29
28
use Opengento \Gdpr \Service \Erase \ProcessorInterface ;
30
- use Random \RandomException ;
31
-
32
- use function random_int ;
33
- use function sha1 ;
34
- use function uniqid ;
35
-
36
- use const PHP_INT_MAX ;
37
29
38
30
class CustomerDataProcessor implements ProcessorInterface
39
31
{
@@ -47,12 +39,12 @@ public function __construct(
47
39
private CustomerRegistry $ customerRegistry ,
48
40
private OrigDataRegistry $ origDataRegistry ,
49
41
private SessionCleanerInterface $ sessionCleaner ,
50
- private ScopeConfigInterface $ scopeConfig
42
+ private ScopeConfigInterface $ scopeConfig ,
43
+ private Random $ random
51
44
) {}
52
45
53
46
/**
54
47
* @throws LocalizedException
55
- * @throws RandomException
56
48
*/
57
49
public function execute (int $ entityId ): bool
58
50
{
@@ -72,7 +64,6 @@ public function execute(int $entityId): bool
72
64
* @throws InputMismatchException
73
65
* @throws LocalizedException
74
66
* @throws NoSuchEntityException
75
- * @throws RandomException
76
67
*/
77
68
private function processCustomerData (int $ customerId ): void
78
69
{
@@ -100,16 +91,14 @@ private function fetchOrdersList(CustomerInterface $customer): OrderSearchResult
100
91
* @throws NoSuchEntityException
101
92
* @throws InputException
102
93
* @throws InputMismatchException
103
- * @throws RandomException
104
94
*/
105
95
private function anonymizeCustomer (CustomerInterface $ customer ): void
106
96
{
107
97
$ this ->customerRegistry ->remove ($ customer ->getId ());
108
98
109
99
$ secureData = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
110
- $ dateTime = (new DateTime ())->setTimestamp (PHP_INT_MAX );
111
- $ secureData ->setData ('lock_expires ' , $ dateTime ->format (DateTimeFormat::DATETIME_PHP_FORMAT ));
112
- $ secureData ->setPasswordHash (sha1 (uniqid ((string )random_int (), true )));
100
+ $ secureData ->setData ('lock_expires ' , '9999-12-31 23:59:59 ' );
101
+ $ secureData ->setPasswordHash ($ this ->random ->getUniqueHash ());
113
102
114
103
$ customer = $ this ->anonymizer ->anonymize ($ customer );
115
104
if ($ customer instanceof DataObject) {
0 commit comments