Skip to content

Commit 3597dc2

Browse files
committed
Fix multiple errors + remove unused types + fix admin actions
1 parent 285e688 commit 3597dc2

File tree

9 files changed

+132
-101
lines changed

9 files changed

+132
-101
lines changed

Block/Adminhtml/Config/Form/Field/AttributesAnonymizers.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getAnonymizersSelectRenderer(): Select
3333
);
3434
}
3535

36-
return $this->getData('anonymizers_select_renderer');
36+
return $this->_getData('anonymizers_select_renderer');
3737
}
3838

3939
/**
@@ -53,6 +53,7 @@ protected function _prepareToRender(): void
5353
'anonymizer',
5454
[
5555
'label' => new Phrase('Anonymizer'),
56+
'class' => 'required-entry',
5657
'renderer' => $this->getAnonymizersSelectRenderer(),
5758
]
5859
);

Controller/Adminhtml/Guest/Erase.php

+26-15
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,42 @@
88
namespace Opengento\Gdpr\Controller\Adminhtml\Guest;
99

1010
use Exception;
11-
use Magento\Backend\Model\View\Result\RedirectFactory;
12-
use Magento\Framework\App\Action\HttpPostActionInterface;
13-
use Magento\Framework\App\RequestInterface;
11+
use Magento\Backend\App\Action;
12+
use Magento\Backend\App\Action\Context;
1413
use Magento\Framework\App\ResponseInterface;
1514
use Magento\Framework\Controller\ResultInterface;
15+
use Magento\Framework\Exception\CouldNotSaveException;
1616
use Magento\Framework\Exception\LocalizedException;
1717
use Magento\Framework\Exception\NoSuchEntityException;
18-
use Magento\Framework\Message\ManagerInterface;
1918
use Magento\Framework\Phrase;
2019
use Magento\Sales\Api\OrderRepositoryInterface;
2120
use Magento\Store\Model\StoreManagerInterface;
21+
use Opengento\Gdpr\Api\Data\EraseEntityInterface;
2222
use Opengento\Gdpr\Api\EraseEntityManagementInterface;
2323
use Opengento\Gdpr\Api\EraseEntityRepositoryInterface;
2424
use Opengento\Gdpr\Model\Config;
2525

26-
class Erase implements HttpPostActionInterface
26+
class Erase extends Action
2727
{
2828
public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_erase';
2929

3030
public function __construct(
31-
private RequestInterface $request,
32-
private ManagerInterface $messageManager,
31+
Context $context,
3332
private StoreManagerInterface $storeManager,
3433
private OrderRepositoryInterface $orderRepository,
3534
private EraseEntityManagementInterface $eraseEntityManagement,
3635
private EraseEntityRepositoryInterface $eraseEntityRepository,
37-
private Config $config,
38-
private RedirectFactory $redirectFactory,
39-
) {}
36+
private Config $config
37+
) {
38+
parent::__construct($context);
39+
}
4040

4141
public function execute(): ResultInterface|ResponseInterface
4242
{
4343
try {
44-
$orderId = (int)$this->request->getParam('id');
44+
$orderId = (int)$this->getRequest()->getParam('id');
4545
if ($this->isOrderErasureEnabled($orderId)) {
46-
$this->eraseEntityManagement->process(
47-
$this->eraseEntityRepository->getByEntity($orderId, 'order')
48-
);
46+
$this->eraseEntityManagement->process($this->fetchEntity($orderId));
4947
$this->messageManager->addSuccessMessage(new Phrase('You erased the order.'));
5048
}
5149
} catch (LocalizedException $e) {
@@ -54,7 +52,7 @@ public function execute(): ResultInterface|ResponseInterface
5452
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
5553
}
5654

57-
return $this->redirectFactory->create()->setPath('sales/order/index');
55+
return $this->resultRedirectFactory->create()->setPath('sales/order/index');
5856
}
5957

6058
/**
@@ -66,4 +64,17 @@ private function isOrderErasureEnabled(int $orderId): bool
6664
$this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId()
6765
);
6866
}
67+
68+
/**
69+
* @throws CouldNotSaveException
70+
* @throws LocalizedException
71+
*/
72+
private function fetchEntity(int $orderId): EraseEntityInterface
73+
{
74+
try {
75+
return $this->eraseEntityRepository->getByEntity($orderId, 'order');
76+
} catch (NoSuchEntityException) {
77+
return $this->eraseEntityManagement->create($orderId, 'order');
78+
}
79+
}
6980
}

