|
8 | 8 | namespace Opengento\Gdpr\Controller\Adminhtml\Guest;
|
9 | 9 |
|
10 | 10 | use Exception;
|
11 |
| -use Magento\Backend\App\Action\Context; |
12 |
| -use Magento\Backend\Model\View\Result\Redirect; |
| 11 | +use Magento\Backend\Model\View\Result\RedirectFactory; |
| 12 | +use Magento\Framework\App\Action\HttpGetActionInterface; |
13 | 13 | use Magento\Framework\App\Filesystem\DirectoryList;
|
| 14 | +use Magento\Framework\App\RequestInterface; |
14 | 15 | use Magento\Framework\App\Response\Http\FileFactory;
|
15 | 16 | use Magento\Framework\App\ResponseInterface;
|
16 |
| -use Magento\Framework\Controller\ResultFactory; |
17 | 17 | use Magento\Framework\Controller\ResultInterface;
|
18 | 18 | use Magento\Framework\Exception\LocalizedException;
|
| 19 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 20 | +use Magento\Framework\Message\ManagerInterface; |
19 | 21 | use Magento\Framework\Phrase;
|
| 22 | +use Magento\Sales\Api\OrderRepositoryInterface; |
| 23 | +use Magento\Store\Model\StoreManagerInterface; |
20 | 24 | use Opengento\Gdpr\Api\ExportEntityManagementInterface;
|
21 | 25 | use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
|
22 |
| -use Opengento\Gdpr\Controller\Adminhtml\AbstractAction; |
23 | 26 | use Opengento\Gdpr\Model\Config;
|
24 | 27 |
|
25 |
| -class Export extends AbstractAction |
| 28 | +class Export implements HttpGetActionInterface |
26 | 29 | {
|
27 | 30 | public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_export';
|
28 | 31 |
|
29 | 32 | public function __construct(
|
30 |
| - Context $context, |
31 |
| - Config $config, |
| 33 | + private RequestInterface $request, |
| 34 | + private ManagerInterface $messageManager, |
| 35 | + private StoreManagerInterface $storeManager, |
| 36 | + private OrderRepositoryInterface $orderRepository, |
32 | 37 | private ExportEntityManagementInterface $exportEntityManagement,
|
33 | 38 | private ExportEntityRepositoryInterface $exportEntityRepository,
|
| 39 | + private Config $config, |
| 40 | + private RedirectFactory $redirectFactory, |
34 | 41 | private FileFactory $fileFactory
|
35 |
| - ) { |
36 |
| - parent::__construct($context, $config); |
37 |
| - } |
| 42 | + ) {} |
38 | 43 |
|
39 |
| - protected function executeAction(): ResultInterface|ResponseInterface |
| 44 | + public function execute(): ResultInterface|ResponseInterface |
40 | 45 | {
|
41 | 46 | try {
|
42 |
| - $exportEntity = $this->exportEntityManagement->export( |
43 |
| - $this->exportEntityRepository->getByEntity((int)$this->getRequest()->getParam('id'), 'order') |
44 |
| - ); |
| 47 | + $orderId = (int)$this->request->getParam('id'); |
| 48 | + if ($this->isOrderExportEnabled($orderId)) { |
| 49 | + $exportEntity = $this->exportEntityManagement->export( |
| 50 | + $this->exportEntityRepository->getByEntity($orderId, 'order') |
| 51 | + ); |
45 | 52 |
|
46 |
| - return $this->fileFactory->create( |
47 |
| - 'guest_privacy_data_' . $exportEntity->getEntityId() . '.zip', |
48 |
| - [ |
49 |
| - 'type' => 'filename', |
50 |
| - 'value' => $exportEntity->getFilePath(), |
51 |
| - ], |
52 |
| - DirectoryList::TMP |
53 |
| - ); |
| 53 | + return $this->fileFactory->create( |
| 54 | + 'guest_privacy_data_' . $exportEntity->getEntityId() . '.zip', |
| 55 | + [ |
| 56 | + 'type' => 'filename', |
| 57 | + 'value' => $exportEntity->getFilePath(), |
| 58 | + ], |
| 59 | + DirectoryList::TMP |
| 60 | + ); |
| 61 | + } |
54 | 62 | } catch (LocalizedException $e) {
|
55 | 63 | $this->messageManager->addErrorMessage($e->getMessage());
|
56 | 64 | } catch (Exception $e) {
|
57 | 65 | $this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
|
58 | 66 | }
|
59 | 67 |
|
60 |
| - /** @var Redirect $resultRedirect */ |
61 |
| - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); |
| 68 | + return $this->redirectFactory->create()->setRefererOrBaseUrl(); |
| 69 | + } |
62 | 70 |
|
63 |
| - return $resultRedirect->setRefererOrBaseUrl(); |
| 71 | + /** |
| 72 | + * @throws NoSuchEntityException |
| 73 | + */ |
| 74 | + private function isOrderExportEnabled(int $orderId): bool |
| 75 | + { |
| 76 | + return $this->config->isErasureEnabled( |
| 77 | + $this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId() |
| 78 | + ); |
64 | 79 | }
|
65 | 80 | }
|
0 commit comments