10
10
use Magento \Framework \App \Area ;
11
11
use Magento \Framework \App \State ;
12
12
use Magento \Framework \Console \Cli ;
13
+ use Magento \Framework \Exception \CouldNotSaveException ;
13
14
use Magento \Framework \Exception \LocalizedException ;
15
+ use Magento \Framework \Exception \NoSuchEntityException ;
14
16
use Magento \Framework \Registry ;
17
+ use Opengento \Gdpr \Api \Data \EraseEntityInterface ;
15
18
use Opengento \Gdpr \Api \EraseEntityManagementInterface ;
19
+ use Opengento \Gdpr \Api \EraseEntityRepositoryInterface ;
16
20
use Symfony \Component \Console \Command \Command ;
17
21
use Symfony \Component \Console \Helper \ProgressBar ;
18
22
use Symfony \Component \Console \Input \InputArgument ;
@@ -27,7 +31,8 @@ class EraseCommand extends Command
27
31
public function __construct (
28
32
private State $ appState ,
29
33
private Registry $ registry ,
30
- private EraseEntityManagementInterface $ eraseManagement ,
34
+ private EraseEntityRepositoryInterface $ eraseEntityRepository ,
35
+ private EraseEntityManagementInterface $ eraseEntityManagement ,
31
36
string $ name = 'gdpr:entity:erase '
32
37
) {
33
38
parent ::__construct ($ name );
@@ -72,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
72
77
73
78
try {
74
79
foreach ($ entityIds as $ entityId ) {
75
- $ this ->eraseManagement ->process ($ this ->eraseManagement -> create ( $ entityId , $ entityType ));
80
+ $ this ->eraseEntityManagement ->process ($ this ->fetchEntity ( $ entityType , $ entityId ));
76
81
$ progressBar ->advance ();
77
82
}
78
83
$ progressBar ->finish ();
@@ -86,4 +91,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
86
91
87
92
return $ returnCode ;
88
93
}
94
+
95
+ /**
96
+ * @throws CouldNotSaveException
97
+ * @throws LocalizedException
98
+ */
99
+ private function fetchEntity (int $ entityId , string $ entityType ): EraseEntityInterface
100
+ {
101
+ try {
102
+ return $ this ->eraseEntityRepository ->getByEntity ($ entityId , $ entityType );
103
+ } catch (NoSuchEntityException ) {
104
+ return $ this ->eraseEntityManagement ->create ($ entityId , $ entityType );
105
+ }
106
+ }
89
107
}
0 commit comments