Controller/Adminhtml/Guest/Export.php

+27-14
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,46 @@
88
namespace Opengento\Gdpr\Controller\Adminhtml\Guest;
99

1010
use Exception;
11-
use Magento\Backend\Model\View\Result\RedirectFactory;
12-
use Magento\Framework\App\Action\HttpGetActionInterface;
11+
use Magento\Backend\App\Action;
12+
use Magento\Backend\App\Action\Context;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
14-
use Magento\Framework\App\RequestInterface;
1514
use Magento\Framework\App\Response\Http\FileFactory;
1615
use Magento\Framework\App\ResponseInterface;
1716
use Magento\Framework\Controller\ResultInterface;
17+
use Magento\Framework\Exception\AlreadyExistsException;
18+
use Magento\Framework\Exception\CouldNotSaveException;
1819
use Magento\Framework\Exception\LocalizedException;
1920
use Magento\Framework\Exception\NoSuchEntityException;
20-
use Magento\Framework\Message\ManagerInterface;
2121
use Magento\Framework\Phrase;
2222
use Magento\Sales\Api\OrderRepositoryInterface;
2323
use Magento\Store\Model\StoreManagerInterface;
24+
use Opengento\Gdpr\Api\Data\ExportEntityInterface;
2425
use Opengento\Gdpr\Api\ExportEntityManagementInterface;
2526
use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
2627
use Opengento\Gdpr\Model\Config;
2728

28-
class Export implements HttpGetActionInterface
29+
class Export extends Action
2930
{
3031
public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_export';
3132

3233
public function __construct(
33-
private RequestInterface $request,
34-
private ManagerInterface $messageManager,
34+
Context $context,
3535
private StoreManagerInterface $storeManager,
3636
private OrderRepositoryInterface $orderRepository,
3737
private ExportEntityManagementInterface $exportEntityManagement,
3838
private ExportEntityRepositoryInterface $exportEntityRepository,
3939
private Config $config,
40-
private RedirectFactory $redirectFactory,
4140
private FileFactory $fileFactory
42-
) {}
41+
) {
42+
parent::__construct($context);
43+
}
4344

4445
public function execute(): ResultInterface|ResponseInterface
4546
{
4647
try {
47-
$orderId = (int)$this->request->getParam('id');
48+
$orderId = (int)$this->getRequest()->getParam('id');
4849
if ($this->isOrderExportEnabled($orderId)) {
49-
$exportEntity = $this->exportEntityManagement->export(
50-
$this->exportEntityRepository->getByEntity($orderId, 'order')
51-
);
50+
$exportEntity = $this->exportEntityManagement->export($this->fetchEntity($orderId));
5251

5352
return $this->fileFactory->create(
5453
'guest_privacy_data_' . $exportEntity->getEntityId() . '.zip',
@@ -65,7 +64,7 @@ public function execute(): ResultInterface|ResponseInterface
6564
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
6665
}
6766

68-
return $this->redirectFactory->create()->setRefererOrBaseUrl();
67+
return $this->resultRedirectFactory->create()->setRefererOrBaseUrl();
6968
}
7069

7170
/**
@@ -77,4 +76,18 @@ private function isOrderExportEnabled(int $orderId): bool
7776
$this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId()
7877
);
7978
}
79+
80+
/**
81+
* @throws AlreadyExistsException
82+
* @throws CouldNotSaveException
83+
* @throws LocalizedException
84+
*/
85+
private function fetchEntity(int $orderId): ExportEntityInterface
86+
{
87+
try {
88+
return $this->exportEntityRepository->getByEntity($orderId, 'order');
89+
} catch (NoSuchEntityException) {
90+
return $this->exportEntityManagement->create($orderId, 'order');
91+
}
92+
}
8093
}

Controller/Adminhtml/Privacy/Erase.php

+26-14
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,40 @@
88
namespace Opengento\Gdpr\Controller\Adminhtml\Privacy;
99

1010
use Exception;
11-
use Magento\Backend\Model\View\Result\RedirectFactory;
11+
use Magento\Backend\App\Action;
12+
use Magento\Backend\App\Action\Context;
1213
use Magento\Customer\Api\CustomerRepositoryInterface;
13-
use Magento\Framework\App\Action\HttpPostActionInterface;
14-
use Magento\Framework\App\RequestInterface;
1514
use Magento\Framework\App\ResponseInterface;
1615
use Magento\Framework\Controller\ResultInterface;
16+
use Magento\Framework\Exception\CouldNotSaveException;
1717
use Magento\Framework\Exception\LocalizedException;
18-
use Magento\Framework\Message\ManagerInterface;
18+
use Magento\Framework\Exception\NoSuchEntityException;
1919
use Magento\Framework\Phrase;
20+
use Opengento\Gdpr\Api\Data\EraseEntityInterface;
2021
use Opengento\Gdpr\Api\EraseEntityManagementInterface;
2122
use Opengento\Gdpr\Api\EraseEntityRepositoryInterface;
2223
use Opengento\Gdpr\Model\Config;
2324

24-
class Erase implements HttpPostActionInterface
25+
class Erase extends Action
2526
{
2627
public const ADMIN_RESOURCE = 'Opengento_Gdpr::customer_erase';
2728

2829
public function __construct(
29-
private RequestInterface $request,
30-
private ManagerInterface $messageManager,
30+
Context $context,
3131
private CustomerRepositoryInterface $customerRepository,
3232
private EraseEntityManagementInterface $eraseEntityManagement,
3333
private EraseEntityRepositoryInterface $eraseEntityRepository,
34-
private RedirectFactory $redirectFactory,
3534
private Config $config
36-
) {}
35+
) {
36+
parent::__construct($context);
37+
}
3738

3839
public function execute(): ResultInterface|ResponseInterface
3940
{
4041
try {
41-
$customerId = (int)$this->request->getParam('id');
42+
$customerId = (int)$this->getRequest()->getParam('id');
4243
if ($this->config->isErasureEnabled($this->customerRepository->getById($customerId)->getWebsiteId())) {
43-
$this->eraseEntityManagement->process(
44-
$this->eraseEntityRepository->getByEntity($customerId, 'customer')
45-
);
44+
$this->eraseEntityManagement->process($this->fetchEntity($customerId));
4645
$this->messageManager->addSuccessMessage(new Phrase('You erased the customer.'));
4746
}
4847
} catch (LocalizedException $e) {
@@ -51,6 +50,19 @@ public function execute(): ResultInterface|ResponseInterface
5150
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
5251
}
5352

54-
return $this->redirectFactory->create()->setPath('customer/index');
53+
return $this->resultRedirectFactory->create()->setPath('customer/index');
54+
}
55+
56+
/**
57+
* @throws CouldNotSaveException
58+
* @throws LocalizedException
59+
*/
60+
private function fetchEntity(int $customerId): EraseEntityInterface
61+
{
62+
try {
63+
return $this->eraseEntityRepository->getByEntity($customerId, 'customer');
64+
} catch (NoSuchEntityException) {
65+
return $this->eraseEntityManagement->create($customerId, 'customer');
66+
}
5567
}
5668
}

Controller/Adminhtml/Privacy/Export.php

+28-14
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,44 @@
88
namespace Opengento\Gdpr\Controller\Adminhtml\Privacy;
99

1010
use Exception;
11-
use Magento\Backend\Model\View\Result\RedirectFactory;
11+
use Magento\Backend\App\Action;
12+
use Magento\Backend\App\Action\Context;
1213
use Magento\Customer\Api\CustomerRepositoryInterface;
13-
use Magento\Framework\App\Action\HttpGetActionInterface;
1414
use Magento\Framework\App\Filesystem\DirectoryList;
15-
use Magento\Framework\App\RequestInterface;
1615
use Magento\Framework\App\Response\Http\FileFactory;
1716
use Magento\Framework\App\ResponseInterface;
1817
use Magento\Framework\Controller\ResultInterface;
18+
use Magento\Framework\Exception\AlreadyExistsException;
19+
use Magento\Framework\Exception\CouldNotSaveException;
1920
use Magento\Framework\Exception\LocalizedException;
20-
use Magento\Framework\Message\ManagerInterface;
21+
use Magento\Framework\Exception\NoSuchEntityException;
2122
use Magento\Framework\Phrase;
23+
use Opengento\Gdpr\Api\Data\ExportEntityInterface;
2224
use Opengento\Gdpr\Api\ExportEntityManagementInterface;
2325
use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
2426
use Opengento\Gdpr\Model\Config;
2527

26-
class Export implements HttpGetActionInterface
28+
class Export extends Action
2729
{
2830
public const ADMIN_RESOURCE = 'Opengento_Gdpr::customer_export';
2931

3032
public function __construct(
31-
private RequestInterface $request,
32-
private ManagerInterface $messageManager,
33+
Context $context,
3334
private CustomerRepositoryInterface $customerRepository,
3435
private ExportEntityManagementInterface $exportEntityManagement,
3536
private ExportEntityRepositoryInterface $exportEntityRepository,
36-
private RedirectFactory $redirectFactory,
3737
private Config $config,
3838
private FileFactory $fileFactory
39-
) {}
39+
) {
40+
parent::__construct($context);
41+
}
4042

4143
public function execute(): ResultInterface|ResponseInterface
4244
{
4345
try {
44-
$customerId = (int)$this->request->getParam('id');
46+
$customerId = (int)$this->getRequest()->getParam('id');
4547
if ($this->config->isExportEnabled($this->customerRepository->getById($customerId)->getWebsiteId())) {
46-
$exportEntity = $this->exportEntityManagement->export(
47-
$this->exportEntityRepository->getByEntity($customerId, 'customer')
48-
);
48+
$exportEntity = $this->exportEntityManagement->export($this->fetchEntity($customerId));
4949

5050
return $this->fileFactory->create(
5151
'customer_privacy_data_' . $exportEntity->getEntityId() . '.zip',
@@ -62,6 +62,20 @@ public function execute(): ResultInterface|ResponseInterface
6262
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
6363
}
6464

65-
return $this->redirectFactory->create()->setRefererOrBaseUrl();
65+
return $this->resultRedirectFactory->create()->setRefererOrBaseUrl();
66+
}
67+
68+
/**
69+
* @throws AlreadyExistsException
70+
* @throws CouldNotSaveException
71+
* @throws LocalizedException
72+
*/
73+
private function fetchEntity(int $customerId): ExportEntityInterface
74+
{
75+
try {
76+
return $this->exportEntityRepository->getByEntity($customerId, 'customer');
77+
} catch (NoSuchEntityException) {
78+
return $this->exportEntityManagement->create($customerId, 'customer');
79+
}
6680
}
6781
}

Model/Config/Source/VirtualEntityAttributes.php

-37
This file was deleted.

Model/Erase/NotifyEraseEntityManagement.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ public function create(int $entityId, string $entityType): EraseEntityInterface
2929

3030
public function cancel(int $entityId, string $entityType): bool
3131
{
32+
$eraseEntity = $this->eraseRepository->getByEntity($entityId, $entityType);
3233
$canceled = $this->eraseManagement->cancel($entityId, $entityType);
3334
if ($canceled) {
34-
$this->notifierRepository->get($entityType, 'cancel')->notify($this->eraseRepository->getByEntity($entityId, $entityType));
35+
$this->notifierRepository->get($entityType, 'cancel')->notify($eraseEntity);
3536
}
3637

3738
return $canceled;

0 commit comments

Comments
 (0)