diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index ec162a1c..4748360f 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,7 +1,7 @@ # These are supported funding model platforms #github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: thomas_klein # Replace with a single Patreon username +#patreon: # Replace with a single Patreon username #open_collective: # Replace with a single Open Collective username #ko_fi: # Replace with a single Ko-fi username #tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel @@ -9,4 +9,4 @@ patreon: thomas_klein # Replace with a single Patreon username #liberapay: # Replace with a single Liberapay username #issuehunt: # Replace with a single IssueHunt username #otechie: # Replace with a single Otechie username -custom: ['https://secure.payplug.com/p/jtN33xM'] +custom: ['https://www.helloasso.com/associations/opengento/formulaires/1'] diff --git a/.github/workflows/coding-standard.yml b/.github/workflows/coding-standard.yml index f68fb074..597ccd84 100644 --- a/.github/workflows/coding-standard.yml +++ b/.github/workflows/coding-standard.yml @@ -6,5 +6,5 @@ jobs: name: M2 Coding Standard runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: extdn/github-actions-m2/magento-coding-standard@master + - uses: actions/checkout@v4 + - uses: extdn/github-actions-m2/magento-coding-standard/8.2@master diff --git a/.github/workflows/mess-detector.yml b/.github/workflows/mess-detector.yml index 8b1700cb..9e69eca4 100644 --- a/.github/workflows/mess-detector.yml +++ b/.github/workflows/mess-detector.yml @@ -6,5 +6,5 @@ jobs: name: M2 Mess Detector runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: extdn/github-actions-m2/magento-mess-detector@master + - uses: actions/checkout@v4 + - uses: extdn/github-actions-m2/magento-mess-detector/@master diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index f5713e24..6d999b44 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -6,7 +6,7 @@ jobs: name: M2 PHPStan runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: extdn/github-actions-m2/magento-phpstan@master + - uses: actions/checkout@v4 + - uses: extdn/github-actions-m2/magento-phpstan/8.2@master with: composer_name: opengento/module-gdpr diff --git a/Api/ActionEntityRepositoryInterface.php b/Api/ActionEntityRepositoryInterface.php deleted file mode 100644 index 09f45125..00000000 --- a/Api/ActionEntityRepositoryInterface.php +++ /dev/null @@ -1,59 +0,0 @@ -urlBuilder = $urlBuilder; - } - - public function getButtonData(): array - { - return [ - 'label' => new Phrase('Back'), - 'on_click' => 'location.href = "' . $this->urlBuilder->getUrl('*/*/') . '";', - 'class' => 'back', - 'sort_order' => 10, - ]; - } -} diff --git a/Block/Adminhtml/Action/Edit/ExecuteButton.php b/Block/Adminhtml/Action/Edit/ExecuteButton.php deleted file mode 100644 index b8a7c52e..00000000 --- a/Block/Adminhtml/Action/Edit/ExecuteButton.php +++ /dev/null @@ -1,29 +0,0 @@ - new Phrase('Execute Action'), - 'class' => 'primary', - 'data_attribute' => [ - 'mage-init' => ['button' => ['event' => 'save']], - 'form-role' => 'save', - ], - 'on_click' => 'location.reload();', - 'sort_order' => 30, - 'aclResource' => 'Opengento_Gdpr::gdpr_actions_execute', - ]; - } -} diff --git a/Block/Adminhtml/Action/Edit/ResetButton.php b/Block/Adminhtml/Action/Edit/ResetButton.php deleted file mode 100644 index 60a13db3..00000000 --- a/Block/Adminhtml/Action/Edit/ResetButton.php +++ /dev/null @@ -1,24 +0,0 @@ - new Phrase('Reset'), - 'class' => 'reset', - 'on_click' => 'location.reload();', - 'sort_order' => 20, - ]; - } -} diff --git a/Block/Adminhtml/Config/Form/Field/AttributesAnonymizers.php b/Block/Adminhtml/Config/Form/Field/AttributesAnonymizers.php index 6e98899b..380419f7 100644 --- a/Block/Adminhtml/Config/Form/Field/AttributesAnonymizers.php +++ b/Block/Adminhtml/Config/Form/Field/AttributesAnonymizers.php @@ -33,7 +33,7 @@ public function getAnonymizersSelectRenderer(): Select ); } - return $this->getData('anonymizers_select_renderer'); + return $this->_getData('anonymizers_select_renderer'); } /** @@ -53,6 +53,7 @@ protected function _prepareToRender(): void 'anonymizer', [ 'label' => new Phrase('Anonymizer'), + 'class' => 'required-entry', 'renderer' => $this->getAnonymizersSelectRenderer(), ] ); diff --git a/Block/Adminhtml/Config/Form/Field/Select/OptionSourceSelect.php b/Block/Adminhtml/Config/Form/Field/Select/OptionSourceSelect.php index f2297087..7026c5c9 100644 --- a/Block/Adminhtml/Config/Form/Field/Select/OptionSourceSelect.php +++ b/Block/Adminhtml/Config/Form/Field/Select/OptionSourceSelect.php @@ -13,17 +13,11 @@ class OptionSourceSelect extends Select { - /** - * @var OptionSourceInterface - */ - private OptionSourceInterface $optionSource; - public function __construct( Context $context, - OptionSourceInterface $optionSource, + private OptionSourceInterface $optionSource, array $data = [] ) { - $this->optionSource = $optionSource; parent::__construct($context, $data); } diff --git a/Block/Adminhtml/Order/Edit/EraseButton.php b/Block/Adminhtml/Order/Edit/EraseButton.php deleted file mode 100644 index 4bdf523b..00000000 --- a/Block/Adminhtml/Order/Edit/EraseButton.php +++ /dev/null @@ -1,59 +0,0 @@ -eraseEntityChecker = $eraseEntityChecker; - parent::__construct($context, $data); - } - - /** - * @inheritdoc - * @throws LocalizedException - */ - protected function _construct(): void - { - parent::_construct(); - - /** @var View $orderView */ - $orderView = $this->getLayout()->getBlock('sales_order_edit'); - $orderId = (int) $orderView->getOrderId(); - - if ($this->_authorization->isAllowed('Opengento_Gdpr::order_erase') && - $this->eraseEntityChecker->canCreate($orderId, 'order') - ) { - $confirmMessage = new Phrase('Are you sure you want to do this?'); - $eraseUrl = $this->getUrl('sales/guest/erase', ['id' => $orderId]); - - $orderView->addButton( - 'opengento-gdpr-order-view-erase-button', - [ - 'label' => new Phrase('Erase Personal Data'), - 'class' => 'action-secondary erase', - 'onclick' => 'deleteConfirm("' . $confirmMessage . '", "' . $eraseUrl . '", {"data":{}})', - ], - 1 - ); - } - } -} diff --git a/Block/Adminhtml/Order/Edit/ExportButton.php b/Block/Adminhtml/Order/Edit/ExportButton.php deleted file mode 100644 index 5a546ecb..00000000 --- a/Block/Adminhtml/Order/Edit/ExportButton.php +++ /dev/null @@ -1,40 +0,0 @@ -getLayout()->getBlock('sales_order_edit'); - $orderId = (int) $orderView->getOrderId(); - - if ($this->_authorization->isAllowed('Opengento_Gdpr::order_export')) { - $orderView->addButton( - 'opengento-gdpr-order-view-export-button', - [ - 'label' => new Phrase('Export Personal Data'), - 'class' => 'export', - 'onclick' => 'setLocation("' . $this->getUrl('sales/guest/export', ['id' => $orderId]) . '")', - ] - ); - } - } -} diff --git a/Console/Command/EraseCommand.php b/Console/Command/EraseCommand.php index 0d6a8536..6ebc3a69 100644 --- a/Console/Command/EraseCommand.php +++ b/Console/Command/EraseCommand.php @@ -10,12 +10,15 @@ use Magento\Framework\App\Area; use Magento\Framework\App\State; use Magento\Framework\Console\Cli; +use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Registry; -use Opengento\Gdpr\Api\ActionInterface; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; +use Opengento\Gdpr\Api\Data\EraseEntityInterface; +use Opengento\Gdpr\Api\EraseEntityManagementInterface; +use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -25,25 +28,13 @@ class EraseCommand extends Command private const INPUT_ARGUMENT_ENTITY_ID = 'entity_id'; private const INPUT_ARGUMENT_ENTITY_TYPE = 'entity_type'; - private State $appState; - - private Registry $registry; - - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( - State $appState, - Registry $registry, - ActionInterface $action, - ContextBuilder $actionContextBuilder, + private State $appState, + private Registry $registry, + private EraseEntityRepositoryInterface $eraseEntityRepository, + private EraseEntityManagementInterface $eraseEntityManagement, string $name = 'gdpr:entity:erase' ) { - $this->appState = $appState; - $this->registry = $registry; - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; parent::__construct($name); } @@ -81,19 +72,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $entityIds = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_ID); $entityType = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_TYPE); + $progressBar = new ProgressBar($output, count($entityIds)); + $progressBar->start(); + try { foreach ($entityIds as $entityId) { - $this->action->execute( - $this->actionContextBuilder->setParameters( - [ArgumentReader::ENTITY_ID => $entityId, ArgumentReader::ENTITY_TYPE => $entityType] - )->create() - ); - - $output->writeln( - 'Entity\'s (' . $entityType . ') with ID "' . $entityId . '" has been erased.' - ); + $this->eraseEntityManagement->process($this->fetchEntity((int)$entityId, $entityType)); + $progressBar->advance(); } + $progressBar->finish(); + $output->writeln(''); + $output->writeln('Entities has been erased.'); } catch (LocalizedException $e) { + $output->writeln(''); $output->writeln('' . $e->getMessage() . ''); $returnCode = Cli::RETURN_FAILURE; } @@ -102,4 +93,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int return $returnCode; } + + /** + * @throws CouldNotSaveException + * @throws LocalizedException + */ + private function fetchEntity(int $entityId, string $entityType): EraseEntityInterface + { + try { + return $this->eraseEntityRepository->getByEntity($entityId, $entityType); + } catch (NoSuchEntityException) { + return $this->eraseEntityManagement->create($entityId, $entityType); + } + } } diff --git a/Console/Command/ExportCommand.php b/Console/Command/ExportCommand.php index 9af11c0a..30a8dbbd 100644 --- a/Console/Command/ExportCommand.php +++ b/Console/Command/ExportCommand.php @@ -11,39 +11,30 @@ use Magento\Framework\App\Area; use Magento\Framework\App\State; use Magento\Framework\Console\Cli; +use Magento\Framework\Exception\AlreadyExistsException; +use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; -use Opengento\Gdpr\Api\ActionInterface; +use Magento\Framework\Exception\NoSuchEntityException; use Opengento\Gdpr\Api\Data\ExportEntityInterface; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; -use Opengento\Gdpr\Model\Action\Export\ArgumentReader as ExportArgumentReader; +use Opengento\Gdpr\Api\ExportEntityManagementInterface; +use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ExportCommand extends Command { private const INPUT_ARGUMENT_ENTITY_ID = 'entity_id'; private const INPUT_ARGUMENT_ENTITY_TYPE = 'entity_type'; - private const INPUT_OPTION_FILENAME = 'filename'; - - private State $appState; - - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; public function __construct( - State $appState, - ActionInterface $action, - ContextBuilder $actionContextBuilder, + private State $appState, + private ExportEntityRepositoryInterface $exportEntityRepository, + private ExportEntityManagementInterface $exportEntityManagement, string $name = 'gdpr:entity:export' ) { - $this->appState = $appState; - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; parent::__construct($name); } @@ -62,13 +53,6 @@ protected function configure(): void self::INPUT_ARGUMENT_ENTITY_ID, InputArgument::REQUIRED + InputArgument::IS_ARRAY, 'Entity ID' - ), - new InputOption( - self::INPUT_OPTION_FILENAME, - '-f', - InputOption::VALUE_OPTIONAL, - 'Export file name', - 'personal_data' ) ]); } @@ -84,28 +68,45 @@ protected function execute(InputInterface $input, OutputInterface $output): int $resultCode = Cli::RETURN_SUCCESS; $entityIds = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_ID); $entityType = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_TYPE); - $fileName = $input->getOption(self::INPUT_OPTION_FILENAME); + + $progressBar = new ProgressBar($output, count($entityIds)); + $progressBar->start(); + + $files = []; try { foreach ($entityIds as $entityId) { - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => $entityId, - ArgumentReader::ENTITY_TYPE => $entityType, - ExportArgumentReader::EXPORT_FILE_NAME => $fileName . '_' . $entityId - ]); - $result = $this->action->execute($this->actionContextBuilder->create())->getResult(); - /** @var ExportEntityInterface $exportEntity */ - $exportEntity = $result[ExportArgumentReader::EXPORT_ENTITY]; - - $output->writeln( - 'Entity\'s related data have been exported to: ' . $exportEntity->getFilePath() . '.' - ); + $exportEntity = $this->fetchEntity((int)$entityId, $entityType); + $this->exportEntityManagement->export($exportEntity); + $files[] = $exportEntity->getFilePath(); + $progressBar->advance(); + } + $progressBar->finish(); + $output->writeln(''); + $output->writeln('Entities data have been exported to:'); + foreach ($files as $file) { + $output->writeln($file); } } catch (Exception $e) { + $output->writeln(''); $output->writeln('' . $e->getMessage() . ''); $resultCode = Cli::RETURN_FAILURE; } return $resultCode; } + + /** + * @throws AlreadyExistsException + * @throws CouldNotSaveException + * @throws LocalizedException + */ + private function fetchEntity(int $entityId, string $entityType): ExportEntityInterface + { + try { + return $this->exportEntityRepository->getByEntity($entityId, $entityType); + } catch (NoSuchEntityException) { + return $this->exportEntityManagement->create($entityId, $entityType); + } + } } diff --git a/Controller/AbstractAction.php b/Controller/AbstractAction.php index fc279b2f..43f2f091 100644 --- a/Controller/AbstractAction.php +++ b/Controller/AbstractAction.php @@ -19,25 +19,12 @@ abstract class AbstractAction implements ActionInterface { - protected RequestInterface $request; - - protected ResultFactory $resultFactory; - - protected ManagerInterface $messageManager; - - protected Config $config; - public function __construct( - RequestInterface $request, - ResultFactory $resultFactory, - ManagerInterface $messageManager, - Config $config - ) { - $this->request = $request; - $this->resultFactory = $resultFactory; - $this->messageManager = $messageManager; - $this->config = $config; - } + protected RequestInterface $request, + protected ResultFactory $resultFactory, + protected ManagerInterface $messageManager, + protected Config $config + ) {} public function execute() { @@ -47,10 +34,9 @@ public function execute() /** * Execute action based on request and return result * - * @return ResultInterface|ResponseInterface * @throws NotFoundException */ - abstract protected function executeAction(); + abstract protected function executeAction(): ResultInterface|ResponseInterface; protected function isAllowed(): bool { diff --git a/Controller/AbstractGuest.php b/Controller/AbstractGuest.php index fd2a1e51..4379624c 100644 --- a/Controller/AbstractGuest.php +++ b/Controller/AbstractGuest.php @@ -8,6 +8,7 @@ namespace Opengento\Gdpr\Controller; use Magento\Framework\App\RequestInterface; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Message\ManagerInterface; @@ -18,27 +19,18 @@ abstract class AbstractGuest extends AbstractAction { - /** - * @var OrderLoaderInterface - */ - protected OrderLoaderInterface $orderLoader; - - protected Registry $registry; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, ManagerInterface $messageManager, Config $config, - OrderLoaderInterface $orderLoader, - Registry $registry + protected OrderLoaderInterface $orderLoader, + protected Registry $registry ) { - $this->orderLoader = $orderLoader; - $this->registry = $registry; parent::__construct($request, $resultFactory, $messageManager, $config); } - public function execute() + public function execute(): ResultInterface|ResponseInterface { $result = $this->orderLoader->load($this->request); diff --git a/Controller/AbstractPrivacy.php b/Controller/AbstractPrivacy.php deleted file mode 100644 index fced185e..00000000 --- a/Controller/AbstractPrivacy.php +++ /dev/null @@ -1,61 +0,0 @@ -customerSession = $customerSession; - $this->response = $response; - parent::__construct($request, $resultFactory, $messageManager, $config); - } - - public function execute() - { - return $this->customerSession->authenticate() ? $this->defaultAction() : $this->response; - } - - /** - * @throws NotFoundException - */ - private function defaultAction() - { - return $this->isAllowed() ? $this->executeAction() : $this->forwardNoRoute(); - } -} diff --git a/Controller/Adminhtml/AbstractAction.php b/Controller/Adminhtml/AbstractAction.php deleted file mode 100644 index 3da9b942..00000000 --- a/Controller/Adminhtml/AbstractAction.php +++ /dev/null @@ -1,60 +0,0 @@ -config = $config; - parent::__construct($context); - } - - public function execute() - { - if ($this->isAllowed()) { - return $this->executeAction(); - } - - return $this->forwardNoRoute(); - } - - /** - * Execute action based on request and return result - * - * @return ResultInterface|ResponseInterface - * @throws NotFoundException - */ - abstract protected function executeAction(); - - protected function isAllowed(): bool - { - return $this->config->isModuleEnabled(); - } - - protected function forwardNoRoute(): ResultInterface - { - /** @var Forward $resultForward */ - $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); - - return $resultForward->forward('no_route'); - } -} diff --git a/Controller/Adminhtml/Action/Execute.php b/Controller/Adminhtml/Action/Execute.php deleted file mode 100644 index 3ccc56d7..00000000 --- a/Controller/Adminhtml/Action/Execute.php +++ /dev/null @@ -1,91 +0,0 @@ -actionFactory = $actionFactory; - $this->contextBuilder = $contextBuilder; - $this->actionStates = $actionStates; - parent::__construct($context); - } - - public function execute(): Redirect - { - /** @var Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - $resultRedirect->setPath('*/*/new'); - - try { - $result = $this->proceed($this->getRequest()->getParam('type')); - $resultRedirect->setPath('*/*/'); - $this->messageManager->addSuccessMessage( - new Phrase('The action state is now: %1.', [$this->actionStates->getOptionText($result->getState())]) - ); - } catch (AbstractAggregateException $e) { - $this->messageManager->addErrorMessage($e->getMessage()); - foreach ($e->getErrors() as $exception) { - $this->messageManager->addErrorMessage($exception->getMessage()); - } - } catch (LocalizedException $e) { - $this->messageManager->addErrorMessage($e->getMessage()); - } catch (Exception $e) { - $this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.')); - } - - return $resultRedirect; - } - - /** - * @param string $actionType - * @return ActionResultInterface - * @throws LocalizedException - */ - private function proceed(string $actionType): ActionResultInterface - { - $parameters = []; - /** @var array $param */ - foreach ((array) $this->getRequest()->getParam('parameters', []) as $param) { - $parameters[$param['name']] = $param['value']; - } - $this->contextBuilder->setParameters($parameters); - - return $this->actionFactory->get($actionType)->execute($this->contextBuilder->create()); - } -} diff --git a/Controller/Adminhtml/Action/Index.php b/Controller/Adminhtml/Action/Index.php deleted file mode 100644 index 1a129690..00000000 --- a/Controller/Adminhtml/Action/Index.php +++ /dev/null @@ -1,31 +0,0 @@ -resultFactory->create(ResultFactory::TYPE_PAGE); - $resultPage->setActiveMenu('Opengento_Gdpr::gdpr_actions'); - $resultPage->getConfig()->getTitle()->set(new Phrase('View Actions')); - $resultPage->addBreadcrumb(new Phrase('GDPR'), new Phrase('GDPR')); - $resultPage->addBreadcrumb(new Phrase('View Actions'), new Phrase('View Actions')); - - return $resultPage; - } -} diff --git a/Controller/Adminhtml/Action/InlineEdit.php b/Controller/Adminhtml/Action/InlineEdit.php deleted file mode 100644 index 3d0dd214..00000000 --- a/Controller/Adminhtml/Action/InlineEdit.php +++ /dev/null @@ -1,112 +0,0 @@ -actionRepository = $actionRepository; - $this->hydratorPool = $hydratorPool; - $this->logger = $logger; - $this->allowedAttributes = $allowedAttributes; - parent::__construct($context); - } - - public function execute() - { - /** @var Json $resultJson */ - $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); - $error = false; - $messages = []; - $postItems = $this->getRequest()->getParam('items', []); - - if (!$postItems || !is_array($postItems) || !$this->getRequest()->getParam('isAjax')) { - return $resultJson->setData(['messages' => [new Phrase('Please correct the data sent.')], 'error' => true]); - } - - foreach ($postItems as $actionId => $item) { - try { - $this->edit($actionId, $item); - } catch (LocalizedException $e) { - $messages[] = new Phrase('Action with ID "%1": %2', [$actionId, $e->getMessage()]); - $error = true; - } catch (Exception $e) { - $this->logger->error($e->getMessage(), $e->getTrace()); - $messages[] = new Phrase( - 'Action with ID "%1": %2', - [$actionId, new Phrase('An error occurred on the server.')] - ); - $error = true; - } - } - - return $resultJson->setData(compact('messages', 'error')); - } - - /** - * @param int $actionId - * @param array $data - * @return void - * @throws LocalizedException - * @todo improve extensibility: these settings should be global and be used to disable field in the ui grid - */ - private function edit(int $actionId, array $data): void - { - $hydrator = $this->hydratorPool->getHydrator(ActionEntityInterface::class); - $actionEntity = $this->actionRepository->getById($actionId); - - $allowedAttributes = array_merge( - $this->allowedAttributes['*'] ?? [], - $this->allowedAttributes[$actionEntity->getState()] ?? [] - ); - - /** @var ActionEntityInterface $actionEntity */ - $actionEntity = $hydrator->hydrate( - $actionEntity, - array_intersect_key($data, array_fill_keys($allowedAttributes, null)) - ); - - $this->actionRepository->save($actionEntity); - } -} diff --git a/Controller/Adminhtml/Action/MassDelete.php b/Controller/Adminhtml/Action/MassDelete.php deleted file mode 100644 index e47546f7..00000000 --- a/Controller/Adminhtml/Action/MassDelete.php +++ /dev/null @@ -1,85 +0,0 @@ -filter = $filter; - $this->collectionFactory = $collectionFactory; - $this->actionRepository = $actionRepository; - parent::__construct($context); - } - - public function execute(): Redirect - { - /** @var Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - $resultRedirect->setPath('*/*/'); - - try { - $this->massAction($this->filter->getCollection($this->collectionFactory->create())); - } catch (LocalizedException $e) { - $this->messageManager->addErrorMessage($e->getMessage()); - } catch (Exception $e) { - $this->messageManager->addExceptionMessage($e, $e->getMessage()); - } - - return $resultRedirect; - } - - /** - * @param AbstractDb $collection - * @return void - * @throws CouldNotDeleteException - * @throws NoSuchEntityException - */ - private function massAction(AbstractDb $collection): void - { - $count = $collection->count(); - - /** @var ActionInterface $actionEntity */ - foreach ($collection->getItems() as $actionEntity) { - $this->actionRepository->delete($actionEntity); - } - - $this->messageManager->addSuccessMessage(new Phrase('A total of %1 record(s) have been deleted.', [$count])); - } -} diff --git a/Controller/Adminhtml/Action/NewAction.php b/Controller/Adminhtml/Action/NewAction.php deleted file mode 100644 index f29ca439..00000000 --- a/Controller/Adminhtml/Action/NewAction.php +++ /dev/null @@ -1,31 +0,0 @@ -resultFactory->create(ResultFactory::TYPE_PAGE); - $resultPage->setActiveMenu('Opengento_Gdpr::gdpr_actions'); - $resultPage->getConfig()->getTitle()->set(new Phrase('Execute New Action')); - $resultPage->addBreadcrumb(new Phrase('GDPR'), new Phrase('GDPR')); - $resultPage->addBreadcrumb(new Phrase('Execute New Action'), new Phrase('Execute New Action')); - - return $resultPage; - } -} diff --git a/Controller/Adminhtml/Guest/Erase.php b/Controller/Adminhtml/Guest/Erase.php index 8c08cc7e..99e373bf 100644 --- a/Controller/Adminhtml/Guest/Erase.php +++ b/Controller/Adminhtml/Guest/Erase.php @@ -8,56 +8,73 @@ namespace Opengento\Gdpr\Controller\Adminhtml\Guest; use Exception; +use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\View\Result\Redirect; -use Magento\Framework\App\Action\HttpPostActionInterface; -use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Phrase; -use Opengento\Gdpr\Api\ActionInterface; -use Opengento\Gdpr\Controller\Adminhtml\AbstractAction; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; +use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Store\Model\StoreManagerInterface; +use Opengento\Gdpr\Api\Data\EraseEntityInterface; +use Opengento\Gdpr\Api\EraseEntityManagementInterface; +use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; use Opengento\Gdpr\Model\Config; -class Erase extends AbstractAction implements HttpPostActionInterface +class Erase extends Action { public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_erase'; - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( Context $context, - Config $config, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private StoreManagerInterface $storeManager, + private OrderRepositoryInterface $orderRepository, + private EraseEntityManagementInterface $eraseEntityManagement, + private EraseEntityRepositoryInterface $eraseEntityRepository, + private Config $config ) { - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; - parent::__construct($context, $config); + parent::__construct($context); } - protected function executeAction() + public function execute(): ResultInterface|ResponseInterface { - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $this->getRequest()->getParam('id'), - ArgumentReader::ENTITY_TYPE => 'order' - ]); - try { - $this->action->execute($this->actionContextBuilder->create()); - $this->messageManager->addSuccessMessage(new Phrase('You erased the order.')); + $orderId = (int)$this->getRequest()->getParam('id'); + if ($this->isOrderErasureEnabled($orderId)) { + $this->eraseEntityManagement->process($this->fetchEntity($orderId)); + $this->messageManager->addSuccessMessage(new Phrase('You erased the order.')); + } } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.')); } - /** @var Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $this->resultRedirectFactory->create()->setPath('sales/order/index'); + } + + /** + * @throws NoSuchEntityException + */ + private function isOrderErasureEnabled(int $orderId): bool + { + return $this->config->isErasureEnabled( + $this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId() + ); + } - return $resultRedirect->setPath('sales/order/index'); + /** + * @throws CouldNotSaveException + * @throws LocalizedException + */ + private function fetchEntity(int $orderId): EraseEntityInterface + { + try { + return $this->eraseEntityRepository->getByEntity($orderId, 'order'); + } catch (NoSuchEntityException) { + return $this->eraseEntityManagement->create($orderId, 'order'); + } } } diff --git a/Controller/Adminhtml/Guest/Export.php b/Controller/Adminhtml/Guest/Export.php index 417ce35f..37e07fc3 100644 --- a/Controller/Adminhtml/Guest/Export.php +++ b/Controller/Adminhtml/Guest/Export.php @@ -8,78 +8,86 @@ namespace Opengento\Gdpr\Controller\Adminhtml\Guest; use Exception; +use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\View\Result\Redirect; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Response\Http\FileFactory; -use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\AlreadyExistsException; +use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Phrase; -use Opengento\Gdpr\Api\ActionInterface; +use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Store\Model\StoreManagerInterface; use Opengento\Gdpr\Api\Data\ExportEntityInterface; -use Opengento\Gdpr\Controller\Adminhtml\AbstractAction; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; -use Opengento\Gdpr\Model\Action\Export\ArgumentReader as ExportArgumentReader; +use Opengento\Gdpr\Api\ExportEntityManagementInterface; +use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; use Opengento\Gdpr\Model\Config; -class Export extends AbstractAction +class Export extends Action { public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_export'; - /** - * @var FileFactory - */ - private FileFactory $fileFactory; - - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( Context $context, - Config $config, - FileFactory $fileFactory, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private StoreManagerInterface $storeManager, + private OrderRepositoryInterface $orderRepository, + private ExportEntityManagementInterface $exportEntityManagement, + private ExportEntityRepositoryInterface $exportEntityRepository, + private Config $config, + private FileFactory $fileFactory ) { - $this->fileFactory = $fileFactory; - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; - parent::__construct($context, $config); + parent::__construct($context); } - protected function executeAction() + public function execute(): ResultInterface|ResponseInterface { - $entityId = (int) $this->getRequest()->getParam('id'); - - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => $entityId, - ArgumentReader::ENTITY_TYPE => 'order' - ]); - try { - $result = $this->action->execute($this->actionContextBuilder->create())->getResult(); - /** @var ExportEntityInterface $exportEntity */ - $exportEntity = $result[ExportArgumentReader::EXPORT_ENTITY]; + $orderId = (int)$this->getRequest()->getParam('id'); + if ($this->isOrderExportEnabled($orderId)) { + $exportEntity = $this->exportEntityManagement->export($this->fetchEntity($orderId)); - return $this->fileFactory->create( - 'guest_privacy_data_' . $entityId . '.zip', - [ - 'type' => 'filename', - 'value' => $exportEntity->getFilePath(), - ], - DirectoryList::TMP - ); + return $this->fileFactory->create( + 'guest_privacy_data_' . $exportEntity->getEntityId() . '.zip', + [ + 'type' => 'filename', + 'value' => $exportEntity->getFilePath(), + ], + DirectoryList::TMP + ); + } } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.')); } - /** @var Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $this->resultRedirectFactory->create()->setRefererOrBaseUrl(); + } + + /** + * @throws NoSuchEntityException + */ + private function isOrderExportEnabled(int $orderId): bool + { + return $this->config->isErasureEnabled( + $this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId() + ); + } - return $resultRedirect->setRefererOrBaseUrl(); + /** + * @throws AlreadyExistsException + * @throws CouldNotSaveException + * @throws LocalizedException + */ + private function fetchEntity(int $orderId): ExportEntityInterface + { + try { + return $this->exportEntityRepository->getByEntity($orderId, 'order'); + } catch (NoSuchEntityException) { + return $this->exportEntityManagement->create($orderId, 'order'); + } } } diff --git a/Controller/Adminhtml/Privacy/Erase.php b/Controller/Adminhtml/Privacy/Erase.php index 3b9e6bad..e0a8d97b 100644 --- a/Controller/Adminhtml/Privacy/Erase.php +++ b/Controller/Adminhtml/Privacy/Erase.php @@ -8,56 +8,61 @@ namespace Opengento\Gdpr\Controller\Adminhtml\Privacy; use Exception; +use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\View\Result\Redirect; -use Magento\Framework\App\Action\HttpPostActionInterface; -use Magento\Framework\Controller\ResultFactory; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Phrase; -use Opengento\Gdpr\Api\ActionInterface; -use Opengento\Gdpr\Controller\Adminhtml\AbstractAction; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; +use Opengento\Gdpr\Api\Data\EraseEntityInterface; +use Opengento\Gdpr\Api\EraseEntityManagementInterface; +use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; use Opengento\Gdpr\Model\Config; -class Erase extends AbstractAction implements HttpPostActionInterface +class Erase extends Action { public const ADMIN_RESOURCE = 'Opengento_Gdpr::customer_erase'; - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( Context $context, - Config $config, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private CustomerRepositoryInterface $customerRepository, + private EraseEntityManagementInterface $eraseEntityManagement, + private EraseEntityRepositoryInterface $eraseEntityRepository, + private Config $config ) { - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; - parent::__construct($context, $config); + parent::__construct($context); } - protected function executeAction() + public function execute(): ResultInterface|ResponseInterface { - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $this->getRequest()->getParam('id'), - ArgumentReader::ENTITY_TYPE => 'customer' - ]); - try { - $this->action->execute($this->actionContextBuilder->create()); - $this->messageManager->addSuccessMessage(new Phrase('You erased the customer.')); + $customerId = (int)$this->getRequest()->getParam('id'); + if ($this->config->isErasureEnabled($this->customerRepository->getById($customerId)->getWebsiteId())) { + $this->eraseEntityManagement->process($this->fetchEntity($customerId)); + $this->messageManager->addSuccessMessage(new Phrase('You erased the customer.')); + } } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.')); } - /** @var Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $this->resultRedirectFactory->create()->setPath('customer/index'); + } - return $resultRedirect->setPath('customer/index'); + /** + * @throws CouldNotSaveException + * @throws LocalizedException + */ + private function fetchEntity(int $customerId): EraseEntityInterface + { + try { + return $this->eraseEntityRepository->getByEntity($customerId, 'customer'); + } catch (NoSuchEntityException) { + return $this->eraseEntityManagement->create($customerId, 'customer'); + } } } diff --git a/Controller/Adminhtml/Privacy/Export.php b/Controller/Adminhtml/Privacy/Export.php index 3a1198b2..e0280916 100644 --- a/Controller/Adminhtml/Privacy/Export.php +++ b/Controller/Adminhtml/Privacy/Export.php @@ -8,78 +8,74 @@ namespace Opengento\Gdpr\Controller\Adminhtml\Privacy; use Exception; +use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\View\Result\Redirect; +use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Response\Http\FileFactory; -use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\AlreadyExistsException; +use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Phrase; -use Opengento\Gdpr\Api\ActionInterface; use Opengento\Gdpr\Api\Data\ExportEntityInterface; -use Opengento\Gdpr\Controller\Adminhtml\AbstractAction; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; -use Opengento\Gdpr\Model\Action\Export\ArgumentReader as ExportArgumentReader; +use Opengento\Gdpr\Api\ExportEntityManagementInterface; +use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; use Opengento\Gdpr\Model\Config; -class Export extends AbstractAction +class Export extends Action { public const ADMIN_RESOURCE = 'Opengento_Gdpr::customer_export'; - /** - * @var FileFactory - */ - private FileFactory $fileFactory; - - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( Context $context, - Config $config, - FileFactory $fileFactory, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private CustomerRepositoryInterface $customerRepository, + private ExportEntityManagementInterface $exportEntityManagement, + private ExportEntityRepositoryInterface $exportEntityRepository, + private Config $config, + private FileFactory $fileFactory ) { - $this->fileFactory = $fileFactory; - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; - parent::__construct($context, $config); + parent::__construct($context); } - protected function executeAction() + public function execute(): ResultInterface|ResponseInterface { - $customerId = (int) $this->getRequest()->getParam('id'); - - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => $customerId, - ArgumentReader::ENTITY_TYPE => 'customer' - ]); - try { - $result = $this->action->execute($this->actionContextBuilder->create())->getResult(); - /** @var ExportEntityInterface $exportEntity */ - $exportEntity = $result[ExportArgumentReader::EXPORT_ENTITY]; + $customerId = (int)$this->getRequest()->getParam('id'); + if ($this->config->isExportEnabled($this->customerRepository->getById($customerId)->getWebsiteId())) { + $exportEntity = $this->exportEntityManagement->export($this->fetchEntity($customerId)); - return $this->fileFactory->create( - 'customer_privacy_data_' . $customerId . '.zip', - [ - 'type' => 'filename', - 'value' => $exportEntity->getFilePath(), - ], - DirectoryList::TMP - ); + return $this->fileFactory->create( + 'customer_privacy_data_' . $exportEntity->getEntityId() . '.zip', + [ + 'type' => 'filename', + 'value' => $exportEntity->getFilePath(), + ], + DirectoryList::TMP + ); + } } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.')); } - /** @var Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $this->resultRedirectFactory->create()->setRefererOrBaseUrl(); + } - return $resultRedirect->setRefererOrBaseUrl(); + /** + * @throws AlreadyExistsException + * @throws CouldNotSaveException + * @throws LocalizedException + */ + private function fetchEntity(int $customerId): ExportEntityInterface + { + try { + return $this->exportEntityRepository->getByEntity($customerId, 'customer'); + } catch (NoSuchEntityException) { + return $this->exportEntityManagement->create($customerId, 'customer'); + } } } diff --git a/Controller/Adminhtml/Privacy/MassErase.php b/Controller/Adminhtml/Privacy/MassErase.php index 1babed60..62e9e527 100644 --- a/Controller/Adminhtml/Privacy/MassErase.php +++ b/Controller/Adminhtml/Privacy/MassErase.php @@ -13,50 +13,47 @@ use Magento\Customer\Controller\Adminhtml\Index\AbstractMassAction; use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory; use Magento\Eav\Model\Entity\Collection\AbstractCollection; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Phrase; use Magento\Ui\Component\MassAction\Filter; -use Opengento\Gdpr\Api\ActionInterface; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; +use Opengento\Gdpr\Api\Data\EraseEntityInterface; +use Opengento\Gdpr\Api\EraseEntityManagementInterface; +use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; class MassErase extends AbstractMassAction { public const ADMIN_RESOURCE = 'Opengento_Gdpr::customer_erase'; - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( Context $context, Filter $filter, CollectionFactory $collectionFactory, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private EraseEntityManagementInterface $eraseEntityManagement, + private EraseEntityRepositoryInterface $eraseEntityRepository, + private SearchCriteriaBuilder $searchCriteriaBuilder ) { - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; parent::__construct($context, $filter, $collectionFactory); } - protected function massAction(AbstractCollection $collection) + protected function massAction(AbstractCollection $collection): ResultInterface|ResponseInterface { $customerErased = 0; - foreach ($collection->getAllIds() as $customerId) { - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $customerId, - ArgumentReader::ENTITY_TYPE => 'customer' - ]); + $this->searchCriteriaBuilder->addFilter(EraseEntityInterface::ENTITY_ID, $collection->getAllIds(), 'in'); + $this->searchCriteriaBuilder->addFilter(EraseEntityInterface::ENTITY_TYPE, 'customer'); + $eraseEntityList = $this->eraseEntityRepository->getList($this->searchCriteriaBuilder->create()); + foreach ($eraseEntityList->getItems() as $eraseEntity) { try { - $this->action->execute($this->actionContextBuilder->create()); + $this->eraseEntityManagement->process($eraseEntity); $customerErased++; } catch (LocalizedException $e) { $this->messageManager->addErrorMessage( - new Phrase('Customer with id "%1": %2', [$customerId, $e->getMessage()]) + new Phrase('Customer with id "%1": %2', [$eraseEntity->getEntityId(), $e->getMessage()]) ); } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.')); diff --git a/Controller/Adminhtml/Privacy/MassExport.php b/Controller/Adminhtml/Privacy/MassExport.php index 295e9a73..ff4abf67 100644 --- a/Controller/Adminhtml/Privacy/MassExport.php +++ b/Controller/Adminhtml/Privacy/MassExport.php @@ -13,66 +13,60 @@ use Magento\Customer\Controller\Adminhtml\Index\AbstractMassAction; use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory; use Magento\Eav\Model\Entity\Collection\AbstractCollection; +use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Phrase; use Magento\Ui\Component\MassAction\Filter; -use Opengento\Gdpr\Api\ActionInterface; use Opengento\Gdpr\Api\Data\ExportEntityInterface; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; -use Opengento\Gdpr\Model\Action\Export\ArgumentReader as ExportArgumentReader; +use Opengento\Gdpr\Api\ExportEntityManagementInterface; +use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; use Opengento\Gdpr\Model\Archive\ArchiveManager; class MassExport extends AbstractMassAction { public const ADMIN_RESOURCE = 'Opengento_Gdpr::customer_export'; - /** - * @var FileFactory - */ - private FileFactory $fileFactory; - - private ArchiveManager $archiveManager; - - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( Context $context, Filter $filter, CollectionFactory $collectionFactory, - FileFactory $fileFactory, - ArchiveManager $archiveManager, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private FileFactory $fileFactory, + private ArchiveManager $archiveManager, + private ExportEntityManagementInterface $exportEntityManagement, + private ExportEntityRepositoryInterface $exportEntityRepository, + private SearchCriteriaBuilder $searchCriteriaBuilder ) { - $this->fileFactory = $fileFactory; - $this->archiveManager = $archiveManager; - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; parent::__construct($context, $filter, $collectionFactory); } - protected function massAction(AbstractCollection $collection) + protected function massAction(AbstractCollection $collection): ResultInterface|ResponseInterface { $archiveFileName = 'customers_privacy_data.zip'; - try { - foreach ($collection->getAllIds() as $customerId) { - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $customerId, - ArgumentReader::ENTITY_TYPE => 'customer' - ]); - $result = $this->action->execute($this->actionContextBuilder->create())->getResult(); - /** @var ExportEntityInterface $exportEntity */ - $exportEntity = $result[ExportArgumentReader::EXPORT_ENTITY]; - $this->archiveManager->addToArchive($exportEntity->getFilePath(), $archiveFileName, false); + $this->searchCriteriaBuilder->addFilter(ExportEntityInterface::ENTITY_ID, $collection->getAllIds(), 'in'); + $this->searchCriteriaBuilder->addFilter(ExportEntityInterface::ENTITY_TYPE, 'customer'); + $exportEntityList = $this->exportEntityRepository->getList($this->searchCriteriaBuilder->create()); + + foreach ($exportEntityList->getItems() as $exportEntity) { + try { + $this->archiveManager->addToArchive( + $this->exportEntityManagement->export($exportEntity)->getFilePath(), + $archiveFileName, + false + ); + } catch (LocalizedException $e) { + $this->messageManager->addErrorMessage( + new Phrase('Customer with id "%1": %2', [$exportEntity->getEntityId(), $e->getMessage()]) + ); } + } + try { return $this->fileFactory->create( $archiveFileName, [ @@ -82,10 +76,6 @@ protected function massAction(AbstractCollection $collection) ], DirectoryList::TMP ); - } catch (LocalizedException $e) { - $this->messageManager->addErrorMessage( - new Phrase('Customer with id "%1": %2', [$customerId ?? 'N/A', $e->getMessage()]) - ); } catch (Exception $e) { $this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.')); } diff --git a/Controller/Guest/Download.php b/Controller/Guest/Download.php index ec1659ae..ba19a7ab 100755 --- a/Controller/Guest/Download.php +++ b/Controller/Guest/Download.php @@ -12,8 +12,10 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Message\ManagerInterface; @@ -51,10 +53,10 @@ public function __construct( protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isExportEnabled(); + return $this->config->isExportEnabled(); } - protected function executeAction() + protected function executeAction(): ResultInterface|ResponseInterface { try { /** @var OrderInterface $order */ @@ -64,11 +66,11 @@ protected function executeAction() 'customer_privacy_data_' . $order->getCustomerLastname() . '.zip', [ 'type' => 'filename', - 'value' => $this->exportRepository->getByEntity((int) $order->getEntityId(), 'order')->getFilePath(), + 'value' => $this->exportRepository->getByEntity((int)$order->getEntityId(), 'order')->getFilePath(), ], DirectoryList::TMP ); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { $this->messageManager->addErrorMessage( new Phrase('The document does not exists and may have expired. Please renew your demand.') ); diff --git a/Controller/Guest/Erase.php b/Controller/Guest/Erase.php index 11823841..56c9ea57 100644 --- a/Controller/Guest/Erase.php +++ b/Controller/Guest/Erase.php @@ -17,18 +17,12 @@ use Magento\Framework\Phrase; use Magento\Framework\Registry; use Magento\Sales\Controller\AbstractController\OrderLoaderInterface; -use Opengento\Gdpr\Api\ActionInterface; +use Opengento\Gdpr\Api\EraseEntityManagementInterface; use Opengento\Gdpr\Controller\AbstractGuest; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; use Opengento\Gdpr\Model\Config; class Erase extends AbstractGuest implements HttpPostActionInterface { - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, @@ -36,17 +30,14 @@ public function __construct( Config $config, OrderLoaderInterface $orderLoader, Registry $registry, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private EraseEntityManagementInterface $eraseEntityManagement ) { - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; parent::__construct($request, $resultFactory, $messageManager, $config, $orderLoader, $registry); } protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isErasureEnabled(); + return $this->config->isErasureEnabled(); } protected function executeAction(): Redirect @@ -55,13 +46,8 @@ protected function executeAction(): Redirect $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setRefererOrBaseUrl(); - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $this->currentOrder()->getEntityId(), - ArgumentReader::ENTITY_TYPE => 'order' - ]); - try { - $this->action->execute($this->actionContextBuilder->create()); + $this->eraseEntityManagement->create((int)$this->currentOrder()->getEntityId(), 'order'); $this->messageManager->addWarningMessage(new Phrase('Your personal data is being removed soon.')); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); diff --git a/Controller/Guest/Export.php b/Controller/Guest/Export.php index a65d877d..6cbc80ff 100755 --- a/Controller/Guest/Export.php +++ b/Controller/Guest/Export.php @@ -18,18 +18,12 @@ use Magento\Framework\Phrase; use Magento\Framework\Registry; use Magento\Sales\Controller\AbstractController\OrderLoaderInterface; -use Opengento\Gdpr\Api\ActionInterface; +use Opengento\Gdpr\Api\ExportEntityManagementInterface; use Opengento\Gdpr\Controller\AbstractGuest; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; use Opengento\Gdpr\Model\Config; class Export extends AbstractGuest implements HttpGetActionInterface { - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, @@ -37,17 +31,14 @@ public function __construct( Config $config, OrderLoaderInterface $orderLoader, Registry $registry, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private ExportEntityManagementInterface $exportEntityManagement ) { - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; parent::__construct($request, $resultFactory, $messageManager, $config, $orderLoader, $registry); } protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isExportEnabled(); + return $this->config->isExportEnabled(); } protected function executeAction(): Redirect @@ -56,15 +47,10 @@ protected function executeAction(): Redirect $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setRefererOrBaseUrl(); - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $this->currentOrder()->getEntityId(), - ArgumentReader::ENTITY_TYPE => 'order' - ]); - try { - $this->action->execute($this->actionContextBuilder->create()); + $this->exportEntityManagement->create((int)$this->currentOrder()->getEntityId(), 'order'); $this->messageManager->addSuccessMessage(new Phrase('You will be notified when the export is ready.')); - } catch (AlreadyExistsException $e) { + } catch (AlreadyExistsException) { $this->messageManager->addNoticeMessage(new Phrase('A document is already available in your order page.')); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); diff --git a/Controller/Guest/UndoErase.php b/Controller/Guest/UndoErase.php index 23cbb390..b8dd31d5 100644 --- a/Controller/Guest/UndoErase.php +++ b/Controller/Guest/UndoErase.php @@ -17,18 +17,12 @@ use Magento\Framework\Phrase; use Magento\Framework\Registry; use Magento\Sales\Controller\AbstractController\OrderLoaderInterface; -use Opengento\Gdpr\Api\ActionInterface; +use Opengento\Gdpr\Api\EraseEntityManagementInterface; use Opengento\Gdpr\Controller\AbstractGuest; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; use Opengento\Gdpr\Model\Config; class UndoErase extends AbstractGuest implements HttpPostActionInterface { - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, @@ -36,17 +30,14 @@ public function __construct( Config $config, OrderLoaderInterface $orderLoader, Registry $registry, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private EraseEntityManagementInterface $eraseEntityManagement ) { - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; parent::__construct($request, $resultFactory, $messageManager, $config, $orderLoader, $registry); } protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isErasureEnabled(); + return $this->config->isErasureEnabled(); } protected function executeAction(): Redirect @@ -55,13 +46,8 @@ protected function executeAction(): Redirect $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setRefererOrBaseUrl(); - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $this->currentOrder()->getEntityId(), - ArgumentReader::ENTITY_TYPE => 'order' - ]); - try { - $this->action->execute($this->actionContextBuilder->create()); + $this->eraseEntityManagement->cancel((int)$this->currentOrder()->getEntityId(), 'order'); $this->messageManager->addWarningMessage(new Phrase('You canceled your personal data deletion.')); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); diff --git a/Controller/Privacy/Download.php b/Controller/Privacy/Download.php index 93bfde27..0532163a 100755 --- a/Controller/Privacy/Download.php +++ b/Controller/Privacy/Download.php @@ -8,55 +8,47 @@ namespace Opengento\Gdpr\Controller\Privacy; use Exception; +use Magento\Customer\Controller\AccountInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\Response\Http; use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Phrase; use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; -use Opengento\Gdpr\Controller\AbstractPrivacy; +use Opengento\Gdpr\Controller\AbstractAction; use Opengento\Gdpr\Model\Config; -class Download extends AbstractPrivacy implements HttpGetActionInterface +class Download extends AbstractAction implements HttpGetActionInterface, AccountInterface { - /** - * @var FileFactory - */ - private FileFactory $fileFactory; - - private ExportEntityRepositoryInterface $exportRepository; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, ManagerInterface $messageManager, Config $config, - Http $response, - Session $customerSession, - FileFactory $fileFactory, - ExportEntityRepositoryInterface $exportRepository + private Session $customerSession, + private FileFactory $fileFactory, + private ExportEntityRepositoryInterface $exportRepository ) { - $this->fileFactory = $fileFactory; - $this->exportRepository = $exportRepository; - parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response); + parent::__construct($request, $resultFactory, $messageManager, $config); } protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isExportEnabled(); + return $this->config->isExportEnabled(); } - protected function executeAction() + protected function executeAction(): ResultInterface|ResponseInterface { try { - $customerId = (int) $this->customerSession->getCustomerId(); + $customerId = (int)$this->customerSession->getCustomerId(); return $this->fileFactory->create( 'customer_privacy_data_' . $customerId . '.zip', @@ -66,7 +58,7 @@ protected function executeAction() ], DirectoryList::TMP ); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { $this->messageManager->addErrorMessage( new Phrase('The document does not exists and may have expired. Please renew your demand.') ); diff --git a/Controller/Privacy/Erase.php b/Controller/Privacy/Erase.php index c0cdeea0..a369d552 100755 --- a/Controller/Privacy/Erase.php +++ b/Controller/Privacy/Erase.php @@ -7,43 +7,40 @@ namespace Opengento\Gdpr\Controller\Privacy; +use Magento\Customer\Controller\AccountInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\Response\Http; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Phrase; +use Magento\Framework\View\Result\Page; use Opengento\Gdpr\Api\EraseEntityCheckerInterface; -use Opengento\Gdpr\Controller\AbstractPrivacy; +use Opengento\Gdpr\Controller\AbstractAction; use Opengento\Gdpr\Model\Config; -class Erase extends AbstractPrivacy implements HttpGetActionInterface +class Erase extends AbstractAction implements HttpGetActionInterface, AccountInterface { - private EraseEntityCheckerInterface $eraseCustomerChecker; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, ManagerInterface $messageManager, Config $config, - Session $customerSession, - Http $response, - EraseEntityCheckerInterface $eraseCustomerChecker + private Session $customerSession, + private EraseEntityCheckerInterface $eraseCustomerChecker ) { - $this->eraseCustomerChecker = $eraseCustomerChecker; - parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response); + parent::__construct($request, $resultFactory, $messageManager, $config); } protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isErasureEnabled(); + return $this->config->isErasureEnabled(); } - protected function executeAction() + protected function executeAction(): Page|Redirect { - if ($this->eraseCustomerChecker->exists((int) $this->customerSession->getCustomerId(), 'customer')) { + if ($this->eraseCustomerChecker->exists((int)$this->customerSession->getCustomerId(), 'customer')) { $this->messageManager->addErrorMessage(new Phrase('Your account is already being removed.')); /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/Controller/Privacy/ErasePost.php b/Controller/Privacy/ErasePost.php index 00e7114e..be582a15 100755 --- a/Controller/Privacy/ErasePost.php +++ b/Controller/Privacy/ErasePost.php @@ -8,11 +8,11 @@ namespace Opengento\Gdpr\Controller\Privacy; use Exception; +use Magento\Customer\Controller\AccountInterface; use Magento\Customer\Model\AuthenticationInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\Response\Http; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\InvalidEmailOrPasswordException; @@ -21,43 +21,27 @@ use Magento\Framework\Exception\State\UserLockedException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Phrase; -use Opengento\Gdpr\Api\ActionInterface; -use Opengento\Gdpr\Controller\AbstractPrivacy; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; +use Opengento\Gdpr\Api\EraseEntityManagementInterface; +use Opengento\Gdpr\Controller\AbstractAction; use Opengento\Gdpr\Model\Config; -class ErasePost extends AbstractPrivacy implements HttpPostActionInterface +class ErasePost extends AbstractAction implements HttpPostActionInterface, AccountInterface { - /** - * @var AuthenticationInterface - */ - private AuthenticationInterface $authentication; - - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, ManagerInterface $messageManager, Config $config, - Session $customerSession, - Http $response, - AuthenticationInterface $authentication, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private Session $customerSession, + private AuthenticationInterface $authentication, + private EraseEntityManagementInterface $eraseEntityManagement ) { - $this->authentication = $authentication; - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; - parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response); + parent::__construct($request, $resultFactory, $messageManager, $config); } protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isErasureEnabled(); + return $this->config->isErasureEnabled(); } protected function executeAction(): Redirect @@ -66,20 +50,16 @@ protected function executeAction(): Redirect $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setPath('customer/privacy/settings'); - $customerId = (int) $this->customerSession->getCustomerId(); - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => $customerId, - ArgumentReader::ENTITY_TYPE => 'customer' - ]); + $customerId = (int)$this->customerSession->getCustomerId(); try { - $this->authentication->authenticate($customerId, $this->request->getParam('password')); - $this->action->execute($this->actionContextBuilder->create()); + $this->authentication->authenticate($customerId, (string)$this->request->getParam('password')); + $this->eraseEntityManagement->create($customerId, 'customer'); $this->messageManager->addWarningMessage(new Phrase('Your personal data is being removed soon.')); } catch (InvalidEmailOrPasswordException $e) { $this->messageManager->addErrorMessage($e->getMessage()); $resultRedirect->setRefererOrBaseUrl(); - } catch (UserLockedException $e) { + } catch (UserLockedException) { $this->customerSession->logout(); try { $this->customerSession->start(); diff --git a/Controller/Privacy/Export.php b/Controller/Privacy/Export.php index 0cb591cd..f7233bbd 100755 --- a/Controller/Privacy/Export.php +++ b/Controller/Privacy/Export.php @@ -8,46 +8,36 @@ namespace Opengento\Gdpr\Controller\Privacy; use Exception; +use Magento\Customer\Controller\AccountInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\Response\Http; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\AlreadyExistsException; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Phrase; -use Opengento\Gdpr\Api\ActionInterface; -use Opengento\Gdpr\Controller\AbstractPrivacy; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; +use Opengento\Gdpr\Api\ExportEntityManagementInterface; +use Opengento\Gdpr\Controller\AbstractAction; use Opengento\Gdpr\Model\Config; -class Export extends AbstractPrivacy implements HttpGetActionInterface +class Export extends AbstractAction implements HttpGetActionInterface, AccountInterface { - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, ManagerInterface $messageManager, Config $config, - Session $customerSession, - Http $response, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private Session $customerSession, + private ExportEntityManagementInterface $exportEntityManagement ) { - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; - parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response); + parent::__construct($request, $resultFactory, $messageManager, $config); } protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isExportEnabled(); + return $this->config->isExportEnabled(); } protected function executeAction(): Redirect @@ -56,15 +46,10 @@ protected function executeAction(): Redirect $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setRefererOrBaseUrl(); - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $this->customerSession->getCustomerId(), - ArgumentReader::ENTITY_TYPE => 'customer' - ]); - try { - $this->action->execute($this->actionContextBuilder->create()); + $this->exportEntityManagement->create((int)$this->customerSession->getCustomerId(), 'customer'); $this->messageManager->addSuccessMessage(new Phrase('You will be notified when the export is ready.')); - } catch (AlreadyExistsException $e) { + } catch (AlreadyExistsException) { $this->messageManager->addNoticeMessage(new Phrase('A document is already available in your account.')); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); diff --git a/Controller/Privacy/Settings.php b/Controller/Privacy/Settings.php index 8938c30c..fa9c518a 100755 --- a/Controller/Privacy/Settings.php +++ b/Controller/Privacy/Settings.php @@ -7,13 +7,15 @@ namespace Opengento\Gdpr\Controller\Privacy; +use Magento\Customer\Controller\AccountInterface; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\Controller\ResultFactory; -use Opengento\Gdpr\Controller\AbstractPrivacy; +use Magento\Framework\View\Result\Page; +use Opengento\Gdpr\Controller\AbstractAction; -class Settings extends AbstractPrivacy implements HttpGetActionInterface +class Settings extends AbstractAction implements HttpGetActionInterface, AccountInterface { - protected function executeAction() + protected function executeAction(): Page { return $this->resultFactory->create(ResultFactory::TYPE_PAGE); } diff --git a/Controller/Privacy/UndoErase.php b/Controller/Privacy/UndoErase.php index ba680c1c..c8957597 100755 --- a/Controller/Privacy/UndoErase.php +++ b/Controller/Privacy/UndoErase.php @@ -8,45 +8,35 @@ namespace Opengento\Gdpr\Controller\Privacy; use Exception; +use Magento\Customer\Controller\AccountInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\Response\Http; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Phrase; -use Opengento\Gdpr\Api\ActionInterface; -use Opengento\Gdpr\Controller\AbstractPrivacy; -use Opengento\Gdpr\Model\Action\ArgumentReader; -use Opengento\Gdpr\Model\Action\ContextBuilder; +use Opengento\Gdpr\Api\EraseEntityManagementInterface; +use Opengento\Gdpr\Controller\AbstractAction; use Opengento\Gdpr\Model\Config; -class UndoErase extends AbstractPrivacy implements HttpPostActionInterface +class UndoErase extends AbstractAction implements HttpPostActionInterface, AccountInterface { - private ActionInterface $action; - - private ContextBuilder $actionContextBuilder; - public function __construct( RequestInterface $request, ResultFactory $resultFactory, ManagerInterface $messageManager, Config $config, - Session $customerSession, - Http $response, - ActionInterface $action, - ContextBuilder $actionContextBuilder + private Session $customerSession, + private EraseEntityManagementInterface $eraseEntityManagement ) { - $this->action = $action; - $this->actionContextBuilder = $actionContextBuilder; - parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response); + parent::__construct($request, $resultFactory, $messageManager, $config); } protected function isAllowed(): bool { - return parent::isAllowed() && $this->config->isErasureEnabled(); + return $this->config->isErasureEnabled(); } protected function executeAction(): Redirect @@ -55,13 +45,8 @@ protected function executeAction(): Redirect $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setPath('customer/privacy/settings'); - $this->actionContextBuilder->setParameters([ - ArgumentReader::ENTITY_ID => (int) $this->customerSession->getCustomerId(), - ArgumentReader::ENTITY_TYPE => 'customer' - ]); - try { - $this->action->execute($this->actionContextBuilder->create()); + $this->eraseEntityManagement->cancel((int)$this->customerSession->getCustomerId(), 'customer'); $this->messageManager->addSuccessMessage(new Phrase('You canceled your account deletion.')); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); diff --git a/Cron/EraseEntity.php b/Cron/EraseEntity.php index 704d01bb..3329f0d6 100755 --- a/Cron/EraseEntity.php +++ b/Cron/EraseEntity.php @@ -17,69 +17,45 @@ use Opengento\Gdpr\Api\Data\EraseEntitySearchResultsInterface; use Opengento\Gdpr\Api\EraseEntityManagementInterface; use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; -use Opengento\Gdpr\Model\Config; use Psr\Log\LoggerInterface; /** * Process erase of all scheduled entities */ -final class EraseEntity +class EraseEntity { - private LoggerInterface $logger; - - private Config $config; - - private Registry $registry; - - private EraseEntityManagementInterface $eraseManagement; - - private EraseEntityRepositoryInterface $eraseRepository; - - private SearchCriteriaBuilder $criteriaBuilder; - - /** - * @var DateTime - */ - private DateTime $dateTime; - public function __construct( - LoggerInterface $logger, - Config $config, - Registry $registry, - EraseEntityManagementInterface $eraseManagement, - EraseEntityRepositoryInterface $eraseRepository, - SearchCriteriaBuilder $criteriaBuilder, - DateTime $dateTime - ) { - $this->logger = $logger; - $this->config = $config; - $this->registry = $registry; - $this->eraseManagement = $eraseManagement; - $this->eraseRepository = $eraseRepository; - $this->criteriaBuilder = $criteriaBuilder; - $this->dateTime = $dateTime; - } + private LoggerInterface $logger, + private Registry $registry, + private EraseEntityManagementInterface $eraseManagement, + private EraseEntityRepositoryInterface $eraseRepository, + private SearchCriteriaBuilder $criteriaBuilder, + private DateTime $dateTime + ) {} public function execute(): void { - if ($this->config->isModuleEnabled() && $this->config->isErasureEnabled()) { - $oldValue = $this->registry->registry('isSecureArea'); - $this->registry->register('isSecureArea', true, true); + $oldValue = $this->registry->registry('isSecureArea'); + $this->registry->register('isSecureArea', true, true); + try { foreach ($this->retrieveEraseEntityList()->getItems() as $eraseEntity) { try { $this->eraseManagement->process($eraseEntity); } catch (Exception $e) { - $this->logger->error($e->getMessage(), $e->getTrace()); + $this->logger->error($e->getMessage(), ['exception' => $e]); } } - - $this->registry->register('isSecureArea', $oldValue, true); + } catch (LocalizedException $e) { + $this->logger->error($e->getLogMessage(), ['exception' => $e]); } + + $this->registry->register('isSecureArea', $oldValue, true); } /** * @return EraseEntitySearchResultsInterface + * @throws LocalizedException */ private function retrieveEraseEntityList(): SearchResultsInterface { @@ -99,12 +75,6 @@ private function retrieveEraseEntityList(): SearchResultsInterface 'in' ); - try { - $eraseCustomerList = $this->eraseRepository->getList($this->criteriaBuilder->create()); - } catch (LocalizedException $e) { - $eraseCustomerList = []; - } - - return $eraseCustomerList; + return $this->eraseRepository->getList($this->criteriaBuilder->create()); } } diff --git a/Cron/EraseEntityScheduler.php b/Cron/EraseEntityScheduler.php index 59bcdfc4..8af42ab8 100644 --- a/Cron/EraseEntityScheduler.php +++ b/Cron/EraseEntityScheduler.php @@ -7,13 +7,8 @@ namespace Opengento\Gdpr\Cron; -use DateTime; use Exception; -use Magento\Framework\Api\FilterBuilder; -use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Framework\Exception\CouldNotSaveException; -use Magento\Framework\Exception\LocalizedException; -use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; use Opengento\Gdpr\Model\Config; use Opengento\Gdpr\Model\Entity\EntityTypeList; use Opengento\Gdpr\Model\Erase\EraseEntityScheduler as EraseEntitySchedulerService; @@ -22,67 +17,27 @@ /** * Schedule entities to erase */ -final class EraseEntityScheduler +class EraseEntityScheduler { - private const CONFIG_PATH_ERASURE_MAX_AGE = 'gdpr/erasure/entity_max_age'; - - private LoggerInterface $logger; - - private ScopeConfigInterface $scopeConfig; - - private Config $config; - - /** - * @var EraseEntitySchedulerService - */ - private EraseEntitySchedulerService $eraseEntityScheduler; - - private FilterBuilder $filterBuilder; - - private EntityTypeList $entityTypeList; public function __construct( - LoggerInterface $logger, - ScopeConfigInterface $scopeConfig, - Config $config, - EraseEntitySchedulerService $eraseEntityScheduler, - FilterBuilder $filterBuilder, - EntityTypeList $entityTypeList - ) { - $this->logger = $logger; - $this->scopeConfig = $scopeConfig; - $this->config = $config; - $this->eraseEntityScheduler = $eraseEntityScheduler; - $this->filterBuilder = $filterBuilder; - $this->entityTypeList = $entityTypeList; - } + private LoggerInterface $logger, + private Config $config, + private EraseEntitySchedulerService $eraseEntityScheduler, + private EntityTypeList $entityTypeList, + private StoreManagerInterface $storeManager + ) {} public function execute(): void { - if ($this->config->isModuleEnabled() && $this->config->isErasureEnabled()) { - try { - $this->scheduleEntitiesErasure(); - } catch (Exception $e) { - $this->logger->error($e->getMessage(), $e->getTrace()); + foreach ($this->storeManager->getWebsites() as $website) { + if ($this->config->isErasureEnabled($website->getId())) { + try { + $this->eraseEntityScheduler->schedule($this->entityTypeList->getEntityTypes(), $website); + } catch (Exception $e) { + $this->logger->error($e->getMessage(), ['exception' => $e]); + } } } } - - /** - * @throws CouldNotSaveException - * @throws LocalizedException - * @throws Exception - */ - private function scheduleEntitiesErasure(): void - { - $this->filterBuilder->setField('created_at'); - $this->filterBuilder->setValue(new DateTime('-' . $this->resolveErasureMaxAge() . 'days')); - $this->filterBuilder->setConditionType('lteq'); - $this->eraseEntityScheduler->schedule($this->entityTypeList->getEntityTypes(), $this->filterBuilder->create()); - } - - private function resolveErasureMaxAge(): int - { - return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_MAX_AGE, ScopeInterface::SCOPE_STORE); - } } diff --git a/Cron/ExportEntity.php b/Cron/ExportEntity.php index 5d6978e2..94ea42d4 100644 --- a/Cron/ExportEntity.php +++ b/Cron/ExportEntity.php @@ -13,58 +13,38 @@ use Opengento\Gdpr\Api\Data\ExportEntityInterface; use Opengento\Gdpr\Api\ExportEntityManagementInterface; use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; -use Opengento\Gdpr\Model\Config; use Psr\Log\LoggerInterface; /** * Export all scheduled entities */ -final class ExportEntity +class ExportEntity { - private LoggerInterface $logger; - - private Config $config; - - private ExportEntityRepositoryInterface $exportRepository; - - private ExportEntityManagementInterface $exportManagement; - - private SearchCriteriaBuilder $criteriaBuilder; - public function __construct( - LoggerInterface $logger, - Config $config, - ExportEntityRepositoryInterface $exportRepository, - ExportEntityManagementInterface $exportManagement, - SearchCriteriaBuilder $criteriaBuilder - ) { - $this->logger = $logger; - $this->config = $config; - $this->exportRepository = $exportRepository; - $this->exportManagement = $exportManagement; - $this->criteriaBuilder = $criteriaBuilder; - } + private LoggerInterface $logger, + private ExportEntityRepositoryInterface $exportRepository, + private ExportEntityManagementInterface $exportManagement, + private SearchCriteriaBuilder $criteriaBuilder + ) {} public function execute(): void { - if ($this->config->isModuleEnabled() && $this->config->isExportEnabled()) { - $this->criteriaBuilder->addFilter(ExportEntityInterface::EXPORTED_AT, true, 'null'); - $this->criteriaBuilder->addFilter(ExportEntityInterface::FILE_PATH, true, 'null'); - - try { - $exportList = $this->exportRepository->getList($this->criteriaBuilder->create()); - - foreach ($exportList->getItems() as $exportEntity) { - try { - $this->exportManagement->export($exportEntity); - } catch (NoSuchEntityException $e) { - $this->logger->error($e->getLogMessage(), $e->getTrace()); - $this->exportRepository->delete($exportEntity); - } + $this->criteriaBuilder->addFilter(ExportEntityInterface::EXPORTED_AT, true, 'null'); + $this->criteriaBuilder->addFilter(ExportEntityInterface::FILE_PATH, true, 'null'); + + try { + $exportList = $this->exportRepository->getList($this->criteriaBuilder->create()); + + foreach ($exportList->getItems() as $exportEntity) { + try { + $this->exportManagement->export($exportEntity); + } catch (NoSuchEntityException $e) { + $this->logger->error($e->getLogMessage(), ['exception' => $e]); + $this->exportRepository->delete($exportEntity); } - } catch (Exception $e) { - $this->logger->critical($e->getMessage(), $e->getTrace()); } + } catch (Exception $e) { + $this->logger->critical($e->getMessage(), ['exception' => $e]); } } } diff --git a/Cron/ExportEntityExpired.php b/Cron/ExportEntityExpired.php index 3961bf61..c451a73f 100644 --- a/Cron/ExportEntityExpired.php +++ b/Cron/ExportEntityExpired.php @@ -12,52 +12,35 @@ use Magento\Framework\Stdlib\DateTime; use Opengento\Gdpr\Api\Data\ExportEntityInterface; use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; -use Opengento\Gdpr\Model\Config; use Psr\Log\LoggerInterface; /** * Delete all expired export entities */ -final class ExportEntityExpired +class ExportEntityExpired { - private LoggerInterface $logger; - - private Config $config; - - private ExportEntityRepositoryInterface $exportRepository; - - private SearchCriteriaBuilder $criteriaBuilder; - public function __construct( - LoggerInterface $logger, - Config $config, - ExportEntityRepositoryInterface $exportRepository, - SearchCriteriaBuilder $criteriaBuilder - ) { - $this->logger = $logger; - $this->config = $config; - $this->exportRepository = $exportRepository; - $this->criteriaBuilder = $criteriaBuilder; - } + private LoggerInterface $logger, + private ExportEntityRepositoryInterface $exportRepository, + private SearchCriteriaBuilder $criteriaBuilder + ) {} public function execute(): void { - if ($this->config->isModuleEnabled() && $this->config->isExportEnabled()) { - $this->criteriaBuilder->addFilter( - ExportEntityInterface::EXPIRED_AT, - (new \DateTime())->format(DateTime::DATE_PHP_FORMAT), - 'lteq' - ); + $this->criteriaBuilder->addFilter( + ExportEntityInterface::EXPIRED_AT, + (new \DateTime())->format(DateTime::DATE_PHP_FORMAT), + 'lteq' + ); - try { - $exportList = $this->exportRepository->getList($this->criteriaBuilder->create()); + try { + $exportList = $this->exportRepository->getList($this->criteriaBuilder->create()); - foreach ($exportList->getItems() as $exportEntity) { - $this->exportRepository->delete($exportEntity); - } - } catch (Exception $e) { - $this->logger->error($e->getMessage(), $e->getTrace()); + foreach ($exportList->getItems() as $exportEntity) { + $this->exportRepository->delete($exportEntity); } + } catch (Exception $e) { + $this->logger->error($e->getMessage(), ['exception' => $e]); } } } diff --git a/Model/Action/AbstractAction.php b/Model/Action/AbstractAction.php deleted file mode 100644 index eea2a3d2..00000000 --- a/Model/Action/AbstractAction.php +++ /dev/null @@ -1,41 +0,0 @@ -resultBuilder = $resultBuilder; - } - - protected function createActionResult( - array $result = [], - string $message = self::DEFAULT_MESSAGE - ): ActionResultInterface { - $this->resultBuilder->setState(ActionEntityInterface::STATE_SUCCEEDED); - $this->resultBuilder->setPerformedAt(new DateTime()); - $this->resultBuilder->setMessage($message); - $this->resultBuilder->setResult($result); - - return $this->resultBuilder->create(); - } -} diff --git a/Model/Action/ActionComposite.php b/Model/Action/ActionComposite.php deleted file mode 100644 index 017b2773..00000000 --- a/Model/Action/ActionComposite.php +++ /dev/null @@ -1,112 +0,0 @@ -type = $type; - $this->actions = $actions; - $this->contextBuilder = $contextBuilder; - $this->actionEntityBuilder = $actionEntityBuilder; - $this->resultBuilder = $resultBuilder; - $this->actionRepository = $actionRepository; - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - $this->actionEntityBuilder->setType($this->type); - $this->actionEntityBuilder->setParameters($actionContext->getParameters()); - $this->actionEntityBuilder->setPerformedFrom($actionContext->getPerformedFrom()); - $this->actionEntityBuilder->setPerformedBy($actionContext->getPerformedBy()); - $this->actionEntityBuilder->setPerformedAt(new DateTime()); - - try { - $this->actionEntityBuilder->setState(ActionEntityInterface::STATE_SUCCEEDED); - $this->actionEntityBuilder->setResult($this->process($actionContext)); - } catch (LocalizedException $e) { - $this->actionEntityBuilder->setState(ActionEntityInterface::STATE_FAILED); - $this->actionEntityBuilder->setMessage($e->getMessage()); - } - - $result = $this->result($this->actionRepository->save($this->actionEntityBuilder->create())); - - if (isset($e)) { - throw $e; - } - - return $result; - } - - /** - * @param ActionContextInterface $actionContext - * @return array - * @throws LocalizedException - */ - private function process(ActionContextInterface $actionContext): array - { - foreach ($this->actions as $action) { - $this->contextBuilder->setPerformedFrom($actionContext->getPerformedFrom()); - $this->contextBuilder->setPerformedBy($actionContext->getPerformedBy()); - $this->contextBuilder->setParameters( - array_merge($actionContext->getParameters(), $action->execute($actionContext)->getResult()) - ); - $actionContext = $this->contextBuilder->create(); - } - - return $actionContext->getParameters(); - } - - private function result(ActionEntityInterface $actionEntity): ActionResultInterface - { - $this->resultBuilder->setPerformedAt(new DateTime()); - $this->resultBuilder->setState($actionEntity->getState()); - $this->resultBuilder->setMessage($actionEntity->getMessage()); - $this->resultBuilder->setResult($actionEntity->getResult()); - - return $this->resultBuilder->create(); - } -} diff --git a/Model/Action/ActionFactory.php b/Model/Action/ActionFactory.php deleted file mode 100644 index 90fdb33c..00000000 --- a/Model/Action/ActionFactory.php +++ /dev/null @@ -1,53 +0,0 @@ -actions = $actions; - $this->objectManager = $objectManager; - $this->instances = []; - } - - public function get(string $type): ActionInterface - { - if (!isset($this->instances[$type])) { - if (!isset($this->actions[$type])) { - throw new InvalidArgumentException(sprintf('Unknown action for type "%s".', $type)); - } - - $this->instances[$type] = $this->objectManager->create($this->actions[$type], ['type' => $type]); - } - - return $this->instances[$type]; - } -} diff --git a/Model/Action/ArgumentReader.php b/Model/Action/ArgumentReader.php deleted file mode 100644 index 653a5dbc..00000000 --- a/Model/Action/ArgumentReader.php +++ /dev/null @@ -1,26 +0,0 @@ -getParameters()[self::ENTITY_TYPE] ?? null; - } - - public static function getEntityId(ActionContextInterface $actionContext): ?int - { - return $actionContext->getParameters()[self::ENTITY_ID] ?? null; - } -} diff --git a/Model/Action/Context.php b/Model/Action/Context.php deleted file mode 100644 index 76b4dd83..00000000 --- a/Model/Action/Context.php +++ /dev/null @@ -1,44 +0,0 @@ -performedFrom = $performedFrom; - $this->performedBy = $performedBy; - $this->parameters = $parameters; - } - - public function getPerformedFrom(): string - { - return $this->performedFrom; - } - - public function getPerformedBy(): string - { - return $this->performedBy; - } - - public function getParameters(): array - { - return $this->parameters; - } -} diff --git a/Model/Action/ContextBuilder.php b/Model/Action/ContextBuilder.php deleted file mode 100644 index fd8110f9..00000000 --- a/Model/Action/ContextBuilder.php +++ /dev/null @@ -1,84 +0,0 @@ -actionContextFactory = $actionContextFactory; - $this->stateArea = $stateArea; - $this->performedBy = $performedBy; - $this->data = []; - } - - public function setPerformedFrom(string $performedFrom): ContextBuilder - { - $this->data['performedFrom'] = $performedFrom; - - return $this; - } - - public function setPerformedBy(string $performedBy): ContextBuilder - { - $this->data['performedBy'] = $performedBy; - - return $this; - } - - public function setParameters(array $parameters): ContextBuilder - { - $this->data['parameters'] = $parameters; - - return $this; - } - - /** - * @throws LocalizedException - */ - public function create(): ActionContextInterface - { - if (!isset($this->data['performedFrom'])) { - $this->data['performedFrom'] = $this->stateArea->getAreaCode(); - } - if (!isset($this->data['performedBy'])) { - $this->data['performedBy'] = $this->performedBy->get(); - } - - /** @var ActionContextInterface $context */ - $context = $this->actionContextFactory->create($this->data); - $this->data = []; - - return $context; - } -} diff --git a/Model/Action/Erase/ArgumentReader.php b/Model/Action/Erase/ArgumentReader.php deleted file mode 100644 index 1723d50c..00000000 --- a/Model/Action/Erase/ArgumentReader.php +++ /dev/null @@ -1,21 +0,0 @@ -getParameters()[self::ERASE_ENTITY] ?? null; - } -} diff --git a/Model/Action/Erase/CancelAction.php b/Model/Action/Erase/CancelAction.php deleted file mode 100644 index 6a64ccd5..00000000 --- a/Model/Action/Erase/CancelAction.php +++ /dev/null @@ -1,85 +0,0 @@ -eraseRepository = $eraseRepository; - $this->eraseManagement = $eraseManagement; - parent::__construct($resultBuilder); - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - $arguments = $this->getArguments($actionContext); - - return $this->createActionResult( - [ - ArgumentReader::ERASE_ENTITY => $this->resolveEntity(...$arguments), - 'canceled' => $this->eraseManagement->cancel(...$arguments), - ] - ); - } - - /** - * @param int $entityId - * @param string $entityType - * @return EraseEntityInterface - * @throws NoSuchEntityException - */ - private function resolveEntity(int $entityId, string $entityType): EraseEntityInterface - { - return clone $this->eraseRepository->getByEntity($entityId, $entityType); - } - - private function getArguments(ActionContextInterface $actionContext): array - { - $entityId = ActionArgumentReader::getEntityId($actionContext); - $entityType = ActionArgumentReader::getEntityType($actionContext); - $errors = []; - - if ($entityId === null) { - $errors[] = InputException::requiredField('entity_id'); - } - if ($entityType === null) { - $errors[] = InputException::requiredField('entity_type'); - } - if (!empty($errors)) { - throw array_reduce( - $errors, - static function (InputException $aggregated, InputException $input): InputException { - return $aggregated->addException($input); - }, - new InputException() - ); - } - - return [$entityId, $entityType]; - } -} diff --git a/Model/Action/Erase/CreateAction.php b/Model/Action/Erase/CreateAction.php deleted file mode 100644 index bb31a652..00000000 --- a/Model/Action/Erase/CreateAction.php +++ /dev/null @@ -1,66 +0,0 @@ -eraseManagement = $eraseManagement; - parent::__construct($resultBuilder); - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - return $this->createActionResult( - [ - ArgumentReader::ERASE_ENTITY => $this->eraseManagement->create( - ...$this->getArguments($actionContext) - ), - ] - ); - } - - private function getArguments(ActionContextInterface $actionContext): array - { - $entityId = ActionArgumentReader::getEntityId($actionContext); - $entityType = ActionArgumentReader::getEntityType($actionContext); - $errors = []; - - if ($entityId === null) { - $errors[] = InputException::requiredField('entity_id'); - } - if ($entityType === null) { - $errors[] = InputException::requiredField('entity_type'); - } - if (!empty($errors)) { - throw array_reduce( - $errors, - static function (InputException $aggregated, InputException $input): InputException { - return $aggregated->addException($input); - }, - new InputException() - ); - } - - return [$entityId, $entityType]; - } -} diff --git a/Model/Action/Erase/ExecuteAction.php b/Model/Action/Erase/ExecuteAction.php deleted file mode 100644 index f499ebf7..00000000 --- a/Model/Action/Erase/ExecuteAction.php +++ /dev/null @@ -1,41 +0,0 @@ -eraseManagement = $eraseManagement; - parent::__construct($resultBuilder); - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - $eraseEntity = ArgumentReader::getEntity($actionContext); - - if ($eraseEntity === null) { - throw InputException::requiredField('entity'); - } - - return $this->createActionResult( - [ArgumentReader::ERASE_ENTITY => $this->eraseManagement->process($eraseEntity)] - ); - } -} diff --git a/Model/Action/Erase/NotifierActionBundle.php b/Model/Action/Erase/NotifierActionBundle.php deleted file mode 100644 index 34d081b2..00000000 --- a/Model/Action/Erase/NotifierActionBundle.php +++ /dev/null @@ -1,60 +0,0 @@ -notifiers = $notifiers; - $this->objectManager = $objectManager; - parent::__construct($resultBuilder); - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - $this->resolveNotifier($actionContext)->notify(ArgumentReader::getEntity($actionContext)); - - return $this->createActionResult(['is_notify' => true]); - } - - /** - * @param ActionContextInterface $actionContext - * @return NotifierInterface - * @throws InputException - */ - private function resolveNotifier(ActionContextInterface $actionContext): NotifierInterface - { - $entityType = ActionArgumentReader::getEntityType($actionContext); - - if (!isset($this->notifiers[$entityType])) { - throw InputException::invalidFieldValue('entity_type', $entityType); - } - - return $this->objectManager->get($this->notifiers[$entityType]); - } -} diff --git a/Model/Action/Export/ArgumentReader.php b/Model/Action/Export/ArgumentReader.php deleted file mode 100644 index 540c56b6..00000000 --- a/Model/Action/Export/ArgumentReader.php +++ /dev/null @@ -1,27 +0,0 @@ -getParameters()[self::EXPORT_ENTITY] ?? null; - } - - public static function getFileName(ActionContextInterface $actionContext): ?string - { - return $actionContext->getParameters()[self::EXPORT_FILE_NAME] ?? null; - } -} diff --git a/Model/Action/Export/CreateAction.php b/Model/Action/Export/CreateAction.php deleted file mode 100644 index 854c650a..00000000 --- a/Model/Action/Export/CreateAction.php +++ /dev/null @@ -1,66 +0,0 @@ -exporter = $exporter; - parent::__construct($resultBuilder); - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - return $this->createActionResult( - [ - ArgumentReader::EXPORT_ENTITY => $this->exporter->create( - ...$this->getArguments($actionContext) - ), - ] - ); - } - - private function getArguments(ActionContextInterface $actionContext): array - { - $entityId = ActionArgumentReader::getEntityId($actionContext); - $entityType = ActionArgumentReader::getEntityType($actionContext); - $errors = []; - - if ($entityId === null) { - $errors[] = InputException::requiredField('entity_id'); - } - if ($entityType === null) { - $errors[] = InputException::requiredField('entity_type'); - } - if (!empty($errors)) { - throw array_reduce( - $errors, - static function (InputException $aggregated, InputException $input): InputException { - return $aggregated->addException($input); - }, - new InputException() - ); - } - - return [$entityId, $entityType, ArgumentReader::getFileName($actionContext)]; - } -} diff --git a/Model/Action/Export/CreateOrExportAction.php b/Model/Action/Export/CreateOrExportAction.php deleted file mode 100644 index c5bb58c5..00000000 --- a/Model/Action/Export/CreateOrExportAction.php +++ /dev/null @@ -1,70 +0,0 @@ -exportEntityData = $exportEntityData; - parent::__construct($resultBuilder); - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - return $this->createActionResult( - [ - ExportArgumentReader::EXPORT_ENTITY => $this->exportEntityData->export( - ...$this->getArguments($actionContext) - ), - ] - ); - } - - private function getArguments(ActionContextInterface $actionContext): array - { - $entityId = ArgumentReader::getEntityId($actionContext); - $entityType = ArgumentReader::getEntityType($actionContext); - $errors = []; - - if ($entityId === null) { - $errors[] = InputException::requiredField('entity_id'); - } - if ($entityType === null) { - $errors[] = InputException::requiredField('entity_type'); - } - if (!empty($errors)) { - throw array_reduce( - $errors, - static function (InputException $aggregated, InputException $input): InputException { - return $aggregated->addException($input); - }, - new InputException() - ); - } - - return [$entityId, $entityType]; - } -} diff --git a/Model/Action/Export/ExportAction.php b/Model/Action/Export/ExportAction.php deleted file mode 100644 index 00112bb3..00000000 --- a/Model/Action/Export/ExportAction.php +++ /dev/null @@ -1,56 +0,0 @@ -exportRepository = $exportRepository; - $this->exportManagement = $exportManagement; - parent::__construct($resultBuilder); - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - $exportEntity = ArgumentReader::getEntity($actionContext); - - if ($exportEntity === null) { - throw InputException::requiredField('entity'); - } - - try { - $exportEntity = $this->exportManagement->export($exportEntity); - } catch (NoSuchEntityException $e) { - $this->exportRepository->delete($exportEntity); - - throw $e; - } - - return $this->createActionResult( - [ExportArgumentReader::EXPORT_ENTITY => $exportEntity] - ); - } -} diff --git a/Model/Action/Export/NotifierActionBundle.php b/Model/Action/Export/NotifierActionBundle.php deleted file mode 100644 index f318e8c5..00000000 --- a/Model/Action/Export/NotifierActionBundle.php +++ /dev/null @@ -1,60 +0,0 @@ -notifiers = $notifiers; - $this->objectManager = $objectManager; - parent::__construct($resultBuilder); - } - - public function execute(ActionContextInterface $actionContext): ActionResultInterface - { - $this->resolveNotifier($actionContext)->notify(ArgumentReader::getEntity($actionContext)); - - return $this->createActionResult(['is_notify' => true]); - } - - /** - * @param ActionContextInterface $actionContext - * @return NotifierInterface - * @throws InputException - */ - private function resolveNotifier(ActionContextInterface $actionContext): NotifierInterface - { - $entityType = ActionArgumentReader::getEntityType($actionContext); - - if (!isset($this->notifiers[$entityType])) { - throw InputException::invalidFieldValue('entity_type', $entityType); - } - - return $this->objectManager->get($this->notifiers[$entityType]); - } -} diff --git a/Model/Action/PerformedBy/AdminUser.php b/Model/Action/PerformedBy/AdminUser.php index 5a466182..a9cf247b 100644 --- a/Model/Action/PerformedBy/AdminUser.php +++ b/Model/Action/PerformedBy/AdminUser.php @@ -10,7 +10,7 @@ use Magento\Backend\Model\Auth\Session; use Opengento\Gdpr\Model\Action\PerformedByInterface; -final class AdminUser implements PerformedByInterface +class AdminUser implements PerformedByInterface { private const PERFORMED_BY = 'Admin: '; diff --git a/Model/Action/PerformedBy/Console.php b/Model/Action/PerformedBy/Console.php index 364b6e50..c40b5f8a 100644 --- a/Model/Action/PerformedBy/Console.php +++ b/Model/Action/PerformedBy/Console.php @@ -9,7 +9,7 @@ use Opengento\Gdpr\Model\Action\PerformedByInterface; -final class Console implements PerformedByInterface +class Console implements PerformedByInterface { private const PERFORMED_BY = 'console'; diff --git a/Model/Action/PerformedBy/Customer.php b/Model/Action/PerformedBy/Customer.php index 03ffda41..f63b31b5 100644 --- a/Model/Action/PerformedBy/Customer.php +++ b/Model/Action/PerformedBy/Customer.php @@ -11,7 +11,7 @@ use Magento\Customer\Model\Session; use Opengento\Gdpr\Model\Action\PerformedByInterface; -final class Customer implements PerformedByInterface +class Customer implements PerformedByInterface { /** * @var Session diff --git a/Model/Action/PerformedBy/Guest.php b/Model/Action/PerformedBy/Guest.php index 65c5c65a..aab938b7 100644 --- a/Model/Action/PerformedBy/Guest.php +++ b/Model/Action/PerformedBy/Guest.php @@ -12,7 +12,7 @@ use Magento\Sales\Model\Order; use Opengento\Gdpr\Model\Action\PerformedByInterface; -final class Guest implements PerformedByInterface +class Guest implements PerformedByInterface { private Registry $coreRegistry; diff --git a/Model/Action/PerformedBy/NotEmptyStrategy.php b/Model/Action/PerformedBy/NotEmptyStrategy.php index 6887ac52..6dce0ffd 100644 --- a/Model/Action/PerformedBy/NotEmptyStrategy.php +++ b/Model/Action/PerformedBy/NotEmptyStrategy.php @@ -9,7 +9,7 @@ use Opengento\Gdpr\Model\Action\PerformedByInterface; -final class NotEmptyStrategy implements PerformedByInterface +class NotEmptyStrategy implements PerformedByInterface { private const PERFORMED_BY = 'Unknown'; diff --git a/Model/Action/Result.php b/Model/Action/Result.php deleted file mode 100644 index b56f5b71..00000000 --- a/Model/Action/Result.php +++ /dev/null @@ -1,57 +0,0 @@ -performedAt = $performedAt; - $this->state = $state; - $this->message = $message; - $this->result = $result; - } - - public function getPerformedAt(): DateTime - { - return $this->performedAt; - } - - public function getState(): string - { - return $this->state; - } - - public function getMessage(): string - { - return $this->message; - } - - public function getResult(): array - { - return $this->result; - } -} diff --git a/Model/Action/ResultBuilder.php b/Model/Action/ResultBuilder.php deleted file mode 100644 index fdf5891f..00000000 --- a/Model/Action/ResultBuilder.php +++ /dev/null @@ -1,69 +0,0 @@ -actionResultFactory = $actionResultFactory; - $this->data = []; - } - - public function setPerformedAt(DateTime $performedAt): ResultBuilder - { - $this->data['performedAt'] = $performedAt; - - return $this; - } - - public function setState(string $state): ResultBuilder - { - $this->data['state'] = $state; - - return $this; - } - - public function setMessage(string $message): ResultBuilder - { - $this->data['message'] = $message; - - return $this; - } - - public function setResult(array $result): ResultBuilder - { - $this->data['result'] = $result; - - return $this; - } - - public function create(): ActionResultInterface - { - /** @var ActionResultInterface $result */ - $result = $this->actionResultFactory->create($this->data); - $this->data = []; - - return $result; - } -} diff --git a/Model/ActionEntity.php b/Model/ActionEntity.php deleted file mode 100644 index b3bf37fe..00000000 --- a/Model/ActionEntity.php +++ /dev/null @@ -1,120 +0,0 @@ -_eventPrefix = 'opengento_gdpr_action_entity'; - $this->_eventObject = 'action_entity'; - $this->_init(ActionEntityResource::class); - } - - public function getActionId(): int - { - return (int) $this->_getData(self::ID); - } - - public function setActionId(int $actionId): ActionEntityInterface - { - return $this->setData(self::ID, $actionId); - } - - public function getType(): string - { - return (string) $this->_getData(self::TYPE); - } - - public function setType(string $type): ActionEntityInterface - { - return $this->setData(self::TYPE, $type); - } - - public function getPerformedFrom(): string - { - return (string) $this->_getData(self::PERFORMED_FROM); - } - - public function setPerformedFrom(?string $performedFrom): ActionEntityInterface - { - return $this->setData(self::PERFORMED_FROM, $performedFrom); - } - - public function getPerformedBy(): string - { - return (string) $this->_getData(self::PERFORMED_BY); - } - - public function setPerformedBy(?string $performedBy): ActionEntityInterface - { - return $this->setData(self::PERFORMED_BY, $performedBy); - } - - /** - * @throws Exception - */ - public function getPerformedAt(): DateTime - { - return is_string($this->_getData(self::PERFORMED_AT)) - ? new DateTime($this->_getData(self::PERFORMED_AT)) - : $this->_getData(self::PERFORMED_AT); - } - - public function setPerformedAt(string $performedAt): ActionEntityInterface - { - return $this->setData(self::PERFORMED_AT, $performedAt); - } - - public function getState(): string - { - return (string) $this->_getData(self::STATE); - } - - public function setState(string $state): ActionEntityInterface - { - return $this->setData(self::STATE, $state); - } - - public function getMessage(): string - { - return (string) $this->_getData(self::MESSAGE); - } - - public function setMessage(string $message): ActionEntityInterface - { - return $this->setData(self::MESSAGE, $message); - } - - public function getParameters(): array - { - return (array) $this->_getData(self::PARAMETERS); - } - - public function setParameters(array $parameters): ActionEntityInterface - { - return $this->setData(self::PARAMETERS, $parameters); - } - - public function getResult(): array - { - return $this->_getData(self::RESULT) ?? []; - } - - public function setResult(array $result): ActionEntityInterface - { - return $this->setData(self::RESULT, $result); - } -} diff --git a/Model/ActionEntityBuilder.php b/Model/ActionEntityBuilder.php deleted file mode 100644 index 680ceffd..00000000 --- a/Model/ActionEntityBuilder.php +++ /dev/null @@ -1,97 +0,0 @@ -actionEntityFactory = $actionEntityFactory; - $this->data = []; - } - - public function setType(string $type): ActionEntityBuilder - { - $this->data[ActionEntityInterface::TYPE] = $type; - - return $this; - } - - public function setPerformedFrom(string $performedFrom): ActionEntityBuilder - { - $this->data[ActionEntityInterface::PERFORMED_FROM] = $performedFrom; - - return $this; - } - - public function setPerformedBy(string $performedBy): ActionEntityBuilder - { - $this->data[ActionEntityInterface::PERFORMED_BY] = $performedBy; - - return $this; - } - - public function setPerformedAt(DateTime $performedAt): ActionEntityBuilder - { - $this->data[ActionEntityInterface::PERFORMED_AT] = $performedAt; - - return $this; - } - - public function setState(string $state): ActionEntityBuilder - { - $this->data[ActionEntityInterface::STATE] = $state; - - return $this; - } - - public function setMessage(string $message): ActionEntityBuilder - { - $this->data[ActionEntityInterface::MESSAGE] = $message; - - return $this; - } - - public function setParameters(array $parameters): ActionEntityBuilder - { - $this->data[ActionEntityInterface::PARAMETERS] = $parameters; - - return $this; - } - - public function setResult(array $result): ActionEntityBuilder - { - $this->data[ActionEntityInterface::RESULT] = $result; - - return $this; - } - - public function create(): ActionEntityInterface - { - /** @var ActionEntityInterface $actionEntity */ - $actionEntity = $this->actionEntityFactory->create(['data' => $this->data]); - $this->data = []; - - return $actionEntity; - } -} diff --git a/Model/ActionEntityRepository.php b/Model/ActionEntityRepository.php deleted file mode 100644 index b3684c7d..00000000 --- a/Model/ActionEntityRepository.php +++ /dev/null @@ -1,126 +0,0 @@ -actionEntityResource = $actionEntityResource; - $this->actionFactory = $actionFactory; - $this->collectionFactory = $collectionFactory; - $this->collectionProcessor = $collectionProcessor; - $this->searchResultsFactory = $searchResultsFactory; - } - - public function save(ActionEntityInterface $actionEntity): ActionEntityInterface - { - try { - $this->actionEntityResource->save($actionEntity); - $this->instances[$actionEntity->getActionId()] = $actionEntity; - } catch (Exception $e) { - throw new CouldNotSaveException(new Phrase('Could not save the entity.'), $e); - } - - return $actionEntity; - } - - public function getById(int $actionId): ActionEntityInterface - { - if (!isset($this->instances[$actionId])) { - /** @var ActionEntityInterface $actionEntity */ - $actionEntity = $this->actionFactory->create(); - $this->actionEntityResource->load($actionEntity, $actionId, ActionEntityInterface::ID); - - if (!$actionEntity->getActionId()) { - throw NoSuchEntityException::singleField(ActionEntityInterface::ID, $actionId); - } - - $this->instances[$actionId] = $actionEntity; - } - - return $this->instances[$actionId]; - } - - public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface - { - /** @var Collection $collection */ - $collection = $this->collectionFactory->create(); - - $this->collectionProcessor->process($searchCriteria, $collection); - - /** @var ActionEntitySearchResultsInterface $searchResults */ - $searchResults = $this->searchResultsFactory->create(); - $searchResults->setSearchCriteria($searchCriteria); - $searchResults->setItems($collection->getItems()); - $searchResults->setTotalCount($collection->getSize()); - - return $searchResults; - } - - public function delete(ActionEntityInterface $actionEntity): bool - { - try { - unset($this->instances[$actionEntity->getActionId()]); - $this->actionEntityResource->delete($actionEntity); - } catch (Exception $e) { - throw new CouldNotDeleteException( - new Phrase('Could not delete entity with id "%1".', [$actionEntity->getActionId()]), - $e - ); - } - - return true; - } -} diff --git a/Model/Archive/ArchiveManager.php b/Model/Archive/ArchiveManager.php index 358d94c1..8d525789 100644 --- a/Model/Archive/ArchiveManager.php +++ b/Model/Archive/ArchiveManager.php @@ -14,25 +14,14 @@ use Magento\Framework\Filesystem; use Magento\Framework\Phrase; -final class ArchiveManager +class ArchiveManager { - private ArchiveInterface $archive; - - private Filesystem $filesystem; - public function __construct( - ArchiveInterface $archive, - Filesystem $filesystem - ) { - $this->archive = $archive; - $this->filesystem = $filesystem; - } + private ArchiveInterface $archive, + private Filesystem $filesystem + ) {} /** - * @param string $source - * @param string $destination - * @param bool $remove [optional] Remove the source files from the file system. - * @return string * @throws FileSystemException * @throws NotFoundException */ diff --git a/Model/Archive/Zip.php b/Model/Archive/Zip.php index 69b94fdc..2bb47c59 100644 --- a/Model/Archive/Zip.php +++ b/Model/Archive/Zip.php @@ -11,36 +11,28 @@ use Magento\Framework\Archive\Zip as ArchiveZip; use Magento\Framework\Filesystem; use ZipArchive; + use function basename; /** * Zip compressed file archive with local file name. * @api */ -final class Zip implements ArchiveInterface +class Zip implements ArchiveInterface { - private Filesystem $filesystem; - - /** - * @var ArchiveZip - */ - private ArchiveZip $zip; - public function __construct( - Filesystem $filesystem, - ArchiveZip $zip - ) { - $this->filesystem = $filesystem; - $this->zip = $zip; - } + private Filesystem $filesystem, + private ArchiveZip $zip + ) {} public function pack($source, $destination): string { - $directoryRead = $this->filesystem->getDirectoryReadByPath($source); - $zip = new ZipArchive(); $zip->open($destination, ZipArchive::CREATE); - $zip->addFile($source, $directoryRead->isDirectory($source) ? '' : basename($source)); + $zip->addFile( + $source, + $this->filesystem->getDirectoryReadByPath($source)->isDirectory($source) ? '' : basename($source) + ); $zip->close(); return $destination; diff --git a/Model/Config.php b/Model/Config.php index e8471aaa..dc6fa1f0 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -9,58 +9,29 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; -use function explode; -final class Config +class Config { - /** - * Scope Config: Data Settings Paths - */ - public const CONFIG_PATH_GENERAL_ENABLED = 'gdpr/general/enabled'; - public const CONFIG_PATH_ERASURE_ENABLED = 'gdpr/erasure/enabled'; - public const CONFIG_PATH_ERASURE_ALLOWED_STATES = 'gdpr/erasure/allowed_states'; - public const CONFIG_PATH_EXPORT_ENABLED = 'gdpr/export/enabled'; + private const CONFIG_PATH_GENERAL_ENABLED = 'gdpr/general/enabled'; + private const CONFIG_PATH_ERASURE_ENABLED = 'gdpr/erasure/enabled'; + private const CONFIG_PATH_EXPORT_ENABLED = 'gdpr/export/enabled'; - private ScopeConfigInterface $scopeConfig; + public function __construct(private ScopeConfigInterface $scopeConfig) {} - public function __construct( - ScopeConfigInterface $scopeConfig - ) { - $this->scopeConfig = $scopeConfig; - } - - public function isModuleEnabled(): bool - { - return $this->scopeConfig->isSetFlag( - self::CONFIG_PATH_GENERAL_ENABLED, - ScopeInterface::SCOPE_STORE - ); - } - - public function isErasureEnabled(): bool + public function isModuleEnabled(int|string|null $website = null): bool { - return $this->scopeConfig->isSetFlag( - self::CONFIG_PATH_ERASURE_ENABLED, - ScopeInterface::SCOPE_STORE - ); + return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_GENERAL_ENABLED, ScopeInterface::SCOPE_WEBSITE, $website); } - /** - * @return string[] - */ - public function getAllowedStatesToErase(): array + public function isErasureEnabled(int|string|null $website = null): bool { - return explode(',', (string) $this->scopeConfig->getValue( - self::CONFIG_PATH_ERASURE_ALLOWED_STATES, - ScopeInterface::SCOPE_STORE - )); + return $this->isModuleEnabled($website) + && $this->scopeConfig->isSetFlag(self::CONFIG_PATH_ERASURE_ENABLED, ScopeInterface::SCOPE_WEBSITE, $website); } - public function isExportEnabled(): bool + public function isExportEnabled(int|string|null $website = null): bool { - return $this->scopeConfig->isSetFlag( - self::CONFIG_PATH_EXPORT_ENABLED, - ScopeInterface::SCOPE_STORE - ); + return $this->isModuleEnabled($website) + && $this->scopeConfig->isSetFlag(self::CONFIG_PATH_EXPORT_ENABLED, ScopeInterface::SCOPE_WEBSITE, $website); } } diff --git a/Model/Config/Backend/Export.php b/Model/Config/Backend/Export.php index ed7a1f53..52823b54 100644 --- a/Model/Config/Backend/Export.php +++ b/Model/Config/Backend/Export.php @@ -21,10 +21,6 @@ class Export extends Value { - private ExportEntityRepositoryInterface $exportRepository; - - private SearchCriteriaBuilder $criteriaBuilder; - public function __construct( Context $context, Registry $registry, @@ -32,12 +28,10 @@ public function __construct( TypeListInterface $cacheTypeList, AbstractResource $resource, AbstractDb $resourceCollection, - ExportEntityRepositoryInterface $exportRepository, - SearchCriteriaBuilder $criteriaBuilder, + private ExportEntityRepositoryInterface $exportRepository, + private SearchCriteriaBuilder $criteriaBuilder, array $data = [] ) { - $this->exportRepository = $exportRepository; - $this->criteriaBuilder = $criteriaBuilder; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } @@ -49,9 +43,7 @@ public function __construct( public function afterSave(): self { if ($this->isValueChanged()) { - $exportList = $this->exportRepository->getList($this->criteriaBuilder->create()); - - foreach ($exportList->getItems() as $exportEntity) { + foreach ($this->exportRepository->getList($this->criteriaBuilder->create())->getItems() as $exportEntity) { $this->exportRepository->delete($exportEntity); } } diff --git a/Model/Config/Entity/Erasure.php b/Model/Config/Entity/Erasure.php new file mode 100644 index 00000000..172cc585 --- /dev/null +++ b/Model/Config/Entity/Erasure.php @@ -0,0 +1,60 @@ +scopeConfig->getValue( + self::CONFIG_PATH_ERASURE_MAX_AGE, + ScopeInterface::SCOPE_WEBSITE, + $website + ); + } + + /** + * @throws Exception + */ + public function getEntityExpireDate(int|string|null $website = null): DateTimeImmutable + { + return new DateTimeImmutable('-' . $this->getEntityMaxAge($website) . 'days'); + } + + /** + * @return string[] + */ + public function getAllowedStatesToErase(int|string|null $website = null): array + { + return explode(',', (string)$this->scopeConfig->getValue( + self::CONFIG_PATH_ERASURE_ALLOWED_STATES, + ScopeInterface::SCOPE_WEBSITE, + $website + )); + } + + public function getDelay(): int + { + return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY); + } +} diff --git a/Model/Config/PrivacyMessage.php b/Model/Config/PrivacyMessage.php deleted file mode 100644 index 65cb1f8e..00000000 --- a/Model/Config/PrivacyMessage.php +++ /dev/null @@ -1,72 +0,0 @@ -scopeConfig = $scopeConfig; - $this->blockFactory = $blockFactory; - $this->helperPage = $helperPage; - } - - public function isEnabled(): bool - { - return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_COOKIE_INFORMATION_ENABLED, ScopeInterface::SCOPE_STORE); - } - - public function getDisclosureInformationHtml(): string - { - return $this->blockHtml ??= $this->createDisclosureInformationBlockHtml(); - } - - public function getLearnMoreUrl(): ?string - { - return $this->helperPage->getPageUrl((string) $this->scopeConfig->getValue( - self::CONFIG_PATH_COOKIE_INFORMATION_PAGE, - ScopeInterface::SCOPE_STORE - )); - } - - private function createDisclosureInformationBlockHtml(): string - { - return $this->blockFactory->createBlock( - BlockByIdentifier::class, - [ - 'data' => [ - 'identifier' => (string) $this->scopeConfig->getValue( - self::CONFIG_PATH_COOKIE_INFORMATION_BLOCK, - ScopeInterface::SCOPE_STORE - ), - ], - ] - )->toHtml(); - } -} diff --git a/Model/Config/Source/ActionStates.php b/Model/Config/Source/ActionStates.php deleted file mode 100644 index 45213971..00000000 --- a/Model/Config/Source/ActionStates.php +++ /dev/null @@ -1,62 +0,0 @@ -additionalOptions = $additionalOptions; - $this->options = []; - $this->optionArray = []; - } - - public function toOptionArray(): array - { - if (!$this->optionArray) { - foreach ($this->loadOptions() as $value => $label) { - $this->optionArray[] = compact('value', 'label'); - } - } - - return $this->optionArray; - } - - public function getOptionText(string $state): ?string - { - return isset($this->loadOptions()[$state]) ? (string) $this->loadOptions()[$state] : null; - } - - private function loadOptions(): array - { - if (!$this->options) { - $this->options = array_merge( - [ - ActionEntityInterface::STATE_SUCCEEDED => new Phrase('Succeeded'), - ActionEntityInterface::STATE_FAILED => new Phrase('Failed'), - ], - $this->additionalOptions - ); - } - - return $this->options; - } -} diff --git a/Model/Config/Source/EraseComponents.php b/Model/Config/Source/EraseComponents.php index 4236b3f1..2a30faea 100644 --- a/Model/Config/Source/EraseComponents.php +++ b/Model/Config/Source/EraseComponents.php @@ -10,45 +10,31 @@ use Magento\Framework\Data\OptionSourceInterface; use Magento\Framework\ObjectManager\ConfigInterface; use Magento\Framework\Phrase; + use function array_keys; +use function array_map; use function array_merge; +use function array_unique; +use function array_values; -final class EraseComponents implements OptionSourceInterface +class EraseComponents implements OptionSourceInterface { - /** - * @var ConfigInterface - */ - private ConfigInterface $objectManagerConfig; - - /** - * Class must be an instance of `\Opengento\Gdpr\Service\Erase\ProcessorResolverFactory` - * - * @var string - */ - private string $factoryClassName; - - /** - * @var string[][] - */ - private array $options = []; + private ?array $options = null; public function __construct( - ConfigInterface $objectManagerConfig, - string $factoryClassName - ) { - $this->objectManagerConfig = $objectManagerConfig; - $this->factoryClassName = $factoryClassName; - } + private ConfigInterface $objectManagerConfig, + private string $factoryClassName + ) {} public function toOptionArray(): array { - if (!$this->options) { - foreach ($this->retrieveDelegateProcessors() as $delegateProcessor) { - $this->options[] = ['value' => $delegateProcessor, 'label' => new Phrase($delegateProcessor)]; - } - } - - return $this->options; + return $this->options ??= array_map( + static fn (string $delegateProcessor): array => [ + 'value' => $delegateProcessor, + 'label' => new Phrase($delegateProcessor) + ], + $this->retrieveDelegateProcessors() + ); } /** @@ -56,26 +42,18 @@ public function toOptionArray(): array */ private function retrieveDelegateProcessors(): array { - $delegateProcessors = []; - /** @var string[] $resolvers */ - $resolvers = $this->retrieveArgument($this->factoryClassName, 'processorResolvers', []); - - foreach ($resolvers as $resolver) { - $delegateProcessors[] = $this->retrieveArgument($resolver, 'processors'); - } - - return array_keys(array_merge([], ...$delegateProcessors)); + return array_unique( + array_merge( + [], + ...array_map( + fn (string $resolver): array => array_keys($this->retrieveArgument($resolver, 'processors')), + array_values($this->retrieveArgument($this->factoryClassName, 'processorResolvers', [])) + ) + ) + ); } - /** - * Retrieve a construct argument value of a class - * - * @param string $className - * @param string $argumentName - * @param mixed $defaultValue - * @return mixed - */ - private function retrieveArgument(string $className, string $argumentName, $defaultValue = null) + private function retrieveArgument(string $className, string $argumentName, mixed $defaultValue = null): array { $arguments = $this->objectManagerConfig->getArguments( $this->objectManagerConfig->getPreference($className) diff --git a/Model/Config/Source/OrderPendingStates.php b/Model/Config/Source/OrderPendingStates.php index 00bc834e..a60adb52 100644 --- a/Model/Config/Source/OrderPendingStates.php +++ b/Model/Config/Source/OrderPendingStates.php @@ -10,20 +10,11 @@ use Magento\Framework\Data\OptionSourceInterface; use Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory; -final class OrderPendingStates implements OptionSourceInterface +class OrderPendingStates implements OptionSourceInterface { - private CollectionFactory $collectionFactory; + private ?array $options = null; - /** - * @var string[][] - */ - private array $options; - - public function __construct( - CollectionFactory $collectionFactory - ) { - $this->collectionFactory = $collectionFactory; - } + public function __construct(private CollectionFactory $collectionFactory) {} public function toOptionArray(): array { diff --git a/Model/Config/Source/VirtualArrayArgumentList.php b/Model/Config/Source/VirtualArrayArgumentList.php index 61893140..a6594014 100644 --- a/Model/Config/Source/VirtualArrayArgumentList.php +++ b/Model/Config/Source/VirtualArrayArgumentList.php @@ -10,40 +10,26 @@ use Magento\Framework\Data\OptionSourceInterface; use Magento\Framework\ObjectManager\ConfigInterface; use Magento\Framework\Phrase; + use function array_keys; +use function array_map; -final class VirtualArrayArgumentList implements OptionSourceInterface +class VirtualArrayArgumentList implements OptionSourceInterface { - /** - * @var ConfigInterface - */ - private ConfigInterface $objectManagerConfig; - - private string $className; - - private string $argumentName; - - private array $options = []; + private ?array $options = null; public function __construct( - ConfigInterface $objectManagerConfig, - string $className, - string $argumentName - ) { - $this->objectManagerConfig = $objectManagerConfig; - $this->className = $className; - $this->argumentName = $argumentName; - } + private ConfigInterface $objectManagerConfig, + private string $className, + private string $argumentName + ) {} public function toOptionArray(): array { - if (!$this->options) { - foreach (array_keys($this->retrieveItems()) as $item) { - $this->options[] = ['value' => $item, 'label' => new Phrase($item)]; - } - } - - return $this->options; + return $this->options ??= array_map( + static fn (string $item): array => ['value' => $item, 'label' => new Phrase($item)], + array_keys($this->retrieveItems()) + ); } /** diff --git a/Model/Config/Source/VirtualCustomerAttributes.php b/Model/Config/Source/VirtualCustomerAttributes.php index bbae965e..9b8c9560 100644 --- a/Model/Config/Source/VirtualCustomerAttributes.php +++ b/Model/Config/Source/VirtualCustomerAttributes.php @@ -7,40 +7,36 @@ namespace Opengento\Gdpr\Model\Config\Source; +use Magento\Customer\Api\Data\AttributeMetadataInterface; use Magento\Customer\Api\MetadataInterface; use Magento\Framework\Data\OptionSourceInterface; use Magento\Framework\Exception\LocalizedException; -final class VirtualCustomerAttributes implements OptionSourceInterface -{ - private MetadataInterface $metadata; +use function array_map; - private array $options; +class VirtualCustomerAttributes implements OptionSourceInterface +{ + private ?array $options = null; - public function __construct( - MetadataInterface $metadata - ) { - $this->metadata = $metadata; - $this->options = []; - } + public function __construct(private MetadataInterface $metadata) {} public function toOptionArray(): array { - if (!$this->options) { - try { - $attributes = $this->metadata->getAllAttributesMetadata(); - } catch (LocalizedException $e) { - $attributes = []; - } + return $this->options ??= array_map( + static fn (AttributeMetadataInterface $attributeMetadata): array => [ + 'value' => $attributeMetadata->getAttributeCode(), + 'label' => $attributeMetadata->getFrontendLabel(), + ], + $this->resolveAttributeMetadataList() + ); + } - foreach ($attributes as $attribute) { - $this->options[] = [ - 'value' => $attribute->getAttributeCode(), - 'label' => $attribute->getFrontendLabel(), - ]; - } + private function resolveAttributeMetadataList(): array + { + try { + return $this->metadata->getAllAttributesMetadata(); + } catch (LocalizedException) { + return []; } - - return $this->options; } } diff --git a/Model/Config/Source/VirtualEntityAttributes.php b/Model/Config/Source/VirtualEntityAttributes.php deleted file mode 100644 index ae5b20e2..00000000 --- a/Model/Config/Source/VirtualEntityAttributes.php +++ /dev/null @@ -1,49 +0,0 @@ -attributeProvider = $attributeProvider; - $this->entityType = $entityType; - $this->options = []; - } - - public function toOptionArray(): array - { - if (!$this->options) { - foreach (array_keys($this->attributeProvider->getAttributes($this->entityType)) as $attribute) { - $this->options[] = ['value' => $attribute, 'label' => $attribute]; - } - } - - return $this->options; - } -} diff --git a/Model/Customer/Anonymize/Processor/CustomerAddressDataProcessor.php b/Model/Customer/Anonymize/Processor/CustomerAddressDataProcessor.php index 68db7c3a..9937323a 100644 --- a/Model/Customer/Anonymize/Processor/CustomerAddressDataProcessor.php +++ b/Model/Customer/Anonymize/Processor/CustomerAddressDataProcessor.php @@ -9,30 +9,18 @@ use Magento\Customer\Api\AddressRepositoryInterface; use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\DataObject; use Magento\Framework\Exception\LocalizedException; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class CustomerAddressDataProcessor implements ProcessorInterface +class CustomerAddressDataProcessor implements ProcessorInterface { - private AnonymizerInterface $anonymizer; - - /** - * @var AddressRepositoryInterface - */ - private AddressRepositoryInterface $addressRepository; - - private SearchCriteriaBuilder $criteriaBuilder; - public function __construct( - AnonymizerInterface $anonymizer, - AddressRepositoryInterface $addressRepository, - SearchCriteriaBuilder $criteriaBuilder - ) { - $this->anonymizer = $anonymizer; - $this->addressRepository = $addressRepository; - $this->criteriaBuilder = $criteriaBuilder; - } + private AnonymizerInterface $anonymizer, + private AddressRepositoryInterface $addressRepository, + private SearchCriteriaBuilder $criteriaBuilder + ) {} /** * @inheritdoc @@ -44,7 +32,11 @@ public function execute(int $customerId): bool $addressList = $this->addressRepository->getList($this->criteriaBuilder->create()); foreach ($addressList->getItems() as $address) { - $this->addressRepository->save($this->anonymizer->anonymize($address)); + $address = $this->anonymizer->anonymize($address); + if ($address instanceof DataObject) { + $address->setData('should_ignore_validation', true); + } + $this->addressRepository->save($address); } return true; diff --git a/Model/Customer/Anonymize/Processor/CustomerDataProcessor.php b/Model/Customer/Anonymize/Processor/CustomerDataProcessor.php index 7bf5b7e3..4f0000ed 100644 --- a/Model/Customer/Anonymize/Processor/CustomerDataProcessor.php +++ b/Model/Customer/Anonymize/Processor/CustomerDataProcessor.php @@ -7,18 +7,18 @@ namespace Opengento\Gdpr\Model\Customer\Anonymize\Processor; -use DateTime; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Customer\Api\SessionCleanerInterface; use Magento\Customer\Model\CustomerRegistry; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\DataObject; use Magento\Framework\Exception\InputException; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\State\InputMismatchException; -use Magento\Framework\Stdlib\DateTime as DateTimeFormat; +use Magento\Framework\Math\Random; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\Data\OrderSearchResultInterface; use Magento\Sales\Api\OrderRepositoryInterface; @@ -26,76 +26,35 @@ use Opengento\Gdpr\Model\Customer\OrigDataRegistry; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -use function mt_rand; -use function sha1; -use function uniqid; -use const PHP_INT_MAX; -final class CustomerDataProcessor implements ProcessorInterface +class CustomerDataProcessor implements ProcessorInterface { private const CONFIG_PATH_ERASURE_REMOVE_CUSTOMER = 'gdpr/erasure/remove_customer'; - private AnonymizerInterface $anonymizer; - - /** - * @var CustomerRepositoryInterface - */ - private CustomerRepositoryInterface $customerRepository; - - private OrderRepositoryInterface $orderRepository; - - private SearchCriteriaBuilder $criteriaBuilder; - - /** - * @var CustomerRegistry - */ - private CustomerRegistry $customerRegistry; - - /** - * @var OrigDataRegistry - */ - private OrigDataRegistry $origDataRegistry; - - /** - * @var SessionCleanerInterface - */ - private SessionCleanerInterface $sessionCleaner; - - private ScopeConfigInterface $scopeConfig; - public function __construct( - AnonymizerInterface $anonymizer, - CustomerRepositoryInterface $customerRepository, - OrderRepositoryInterface $orderRepository, - SearchCriteriaBuilder $criteriaBuilder, - CustomerRegistry $customerRegistry, - OrigDataRegistry $origDataRegistry, - SessionCleanerInterface $sessionCleaner, - ScopeConfigInterface $scopeConfig - ) { - $this->anonymizer = $anonymizer; - $this->customerRepository = $customerRepository; - $this->orderRepository = $orderRepository; - $this->criteriaBuilder = $criteriaBuilder; - $this->customerRegistry = $customerRegistry; - $this->origDataRegistry = $origDataRegistry; - $this->sessionCleaner = $sessionCleaner; - $this->scopeConfig = $scopeConfig; - } + private AnonymizerInterface $anonymizer, + private CustomerRepositoryInterface $customerRepository, + private OrderRepositoryInterface $orderRepository, + private SearchCriteriaBuilder $criteriaBuilder, + private CustomerRegistry $customerRegistry, + private OrigDataRegistry $origDataRegistry, + private SessionCleanerInterface $sessionCleaner, + private ScopeConfigInterface $scopeConfig, + private Random $random + ) {} /** - * @inheritdoc * @throws LocalizedException */ - public function execute(int $customerId): bool + public function execute(int $entityId): bool { try { - $this->processCustomerData($customerId); - } catch (NoSuchEntityException $e) { + $this->processCustomerData($entityId); + } catch (NoSuchEntityException) { return false; } - $this->sessionCleaner->clearFor($customerId); + $this->sessionCleaner->clearFor($entityId); return true; } @@ -112,7 +71,7 @@ private function processCustomerData(int $customerId): void $this->origDataRegistry->set(clone $customer); $isRemoved = false; - if ($this->shouldRemoveCustomerWithoutOrders() && !$this->fetchOrdersList($customer)->getTotalCount()) { + if ($this->shouldRemoveCustomerWithoutOrders($customer) && !$this->fetchOrdersList($customer)->getTotalCount()) { $isRemoved = $this->customerRepository->deleteById($customer->getId()); } if (!$isRemoved) { @@ -138,15 +97,23 @@ private function anonymizeCustomer(CustomerInterface $customer): void $this->customerRegistry->remove($customer->getId()); $secureData = $this->customerRegistry->retrieveSecureData($customer->getId()); - $dateTime = (new DateTime())->setTimestamp(PHP_INT_MAX); - $secureData->setData('lock_expires', $dateTime->format(DateTimeFormat::DATETIME_PHP_FORMAT)); - $secureData->setPasswordHash(sha1(uniqid((string) mt_rand(), true))); + $secureData->setData('lock_expires', '9999-12-31 23:59:59'); + $secureData->setPasswordHash($this->random->getUniqueHash()); + + $customer = $this->anonymizer->anonymize($customer); + if ($customer instanceof DataObject) { + $customer->setData('ignore_validation_flag', true); + } - $this->customerRepository->save($this->anonymizer->anonymize($customer)); + $this->customerRepository->save($customer); } - private function shouldRemoveCustomerWithoutOrders(): bool + private function shouldRemoveCustomerWithoutOrders(CustomerInterface $customer): bool { - return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_ERASURE_REMOVE_CUSTOMER, ScopeInterface::SCOPE_STORE); + return $this->scopeConfig->isSetFlag( + self::CONFIG_PATH_ERASURE_REMOVE_CUSTOMER, + ScopeInterface::SCOPE_WEBSITE, + $customer->getWebsiteId() + ); } } diff --git a/Model/Customer/Anonymize/Processor/OrderDataProcessor.php b/Model/Customer/Anonymize/Processor/OrderDataProcessor.php index e07f0776..04fa265e 100644 --- a/Model/Customer/Anonymize/Processor/OrderDataProcessor.php +++ b/Model/Customer/Anonymize/Processor/OrderDataProcessor.php @@ -19,7 +19,7 @@ use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class OrderDataProcessor implements ProcessorInterface +class OrderDataProcessor implements ProcessorInterface { private AnonymizerInterface $anonymizer; @@ -58,7 +58,7 @@ public function execute(int $customerId): bool foreach ($orderList->getItems() as $order) { $lastActive = new DateTime($order->getUpdatedAt()); $this->salesInformation->isAlive($lastActive) - ? $this->salesInformation->scheduleEraseEntity((int) $order->getEntityId(), 'order', $lastActive) + ? $this->salesInformation->scheduleEraseEntity((int)$order->getEntityId(), 'order', $lastActive) : $this->anonymize($order); } diff --git a/Model/Customer/Anonymize/Processor/QuoteDataProcessor.php b/Model/Customer/Anonymize/Processor/QuoteDataProcessor.php index d1eebe19..ce0dd358 100644 --- a/Model/Customer/Anonymize/Processor/QuoteDataProcessor.php +++ b/Model/Customer/Anonymize/Processor/QuoteDataProcessor.php @@ -15,7 +15,7 @@ use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class QuoteDataProcessor implements ProcessorInterface +class QuoteDataProcessor implements ProcessorInterface { private AnonymizerInterface $anonymizer; diff --git a/Model/Customer/Anonymize/Processor/SubscriberDataProcessor.php b/Model/Customer/Anonymize/Processor/SubscriberDataProcessor.php index 16482033..e3913246 100644 --- a/Model/Customer/Anonymize/Processor/SubscriberDataProcessor.php +++ b/Model/Customer/Anonymize/Processor/SubscriberDataProcessor.php @@ -14,7 +14,7 @@ use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class SubscriberDataProcessor implements ProcessorInterface +class SubscriberDataProcessor implements ProcessorInterface { private AnonymizerInterface $anonymizer; diff --git a/Model/Customer/CustomerChecker.php b/Model/Customer/CustomerChecker.php index b2894c75..8cc883d5 100644 --- a/Model/Customer/CustomerChecker.php +++ b/Model/Customer/CustomerChecker.php @@ -7,46 +7,36 @@ namespace Opengento\Gdpr\Model\Customer; -use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Sales\Api\Data\OrderInterface; -use Magento\Sales\Api\OrderRepositoryInterface; -use Opengento\Gdpr\Model\Config; +use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; +use Opengento\Gdpr\Model\Config\Entity\Erasure as ErasureConfig; use Opengento\Gdpr\Model\Entity\EntityCheckerInterface; -final class CustomerChecker implements EntityCheckerInterface +class CustomerChecker implements EntityCheckerInterface { - private OrderRepositoryInterface $orderRepository; - - private SearchCriteriaBuilder $criteriaBuilder; - - private Config $config; + public function __construct( + private CustomerRepositoryInterface $customerRepository, + private CollectionFactory $collectionFactory, + private ErasureConfig $erasureConfig + ) {} /** - * @var bool[] + * @throws NoSuchEntityException + * @throws LocalizedException */ - private array $cache; - - public function __construct( - OrderRepositoryInterface $orderRepository, - SearchCriteriaBuilder $criteriaBuilder, - Config $config - ) { - $this->orderRepository = $orderRepository; - $this->criteriaBuilder = $criteriaBuilder; - $this->config = $config; - $this->cache = []; - } - - public function canErase(int $customerId): bool + public function canErase(int $entityId): bool { - if (!isset($this->cache[$customerId])) { - $this->criteriaBuilder->addFilter(OrderInterface::STATE, $this->config->getAllowedStatesToErase(), 'nin'); - $this->criteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId); - $orderList = $this->orderRepository->getList($this->criteriaBuilder->create()); - - $this->cache[$customerId] = !$orderList->getTotalCount(); - } - - return $this->cache[$customerId]; + $customer = $this->customerRepository->getById($entityId); + $collection = $this->collectionFactory->create(); + $collection->addFieldToFilter(OrderInterface::CUSTOMER_ID, $entityId); + $collection->addFieldToFilter( + OrderInterface::STATE, + ['nin' => $this->erasureConfig->getAllowedStatesToErase($customer->getWebsiteId())] + ); + + return !$collection->getSize(); } } diff --git a/Model/Customer/Delete/Processor/CustomerAddressDataProcessor.php b/Model/Customer/Delete/Processor/CustomerAddressDataProcessor.php index 927518ff..3cd84a4d 100644 --- a/Model/Customer/Delete/Processor/CustomerAddressDataProcessor.php +++ b/Model/Customer/Delete/Processor/CustomerAddressDataProcessor.php @@ -12,7 +12,7 @@ use Magento\Framework\Exception\LocalizedException; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class CustomerAddressDataProcessor implements ProcessorInterface +class CustomerAddressDataProcessor implements ProcessorInterface { /** * @var AddressRepositoryInterface diff --git a/Model/Customer/Delete/Processor/CustomerDataProcessor.php b/Model/Customer/Delete/Processor/CustomerDataProcessor.php index f33714f7..9cab79df 100644 --- a/Model/Customer/Delete/Processor/CustomerDataProcessor.php +++ b/Model/Customer/Delete/Processor/CustomerDataProcessor.php @@ -13,7 +13,7 @@ use Magento\Framework\Exception\NoSuchEntityException; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class CustomerDataProcessor implements ProcessorInterface +class CustomerDataProcessor implements ProcessorInterface { /** * @var CustomerRepositoryInterface diff --git a/Model/Customer/Delete/Processor/OrderDataProcessor.php b/Model/Customer/Delete/Processor/OrderDataProcessor.php index e4fa360a..2beb36bc 100644 --- a/Model/Customer/Delete/Processor/OrderDataProcessor.php +++ b/Model/Customer/Delete/Processor/OrderDataProcessor.php @@ -15,7 +15,7 @@ use Opengento\Gdpr\Api\EraseSalesInformationInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class OrderDataProcessor implements ProcessorInterface +class OrderDataProcessor implements ProcessorInterface { private OrderRepositoryInterface $orderRepository; @@ -45,7 +45,7 @@ public function execute(int $customerId): bool foreach ($orderList->getItems() as $order) { $lastActive = new DateTime($order->getUpdatedAt()); $this->salesInformation->isAlive($lastActive) - ? $this->salesInformation->scheduleEraseEntity((int) $order->getEntityId(), 'order', $lastActive) + ? $this->salesInformation->scheduleEraseEntity((int)$order->getEntityId(), 'order', $lastActive) : $this->orderRepository->delete($order); } diff --git a/Model/Customer/Delete/Processor/QuoteDataProcessor.php b/Model/Customer/Delete/Processor/QuoteDataProcessor.php index 0b19224e..4e925697 100644 --- a/Model/Customer/Delete/Processor/QuoteDataProcessor.php +++ b/Model/Customer/Delete/Processor/QuoteDataProcessor.php @@ -11,7 +11,7 @@ use Magento\Quote\Api\CartRepositoryInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class QuoteDataProcessor implements ProcessorInterface +class QuoteDataProcessor implements ProcessorInterface { private CartRepositoryInterface $quoteRepository; diff --git a/Model/Customer/Delete/Processor/SubscriberDataProcessor.php b/Model/Customer/Delete/Processor/SubscriberDataProcessor.php index 8083c8b6..f017042c 100644 --- a/Model/Customer/Delete/Processor/SubscriberDataProcessor.php +++ b/Model/Customer/Delete/Processor/SubscriberDataProcessor.php @@ -13,7 +13,7 @@ use Magento\Newsletter\Model\SubscriberFactory; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class SubscriberDataProcessor implements ProcessorInterface +class SubscriberDataProcessor implements ProcessorInterface { private SubscriberFactory $subscriberFactory; diff --git a/Model/Customer/Erase/Notifier.php b/Model/Customer/Erase/Notifier.php index af58e841..7c4e9b57 100644 --- a/Model/Customer/Erase/Notifier.php +++ b/Model/Customer/Erase/Notifier.php @@ -15,7 +15,7 @@ use Opengento\Gdpr\Model\Erase\NotifierInterface; use Psr\Log\LoggerInterface; -final class Notifier implements NotifierInterface +class Notifier implements NotifierInterface { /** @var SenderInterface[] */ private array $senders; @@ -51,7 +51,7 @@ public function notify(EraseEntityInterface $eraseEntity): void try { $sender->send($customer); } catch (LocalizedException $e) { - $this->logger->error($e->getLogMessage(), $e->getTrace()); + $this->logger->error($e->getLogMessage(), ['exception' => $e]); } } } diff --git a/Model/Customer/Export/Notifier.php b/Model/Customer/Export/Notifier.php index 07e0671c..524dfdbe 100644 --- a/Model/Customer/Export/Notifier.php +++ b/Model/Customer/Export/Notifier.php @@ -14,7 +14,7 @@ use Opengento\Gdpr\Model\Export\NotifierInterface; use Psr\Log\LoggerInterface; -final class Notifier implements NotifierInterface +class Notifier implements NotifierInterface { /** @var SenderInterface[] */ private array $senders; @@ -45,7 +45,7 @@ public function notify(ExportEntityInterface $exportEntity): void try { $sender->send($customer); } catch (LocalizedException $e) { - $this->logger->error($e->getLogMessage(), $e->getTrace()); + $this->logger->error($e->getLogMessage(), ['exception' => $e]); } } } diff --git a/Model/Customer/Export/Processor/CustomerAddressDataProcessor.php b/Model/Customer/Export/Processor/CustomerAddressDataProcessor.php index 18ba7556..7e667bf7 100644 --- a/Model/Customer/Export/Processor/CustomerAddressDataProcessor.php +++ b/Model/Customer/Export/Processor/CustomerAddressDataProcessor.php @@ -14,7 +14,7 @@ use Opengento\Gdpr\Model\Entity\DataCollectorInterface; use Opengento\Gdpr\Service\Export\Processor\AbstractDataProcessor; -final class CustomerAddressDataProcessor extends AbstractDataProcessor +class CustomerAddressDataProcessor extends AbstractDataProcessor { /** * @var AddressRepositoryInterface diff --git a/Model/Customer/Export/Processor/CustomerDataProcessor.php b/Model/Customer/Export/Processor/CustomerDataProcessor.php index 9150ebdc..8be3f931 100644 --- a/Model/Customer/Export/Processor/CustomerDataProcessor.php +++ b/Model/Customer/Export/Processor/CustomerDataProcessor.php @@ -13,7 +13,7 @@ use Opengento\Gdpr\Model\Entity\DataCollectorInterface; use Opengento\Gdpr\Service\Export\Processor\AbstractDataProcessor; -final class CustomerDataProcessor extends AbstractDataProcessor +class CustomerDataProcessor extends AbstractDataProcessor { /** * @var CustomerRepositoryInterface diff --git a/Model/Customer/Export/Processor/OrderDataProcessor.php b/Model/Customer/Export/Processor/OrderDataProcessor.php index bfb3ff38..db33350e 100644 --- a/Model/Customer/Export/Processor/OrderDataProcessor.php +++ b/Model/Customer/Export/Processor/OrderDataProcessor.php @@ -15,7 +15,7 @@ use Opengento\Gdpr\Model\Entity\DataCollectorInterface; use Opengento\Gdpr\Service\Export\Processor\AbstractDataProcessor; -final class OrderDataProcessor extends AbstractDataProcessor +class OrderDataProcessor extends AbstractDataProcessor { private OrderRepositoryInterface $orderRepository; diff --git a/Model/Customer/Export/Processor/QuoteDataProcessor.php b/Model/Customer/Export/Processor/QuoteDataProcessor.php index fb537797..0ead8c04 100644 --- a/Model/Customer/Export/Processor/QuoteDataProcessor.php +++ b/Model/Customer/Export/Processor/QuoteDataProcessor.php @@ -14,7 +14,7 @@ use Opengento\Gdpr\Model\Entity\DataCollectorInterface; use Opengento\Gdpr\Service\Export\Processor\AbstractDataProcessor; -final class QuoteDataProcessor extends AbstractDataProcessor +class QuoteDataProcessor extends AbstractDataProcessor { private CartRepositoryInterface $quoteRepository; diff --git a/Model/Customer/Export/Processor/SubscriberDataProcessor.php b/Model/Customer/Export/Processor/SubscriberDataProcessor.php index 7508924c..05104a21 100644 --- a/Model/Customer/Export/Processor/SubscriberDataProcessor.php +++ b/Model/Customer/Export/Processor/SubscriberDataProcessor.php @@ -12,7 +12,7 @@ use Opengento\Gdpr\Model\Newsletter\SubscriberFactory; use Opengento\Gdpr\Service\Export\Processor\AbstractDataProcessor; -final class SubscriberDataProcessor extends AbstractDataProcessor +class SubscriberDataProcessor extends AbstractDataProcessor { private SubscriberFactory $subscriberFactory; diff --git a/Model/Customer/Notifier/MailSender.php b/Model/Customer/Notifier/MailSender.php index 3fb380d2..f2379c0a 100644 --- a/Model/Customer/Notifier/MailSender.php +++ b/Model/Customer/Notifier/MailSender.php @@ -15,23 +15,19 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Store\Model\StoreManagerInterface; +use Opengento\Gdpr\Model\Config\Entity\Erasure; use Opengento\Gdpr\Model\Notifier\AbstractMailSender; -final class MailSender extends AbstractMailSender implements SenderInterface +class MailSender extends AbstractMailSender implements SenderInterface { - private View $customerViewHelper; - - private StoreManagerInterface $storeManager; - public function __construct( - View $customerViewHelper, + private Erasure $erasureConfig, + private View $customerViewHelper, + private StoreManagerInterface $storeManager, TransportBuilder $transportBuilder, ScopeConfigInterface $scopeConfig, - StoreManagerInterface $storeManager, array $configPaths ) { - $this->customerViewHelper = $customerViewHelper; - $this->storeManager = $storeManager; parent::__construct($transportBuilder, $scopeConfig, $configPaths); } @@ -42,15 +38,21 @@ public function __construct( */ public function send(CustomerInterface $customer): void { - $storeId = $customer->getStoreId() === null ? null : (int) $customer->getStoreId(); - $vars = [ - 'customer' => $customer, - 'store' => $this->storeManager->getStore($customer->getStoreId()), - 'customer_data' => [ - 'customer_name' => $this->customerViewHelper->getCustomerName($customer), - ], - ]; + $delay = $this->erasureConfig->getDelay(); + $storeId = $customer->getStoreId() === null ? null : (int)$customer->getStoreId(); - $this->sendMail($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer), $storeId, $vars); + $this->sendMail( + $customer->getEmail(), + $this->customerViewHelper->getCustomerName($customer), + $storeId, + [ + 'delay' => $delay !== 0 ? $delay / 60 : 0, + 'customer' => $customer, + 'store' => $this->storeManager->getStore($storeId), + 'customer_data' => [ + 'customer_name' => $this->customerViewHelper->getCustomerName($customer), + ] + ] + ); } } diff --git a/Model/Customer/OrigDataRegistry.php b/Model/Customer/OrigDataRegistry.php index 668c253d..30a43149 100644 --- a/Model/Customer/OrigDataRegistry.php +++ b/Model/Customer/OrigDataRegistry.php @@ -9,7 +9,7 @@ use Magento\Customer\Api\Data\CustomerInterface; -final class OrigDataRegistry +class OrigDataRegistry { /** * @var CustomerInterface[] @@ -23,6 +23,6 @@ public function get(int $customerId): ?CustomerInterface public function set(CustomerInterface $customer): void { - $this->customers[(int) $customer->getId()] = $customer; + $this->customers[(int)$customer->getId()] = $customer; } } diff --git a/Model/Customer/SourceProvider/IdleFilterModifier.php b/Model/Customer/SourceProvider/IdleFilterModifier.php index 900a4996..9763c471 100644 --- a/Model/Customer/SourceProvider/IdleFilterModifier.php +++ b/Model/Customer/SourceProvider/IdleFilterModifier.php @@ -7,40 +7,46 @@ namespace Opengento\Gdpr\Model\Customer\SourceProvider; -use Magento\Framework\Api\Filter; -use Magento\Framework\Data\Collection; +use Exception; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Store\Api\Data\WebsiteInterface; +use Opengento\Gdpr\Model\Config\Entity\Erasure as ErasureConfig; use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface; -final class IdleFilterModifier implements ModifierInterface +class IdleFilterModifier implements ModifierInterface { - public function apply(Collection $collection, Filter $filter): void + public function __construct(private ErasureConfig $erasureConfig) {} + + /** + * @throws Exception + */ + public function apply(AbstractDb $collection, WebsiteInterface $website): void { - if ($collection instanceof Collection\AbstractDb && $filter->getField() === 'created_at') { - $connection = $collection->getConnection(); + $connection = $collection->getConnection(); - $visitorSelect = $connection->select() - ->from( - $connection->getTableName('customer_visitor'), - ['customer_id' => 'customer_id', 'last_visit_at' => 'MAX(last_visit_at)'] - ) - ->group(['customer_id']); + $visitorSelect = $connection->select() + ->from( + $connection->getTableName('customer_visitor'), + ['customer_id' => 'customer_id', 'last_visit_at' => 'MAX(last_visit_at)'] + ) + ->group(['customer_id']); - $collection->getSelect()->joinLeft( - ['cv' => $visitorSelect], - 'e.entity_id=cv.customer_id', - null - ); - $collection->getSelect()->joinLeft( - ['cl' => $connection->getTableName('customer_log')], - 'e.entity_id=cl.customer_id', - null - ); - $collection->getSelect()->where( - $connection->prepareSqlCondition( - 'IFNULL(cv.last_visit_at, GREATEST(IFNULL(cl.last_login_at, e.created_at), IFNULL(cl.last_logout_at, e.updated_at)))', - [$filter->getConditionType() => $filter->getValue()] - ) - ); - } + $collection->getSelect()->joinLeft( + ['cv' => $visitorSelect], + 'e.entity_id=cv.customer_id', + null + ); + $collection->addFieldToFilter('website_id', $website->getId()); + $collection->getSelect()->joinLeft( + ['cl' => $connection->getTableName('customer_log')], + 'e.entity_id=cl.customer_id', + null + ); + $collection->getSelect()->where( + $connection->prepareSqlCondition( + 'IFNULL(cv.last_visit_at, GREATEST(IFNULL(cl.last_login_at, e.created_at), IFNULL(cl.last_logout_at, e.updated_at)))', + ['lteq' => $this->erasureConfig->getEntityExpireDate($website->getId())] + ) + ); } } diff --git a/Model/Entity/DataCollector.php b/Model/Entity/DataCollector.php index f2017d3a..d496cb55 100644 --- a/Model/Entity/DataCollector.php +++ b/Model/Entity/DataCollector.php @@ -7,7 +7,7 @@ namespace Opengento\Gdpr\Model\Entity; -final class DataCollector implements DataCollectorInterface +class DataCollector implements DataCollectorInterface { /** * @var EntityIteratorInterface diff --git a/Model/Entity/DataCollectorGeneric.php b/Model/Entity/DataCollectorGeneric.php index dba4a675..cb7485fe 100644 --- a/Model/Entity/DataCollectorGeneric.php +++ b/Model/Entity/DataCollectorGeneric.php @@ -10,9 +10,10 @@ use Exception; use LogicException; use Magento\Framework\EntityManager\TypeResolver; + use function sprintf; -final class DataCollectorGeneric implements DataCollectorInterface +class DataCollectorGeneric implements DataCollectorInterface { private TypeResolver $typeResolver; diff --git a/Model/Entity/Document.php b/Model/Entity/Document.php index 46f75c30..10ca7c04 100644 --- a/Model/Entity/Document.php +++ b/Model/Entity/Document.php @@ -7,7 +7,7 @@ namespace Opengento\Gdpr\Model\Entity; -final class Document implements DocumentInterface +class Document implements DocumentInterface { private array $data; diff --git a/Model/Entity/EntityCheckerFactory.php b/Model/Entity/EntityCheckerFactory.php index b882345f..8b6053a6 100644 --- a/Model/Entity/EntityCheckerFactory.php +++ b/Model/Entity/EntityCheckerFactory.php @@ -9,12 +9,13 @@ use InvalidArgumentException; use Magento\Framework\ObjectManagerInterface; + use function sprintf; /** * @api */ -final class EntityCheckerFactory +class EntityCheckerFactory { /** * @var string[] diff --git a/Model/Entity/EntityIterator.php b/Model/Entity/EntityIterator.php index 46b3aef2..54671e89 100644 --- a/Model/Entity/EntityIterator.php +++ b/Model/Entity/EntityIterator.php @@ -11,7 +11,7 @@ use Magento\Framework\EntityManager\HydratorPool; use Magento\Framework\EntityManager\TypeResolver; -final class EntityIterator implements EntityIteratorInterface +class EntityIterator implements EntityIteratorInterface { private HydratorPool $hydratorPool; diff --git a/Model/Entity/EntityTypeList.php b/Model/Entity/EntityTypeList.php index 335657ec..026a3f00 100644 --- a/Model/Entity/EntityTypeList.php +++ b/Model/Entity/EntityTypeList.php @@ -13,7 +13,7 @@ /** * @api */ -final class EntityTypeList +class EntityTypeList { /** * @var string[][] diff --git a/Model/Entity/EntityTypeResolver.php b/Model/Entity/EntityTypeResolver.php index 65ee4bc3..02b1f393 100644 --- a/Model/Entity/EntityTypeResolver.php +++ b/Model/Entity/EntityTypeResolver.php @@ -13,7 +13,7 @@ /** * @api */ -final class EntityTypeResolver +class EntityTypeResolver { private TypeResolver $typeResolver; diff --git a/Model/Entity/EntityValue/CustomAttributesProcessor.php b/Model/Entity/EntityValue/CustomAttributesProcessor.php index 02a15b01..7e895c4f 100644 --- a/Model/Entity/EntityValue/CustomAttributesProcessor.php +++ b/Model/Entity/EntityValue/CustomAttributesProcessor.php @@ -9,9 +9,10 @@ use Magento\Framework\Api\CustomAttributesDataInterface; use Opengento\Gdpr\Model\Entity\EntityValueProcessorInterface; + use function is_iterable; -final class CustomAttributesProcessor implements EntityValueProcessorInterface +class CustomAttributesProcessor implements EntityValueProcessorInterface { private EntityValueProcessorInterface $processor; diff --git a/Model/Entity/EntityValue/ExtensibleDataProcessor.php b/Model/Entity/EntityValue/ExtensibleDataProcessor.php index 471f9130..c81234df 100644 --- a/Model/Entity/EntityValue/ExtensibleDataProcessor.php +++ b/Model/Entity/EntityValue/ExtensibleDataProcessor.php @@ -9,9 +9,10 @@ use Magento\Framework\Api\ExtensibleDataInterface; use Opengento\Gdpr\Model\Entity\EntityValueProcessorInterface; + use function is_iterable; -final class ExtensibleDataProcessor implements EntityValueProcessorInterface +class ExtensibleDataProcessor implements EntityValueProcessorInterface { private EntityValueProcessorInterface $processor; diff --git a/Model/Entity/EntityValue/StrategyProcessor.php b/Model/Entity/EntityValue/StrategyProcessor.php index c2782f82..01b1c966 100644 --- a/Model/Entity/EntityValue/StrategyProcessor.php +++ b/Model/Entity/EntityValue/StrategyProcessor.php @@ -9,7 +9,7 @@ use Opengento\Gdpr\Model\Entity\EntityValueProcessorInterface; -final class StrategyProcessor implements EntityValueProcessorInterface +class StrategyProcessor implements EntityValueProcessorInterface { /** * @var EntityValueProcessorInterface[] diff --git a/Model/Entity/Metadata.php b/Model/Entity/Metadata.php index 75689677..5adb7fc4 100644 --- a/Model/Entity/Metadata.php +++ b/Model/Entity/Metadata.php @@ -8,9 +8,10 @@ namespace Opengento\Gdpr\Model\Entity; use Magento\Framework\App\Config\ScopeConfigInterface; + use function explode; -final class Metadata implements MetadataInterface +class Metadata implements MetadataInterface { private ScopeConfigInterface $scopeConfig; diff --git a/Model/Entity/SourceProvider/ExpireFilterModifier.php b/Model/Entity/SourceProvider/ExpireFilterModifier.php new file mode 100644 index 00000000..1a5c5bbb --- /dev/null +++ b/Model/Entity/SourceProvider/ExpireFilterModifier.php @@ -0,0 +1,32 @@ +addFieldToFilter( + $this->fieldToFilter, + ['lteq' => $this->erasureConfig->getEntityExpireDate($website->getId())] + ); + } +} diff --git a/Model/Entity/SourceProvider/FilterModifier.php b/Model/Entity/SourceProvider/FilterModifier.php deleted file mode 100644 index 826732d3..00000000 --- a/Model/Entity/SourceProvider/FilterModifier.php +++ /dev/null @@ -1,41 +0,0 @@ -filterIdentifier = $filterIdentifier; - $this->fieldToFilter = $fieldToFilter; - } - - /** - * @inheritdoc - * @throws LocalizedException - */ - public function apply(Collection $collection, Filter $filter): void - { - if ($filter->getField() === $this->filterIdentifier) { - $collection->addFieldToFilter( - $this->fieldToFilter, - [$filter->getConditionType() => $filter->getValue()] - ); - } - } -} diff --git a/Model/Entity/SourceProvider/ModifierComposite.php b/Model/Entity/SourceProvider/ModifierComposite.php index a6987240..dc8ebf2b 100644 --- a/Model/Entity/SourceProvider/ModifierComposite.php +++ b/Model/Entity/SourceProvider/ModifierComposite.php @@ -7,29 +7,20 @@ namespace Opengento\Gdpr\Model\Entity\SourceProvider; -use Magento\Framework\Api\Filter; -use Magento\Framework\Data\Collection; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Store\Api\Data\WebsiteInterface; /** * @api */ -final class ModifierComposite implements ModifierInterface +class ModifierComposite implements ModifierInterface { - /** - * @var ModifierInterface[] - */ - private array $modifiers; + public function __construct(private array $modifiers = []) {} - public function __construct( - array $modifiers - ) { - $this->modifiers = $modifiers; - } - - public function apply(Collection $collection, Filter $filter): void + public function apply(AbstractDb $collection, WebsiteInterface $website): void { foreach ($this->modifiers as $modifier) { - $modifier->apply($collection, $filter); + $modifier->apply($collection, $website); } } } diff --git a/Model/Entity/SourceProvider/ModifierFactory.php b/Model/Entity/SourceProvider/ModifierFactory.php index c31dfa49..f49c1991 100644 --- a/Model/Entity/SourceProvider/ModifierFactory.php +++ b/Model/Entity/SourceProvider/ModifierFactory.php @@ -12,7 +12,7 @@ /** * @api */ -final class ModifierFactory +class ModifierFactory { /** * @var string[] diff --git a/Model/Entity/SourceProvider/ModifierInterface.php b/Model/Entity/SourceProvider/ModifierInterface.php index dcf49935..eb940cfc 100644 --- a/Model/Entity/SourceProvider/ModifierInterface.php +++ b/Model/Entity/SourceProvider/ModifierInterface.php @@ -7,13 +7,13 @@ namespace Opengento\Gdpr\Model\Entity\SourceProvider; -use Magento\Framework\Api\Filter; -use Magento\Framework\Data\Collection; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Store\Api\Data\WebsiteInterface; /** * @api */ interface ModifierInterface { - public function apply(Collection $collection, Filter $filter): void; + public function apply(AbstractDb $collection, WebsiteInterface $website): void; } diff --git a/Model/Entity/SourceProvider/NotErasedFilterModifier.php b/Model/Entity/SourceProvider/NotErasedFilterModifier.php index 8f147535..96ceca86 100644 --- a/Model/Entity/SourceProvider/NotErasedFilterModifier.php +++ b/Model/Entity/SourceProvider/NotErasedFilterModifier.php @@ -7,46 +7,32 @@ namespace Opengento\Gdpr\Model\Entity\SourceProvider; -use Magento\Framework\Api\Filter; -use Magento\Framework\Data\Collection; use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Store\Api\Data\WebsiteInterface; + use function sprintf; -final class NotErasedFilterModifier implements ModifierInterface +class NotErasedFilterModifier implements ModifierInterface { private const DEFAULT_PRIMARY_FIELD = 'entity_id'; - private const DEFAULT_MAIN_TABLE_ALIAS = 'main_table'; - private const JOIN_ON = '%s.%s=ogee.entity_id AND ogee.entity_type="%s"'; - private string $entityType; - - private string $entityPrimaryField; - - private string $mainTableAlias; - public function __construct( - string $entityType, - string $entityPrimaryField = self::DEFAULT_PRIMARY_FIELD, - string $mainTableAlias = self::DEFAULT_MAIN_TABLE_ALIAS - ) { - $this->entityType = $entityType; - $this->entityPrimaryField = $entityPrimaryField; - $this->mainTableAlias = $mainTableAlias; - } + private string $entityType, + private string $entityPrimaryField = self::DEFAULT_PRIMARY_FIELD, + private string $mainTableAlias = self::DEFAULT_MAIN_TABLE_ALIAS + ) {} - public function apply(Collection $collection, Filter $filter): void + public function apply(AbstractDb $collection, WebsiteInterface $website): void { - if ($collection instanceof AbstractDb) { - $connection = $collection->getConnection(); - $select = $collection->getSelect(); - $select->joinLeft( - ['ogee' => $connection->getTableName('opengento_gdpr_erase_entity')], - sprintf(self::JOIN_ON, $this->mainTableAlias, $this->entityPrimaryField, $this->entityType), - [''] - ); - $select->where('ogee.erase_id IS NULL'); - } + $connection = $collection->getConnection(); + $select = $collection->getSelect(); + $select->joinLeft( + ['ogee' => $connection->getTableName('opengento_gdpr_erase_entity')], + sprintf(self::JOIN_ON, $this->mainTableAlias, $this->entityPrimaryField, $this->entityType), + [''] + ); + $select->where('ogee.erase_id IS NULL'); } } diff --git a/Model/Entity/SourceProviderFactory.php b/Model/Entity/SourceProviderFactory.php index f74035b6..02ce18b5 100644 --- a/Model/Entity/SourceProviderFactory.php +++ b/Model/Entity/SourceProviderFactory.php @@ -8,35 +8,25 @@ namespace Opengento\Gdpr\Model\Entity; use InvalidArgumentException; -use Magento\Framework\Data\Collection; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\ObjectManagerInterface; + use function sprintf; /** * @api */ -final class SourceProviderFactory +class SourceProviderFactory { - /** - * @var string[] - */ - private array $sourceProviders; - - private ObjectManagerInterface $objectManager; - /** * @param string[] $sourceProviders - * @param ObjectManagerInterface $objectManager */ public function __construct( - array $sourceProviders, - ObjectManagerInterface $objectManager - ) { - $this->sourceProviders = $sourceProviders; - $this->objectManager = $objectManager; - } + private array $sourceProviders, + private ObjectManagerInterface $objectManager + ) {} - public function create(string $entityType): Collection + public function create(string $entityType): AbstractDb { if (!isset($this->sourceProviders[$entityType])) { throw new InvalidArgumentException(sprintf('Unknown source provider for entity type "%s".', $entityType)); diff --git a/Model/Erase/EraseEntityScheduler.php b/Model/Erase/EraseEntityScheduler.php index f06bb163..53498bfa 100644 --- a/Model/Erase/EraseEntityScheduler.php +++ b/Model/Erase/EraseEntityScheduler.php @@ -8,60 +8,47 @@ namespace Opengento\Gdpr\Model\Erase; use Generator; -use Magento\Framework\Api\Filter; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; +use Magento\Store\Api\Data\WebsiteInterface; use Opengento\Gdpr\Api\EraseEntityManagementInterface; use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierFactory; use Opengento\Gdpr\Model\Entity\SourceProviderFactory; -final class EraseEntityScheduler +class EraseEntityScheduler { - private SourceProviderFactory $srcProviderFactory; - - private ModifierFactory $modifierFactory; - - private EraseEntityManagementInterface $eraseManagement; - public function __construct( - SourceProviderFactory $srcProviderFactory, - ModifierFactory $modifierFactory, - EraseEntityManagementInterface $eraseManagement - ) { - $this->srcProviderFactory = $srcProviderFactory; - $this->modifierFactory = $modifierFactory; - $this->eraseManagement = $eraseManagement; - } + private SourceProviderFactory $srcProviderFactory, + private ModifierFactory $modifierFactory, + private EraseEntityManagementInterface $eraseManagement + ) {} /** * @param string[] $entityTypes - * @param Filter $filter * @throws CouldNotSaveException * @throws LocalizedException */ - public function schedule(array $entityTypes, Filter $filter): void + public function schedule(array $entityTypes, WebsiteInterface $website): void { /** * @var string $entityType * @var string[] $entityIds */ - foreach ($this->collectEntityIds($entityTypes, $filter) as $entityType => $entityIds) { + foreach ($this->collectEntityIds($entityTypes, $website) as $entityType => $entityIds) { foreach ($entityIds as $entityId) { - $this->eraseManagement->create((int) $entityId, $entityType); + $this->eraseManagement->create((int)$entityId, $entityType); } } } /** * @param string[] $entityTypes - * @param Filter $filter - * @return Generator */ - private function collectEntityIds(array $entityTypes, Filter $filter): Generator + private function collectEntityIds(array $entityTypes, WebsiteInterface $website): Generator { foreach ($entityTypes as $entityType) { $source = $this->srcProviderFactory->create($entityType); - $this->modifierFactory->get($entityType)->apply($source, $filter); + $this->modifierFactory->get($entityType)->apply($source, $website); yield $entityType => $source->getAllIds(); } diff --git a/Model/Erase/EraseSalesInformation.php b/Model/Erase/EraseSalesInformation.php index afc69a28..a924e970 100644 --- a/Model/Erase/EraseSalesInformation.php +++ b/Model/Erase/EraseSalesInformation.php @@ -8,43 +8,32 @@ namespace Opengento\Gdpr\Model\Erase; use DateTimeImmutable; +use DateTimeInterface; use Exception; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Stdlib\DateTime; -use Magento\Store\Model\ScopeInterface; use Opengento\Gdpr\Api\Data\EraseEntityInterface; use Opengento\Gdpr\Api\Data\EraseEntityInterfaceFactory; use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; use Opengento\Gdpr\Api\EraseSalesInformationInterface; -final class EraseSalesInformation implements EraseSalesInformationInterface +class EraseSalesInformation implements EraseSalesInformationInterface { private const CONFIG_PATH_ERASURE_SALES_MAX_AGE = 'gdpr/erasure/sales_max_age'; - private EraseEntityInterfaceFactory $eraseEntityFactory; - - private EraseEntityRepositoryInterface $eraseRepository; - - private ScopeConfigInterface $scopeConfig; - public function __construct( - EraseEntityInterfaceFactory $eraseEntityFactory, - EraseEntityRepositoryInterface $eraseRepository, - ScopeConfigInterface $scopeConfig - ) { - $this->eraseEntityFactory = $eraseEntityFactory; - $this->eraseRepository = $eraseRepository; - $this->scopeConfig = $scopeConfig; - } + private EraseEntityInterfaceFactory $eraseEntityFactory, + private EraseEntityRepositoryInterface $eraseRepository, + private ScopeConfigInterface $scopeConfig + ) {} /** - * @inheritdoc * @throws CouldNotSaveException */ - public function scheduleEraseEntity(int $entityId, string $entityType, \DateTime $lastActive): EraseEntityInterface + public function scheduleEraseEntity(int $entityId, string $entityType, DateTimeInterface $lastActive): EraseEntityInterface { - $dateTime = DateTimeImmutable::createFromMutable($lastActive); + $dateTime = DateTimeImmutable::createFromInterface($lastActive); $scheduleAt = $dateTime->modify('+' . $this->resolveErasureSalesMaxAge() . ' days'); /** @var EraseEntityInterface $eraseEntity */ @@ -61,16 +50,15 @@ public function scheduleEraseEntity(int $entityId, string $entityType, \DateTime } /** - * @inheritdoc * @throws Exception */ - public function isAlive(\DateTime $dateTime): bool + public function isAlive(DateTimeInterface $lastActive): bool { - return $dateTime > new \DateTime('-' . $this->resolveErasureSalesMaxAge() . 'days'); + return $lastActive > new \DateTime('-' . $this->resolveErasureSalesMaxAge() . 'days'); } private function resolveErasureSalesMaxAge(): int { - return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_SALES_MAX_AGE, ScopeInterface::SCOPE_STORE); + return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_SALES_MAX_AGE); } } diff --git a/Model/Erase/NotifierRepository.php b/Model/Erase/NotifierRepository.php new file mode 100644 index 00000000..f46c6bfb --- /dev/null +++ b/Model/Erase/NotifierRepository.php @@ -0,0 +1,34 @@ +notifiers[$action][$entityType] ?? throw $this->createException($entityType, $action); + } + + private function createException(string $entityType, string $action): NoSuchEntityException + { + return new NoSuchEntityException( + new Phrase('No such notifier for entity type "' . $entityType . '" and action "' . $action . '"') + ); + } +} diff --git a/Model/Erase/NotifyEraseEntityManagement.php b/Model/Erase/NotifyEraseEntityManagement.php new file mode 100644 index 00000000..448ac41f --- /dev/null +++ b/Model/Erase/NotifyEraseEntityManagement.php @@ -0,0 +1,48 @@ +eraseManagement->create($entityId, $entityType); + $this->notifierRepository->get($entityType, 'pending')->notify($eraseEntity); + + return $eraseEntity; + } + + public function cancel(int $entityId, string $entityType): bool + { + $eraseEntity = $this->eraseRepository->getByEntity($entityId, $entityType); + $canceled = $this->eraseManagement->cancel($entityId, $entityType); + if ($canceled) { + $this->notifierRepository->get($entityType, 'cancel')->notify($eraseEntity); + } + + return $canceled; + } + + public function process(EraseEntityInterface $entity): EraseEntityInterface + { + $eraseEntity = $this->eraseManagement->process($entity); + $this->notifierRepository->get($entity->getEntityType(), 'success')->notify($eraseEntity); + + return $eraseEntity; + } +} diff --git a/Model/Erase/SecureEraseEntityManagement.php b/Model/Erase/SecureEraseEntityManagement.php index f17dfb0c..cc71bf0d 100644 --- a/Model/Erase/SecureEraseEntityManagement.php +++ b/Model/Erase/SecureEraseEntityManagement.php @@ -13,19 +13,12 @@ use Opengento\Gdpr\Api\EraseEntityCheckerInterface; use Opengento\Gdpr\Api\EraseEntityManagementInterface; -final class SecureEraseEntityManagement implements EraseEntityManagementInterface +class SecureEraseEntityManagement implements EraseEntityManagementInterface { - private EraseEntityManagementInterface $eraseManagement; - - private EraseEntityCheckerInterface $eraseEntityChecker; - public function __construct( - EraseEntityManagementInterface $eraseManagement, - EraseEntityCheckerInterface $eraseEntityChecker - ) { - $this->eraseManagement = $eraseManagement; - $this->eraseEntityChecker = $eraseEntityChecker; - } + private EraseEntityManagementInterface $eraseManagement, + private EraseEntityCheckerInterface $eraseEntityChecker + ) {} public function create(int $entityId, string $entityType): EraseEntityInterface { diff --git a/Model/EraseEntity.php b/Model/EraseEntity.php index 55433d25..38e1660f 100755 --- a/Model/EraseEntity.php +++ b/Model/EraseEntity.php @@ -22,7 +22,7 @@ protected function _construct(): void public function getEraseId(): int { - return (int) $this->getId(); + return (int)$this->getId(); } public function setEraseId(int $eraseId): EraseEntityInterface @@ -32,7 +32,7 @@ public function setEraseId(int $eraseId): EraseEntityInterface public function getEntityId(): int { - return (int) $this->_getData(self::ENTITY_ID); + return (int)$this->_getData(self::ENTITY_ID); } public function setEntityId($entityId): EraseEntityInterface @@ -42,7 +42,7 @@ public function setEntityId($entityId): EraseEntityInterface public function getEntityType(): string { - return (string) $this->_getData(self::ENTITY_TYPE); + return (string)$this->_getData(self::ENTITY_TYPE); } public function setEntityType(string $entityType): EraseEntityInterface @@ -52,7 +52,7 @@ public function setEntityType(string $entityType): EraseEntityInterface public function getScheduledAt(): string { - return (string) $this->_getData(self::SCHEDULED_AT); + return (string)$this->_getData(self::SCHEDULED_AT); } public function setScheduledAt(string $scheduledAt): EraseEntityInterface @@ -62,7 +62,7 @@ public function setScheduledAt(string $scheduledAt): EraseEntityInterface public function getState(): string { - return (string) $this->_getData(self::STATE); + return (string)$this->_getData(self::STATE); } public function setState(string $state): EraseEntityInterface @@ -72,7 +72,7 @@ public function setState(string $state): EraseEntityInterface public function getStatus(): string { - return (string) $this->_getData(self::STATUS); + return (string)$this->_getData(self::STATUS); } public function setStatus(string $status): EraseEntityInterface @@ -82,7 +82,7 @@ public function setStatus(string $status): EraseEntityInterface public function getMessage(): ?string { - return $this->_getData(self::MESSAGE) === null ? null : (string) $this->_getData(self::MESSAGE); + return $this->_getData(self::MESSAGE) === null ? null : (string)$this->_getData(self::MESSAGE); } public function setMessage(?string $message): EraseEntityInterface @@ -92,7 +92,7 @@ public function setMessage(?string $message): EraseEntityInterface public function getErasedAt(): string { - return (string) $this->_getData(self::ERASED_AT); + return (string)$this->_getData(self::ERASED_AT); } public function setErasedAt(string $erasedAt): EraseEntityInterface diff --git a/Model/EraseEntityChecker.php b/Model/EraseEntityChecker.php index 4f5de130..0a3d170f 100644 --- a/Model/EraseEntityChecker.php +++ b/Model/EraseEntityChecker.php @@ -13,7 +13,7 @@ use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; use Opengento\Gdpr\Model\Entity\EntityCheckerFactory; -final class EraseEntityChecker implements EraseEntityCheckerInterface +class EraseEntityChecker implements EraseEntityCheckerInterface { private EraseEntityRepositoryInterface $eraseRepository; @@ -33,8 +33,8 @@ public function __construct( public function exists(int $entityId, string $entityType): bool { try { - return (bool) $this->eraseRepository->getByEntity($entityId, $entityType)->getEraseId(); - } catch (NoSuchEntityException $e) { + return (bool)$this->eraseRepository->getByEntity($entityId, $entityType)->getEraseId(); + } catch (NoSuchEntityException) { return false; } } @@ -50,7 +50,7 @@ public function canCancel(int $entityId, string $entityType): bool { try { $entity = $this->eraseRepository->getByEntity($entityId, $entityType); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { return false; } @@ -62,7 +62,7 @@ public function canProcess(int $entityId, string $entityType): bool { try { $entity = $this->eraseRepository->getByEntity($entityId, $entityType); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { return false; } $entityChecker = $this->entityCheckerFactory->get($entityType); diff --git a/Model/EraseEntityManagement.php b/Model/EraseEntityManagement.php index 2c4b8526..879413b3 100644 --- a/Model/EraseEntityManagement.php +++ b/Model/EraseEntityManagement.php @@ -8,46 +8,27 @@ namespace Opengento\Gdpr\Model; use Exception; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Phrase; use Magento\Framework\Stdlib\DateTime as DateTimeFormat; use Magento\Framework\Stdlib\DateTime\DateTime; -use Magento\Store\Model\ScopeInterface; use Opengento\Gdpr\Api\Data\EraseEntityInterface; use Opengento\Gdpr\Api\Data\EraseEntityInterfaceFactory; use Opengento\Gdpr\Api\EraseEntityManagementInterface; use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; +use Opengento\Gdpr\Model\Config\Entity\Erasure; use Opengento\Gdpr\Service\Erase\ProcessorFactory; -final class EraseEntityManagement implements EraseEntityManagementInterface +class EraseEntityManagement implements EraseEntityManagementInterface { - private const CONFIG_PATH_ERASURE_DELAY = 'gdpr/erasure/delay'; - - private EraseEntityInterfaceFactory $eraseEntityFactory; - - private EraseEntityRepositoryInterface $eraseRepository; - - private ProcessorFactory $processorFactory; - - private ScopeConfigInterface $scopeConfig; - - private DateTime $localeDate; - public function __construct( - EraseEntityInterfaceFactory $eraseEntityFactory, - EraseEntityRepositoryInterface $eraseRepository, - ProcessorFactory $processorFactory, - ScopeConfigInterface $scopeConfig, - DateTime $localeDate - ) { - $this->eraseEntityFactory = $eraseEntityFactory; - $this->eraseRepository = $eraseRepository; - $this->processorFactory = $processorFactory; - $this->scopeConfig = $scopeConfig; - $this->localeDate = $localeDate; - } + private Erasure $erasureConfig, + private EraseEntityInterfaceFactory $eraseEntityFactory, + private EraseEntityRepositoryInterface $eraseRepository, + private ProcessorFactory $processorFactory, + private DateTime $localeDate + ) {} public function create(int $entityId, string $entityType): EraseEntityInterface { @@ -57,7 +38,7 @@ public function create(int $entityId, string $entityType): EraseEntityInterface $entity->setEntityType($entityType); $entity->setState(EraseEntityInterface::STATE_PENDING); $entity->setStatus(EraseEntityInterface::STATUS_READY); - $entity->setScheduledAt($this->retrieveScheduledAt()); + $entity->setScheduledAt($this->createScheduledAt()); return $this->eraseRepository->save($entity); } @@ -83,8 +64,6 @@ public function process(EraseEntityInterface $entity): EraseEntityInterface } /** - * @param EraseEntityInterface $entity - * @return EraseEntityInterface * @throws CouldNotSaveException */ private function success(EraseEntityInterface $entity): EraseEntityInterface @@ -98,9 +77,6 @@ private function success(EraseEntityInterface $entity): EraseEntityInterface } /** - * @param EraseEntityInterface $entity - * @param string|null $message [optional] - * @return EraseEntityInterface * @throws CouldNotSaveException */ private function fail(EraseEntityInterface $entity, ?string $message = null): EraseEntityInterface @@ -112,16 +88,11 @@ private function fail(EraseEntityInterface $entity, ?string $message = null): Er return $this->eraseRepository->save($entity); } - private function retrieveScheduledAt(): string + private function createScheduledAt(): string { return $this->localeDate->gmtDate( DateTimeFormat::DATETIME_PHP_FORMAT, - $this->resolveErasureDelay() * 60 + $this->localeDate->gmtTimestamp() + $this->erasureConfig->getDelay() * 60 + $this->localeDate->gmtTimestamp() ); } - - private function resolveErasureDelay(): int - { - return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE); - } } diff --git a/Model/EraseEntityRepository.php b/Model/EraseEntityRepository.php index a1438bbc..8ae7a30d 100644 --- a/Model/EraseEntityRepository.php +++ b/Model/EraseEntityRepository.php @@ -24,7 +24,7 @@ use Opengento\Gdpr\Model\ResourceModel\EraseEntity\Collection; use Opengento\Gdpr\Model\ResourceModel\EraseEntity\CollectionFactory; -final class EraseEntityRepository implements EraseEntityRepositoryInterface +class EraseEntityRepository implements EraseEntityRepositoryInterface { /** * @var EraseEntityResource diff --git a/Model/Export/ExportEntityData.php b/Model/Export/ExportEntityData.php index 35ae00df..9a382a43 100644 --- a/Model/Export/ExportEntityData.php +++ b/Model/Export/ExportEntityData.php @@ -19,7 +19,7 @@ /** * @api */ -final class ExportEntityData +class ExportEntityData { private ExportEntityRepositoryInterface $exportRepository; diff --git a/Model/Export/ExportToFile.php b/Model/Export/ExportToFile.php index 7e4b8ee6..e59ff1a7 100644 --- a/Model/Export/ExportToFile.php +++ b/Model/Export/ExportToFile.php @@ -16,37 +16,24 @@ use Opengento\Gdpr\Model\Archive\ArchiveManager; use Opengento\Gdpr\Service\Export\ProcessorFactory; use Opengento\Gdpr\Service\Export\RendererFactory; + use function explode; use function sha1; + use const DIRECTORY_SEPARATOR; -final class ExportToFile +class ExportToFile { private const CONFIG_PATH_EXPORT_RENDERERS = 'gdpr/export/renderers'; - private ProcessorFactory $processorFactory; - - private RendererFactory $rendererFactory; - - private ArchiveManager $archiveManager; - - private ScopeConfigInterface $scopeConfig; - public function __construct( - ProcessorFactory $processorFactory, - RendererFactory $rendererFactory, - ArchiveManager $archiveManager, - ScopeConfigInterface $scopeConfig - ) { - $this->processorFactory = $processorFactory; - $this->rendererFactory = $rendererFactory; - $this->archiveManager = $archiveManager; - $this->scopeConfig = $scopeConfig; - } + private ProcessorFactory $processorFactory, + private RendererFactory $rendererFactory, + private ArchiveManager $archiveManager, + private ScopeConfigInterface $scopeConfig + ) {} /** - * @param ExportEntityInterface $exportEntity - * @return string|null * @throws FileSystemException * @throws NotFoundException * @throws NoSuchEntityException @@ -69,9 +56,9 @@ public function export(ExportEntityInterface $exportEntity): string public function resolveExportRendererCodes(): array { - return explode(',', (string) $this->scopeConfig->getValue( + return explode(',', (string)$this->scopeConfig->getValue( self::CONFIG_PATH_EXPORT_RENDERERS, - ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_WEBSITE )); } diff --git a/Model/Export/NotifierRepository.php b/Model/Export/NotifierRepository.php new file mode 100644 index 00000000..37aef550 --- /dev/null +++ b/Model/Export/NotifierRepository.php @@ -0,0 +1,34 @@ +notifiers[$action][$entityType] ?? throw $this->createException($entityType, $action); + } + + private function createException(string $entityType, string $action): NoSuchEntityException + { + return new NoSuchEntityException( + new Phrase('No such notifier for entity type "' . $entityType . '" and action "' . $action . '"') + ); + } +} diff --git a/Model/Export/NotifyExportEntityManagement.php b/Model/Export/NotifyExportEntityManagement.php new file mode 100644 index 00000000..8e5b0422 --- /dev/null +++ b/Model/Export/NotifyExportEntityManagement.php @@ -0,0 +1,41 @@ +exportManagement->create($entityId, $entityType, $fileName); + $this->notifierRepository->get($entityType, 'pending')->notify($exportEntity); + + return $exportEntity; + } + + public function export(ExportEntityInterface $exportEntity): ExportEntityInterface + { + $exportEntity = $this->exportManagement->export($exportEntity); + $this->notifierRepository->get($exportEntity->getEntityType(), 'ready')->notify($exportEntity); + + + return $exportEntity; + } + + public function invalidate(ExportEntityInterface $exportEntity): ExportEntityInterface + { + return $this->exportManagement->invalidate($exportEntity); + } +} diff --git a/Model/ExportEntity.php b/Model/ExportEntity.php index 4af187fb..a84f1e41 100644 --- a/Model/ExportEntity.php +++ b/Model/ExportEntity.php @@ -22,7 +22,7 @@ protected function _construct(): void public function getExportId(): int { - return (int) $this->getId(); + return (int)$this->getId(); } public function setExportId(int $exportId): ExportEntityInterface @@ -32,7 +32,7 @@ public function setExportId(int $exportId): ExportEntityInterface public function getEntityId(): int { - return (int) $this->_getData(self::ENTITY_ID); + return (int)$this->_getData(self::ENTITY_ID); } public function setEntityId($entityId): ExportEntityInterface @@ -42,7 +42,7 @@ public function setEntityId($entityId): ExportEntityInterface public function getEntityType(): string { - return (string) $this->_getData(self::ENTITY_TYPE); + return (string)$this->_getData(self::ENTITY_TYPE); } public function setEntityType(string $entityType): ExportEntityInterface @@ -52,7 +52,7 @@ public function setEntityType(string $entityType): ExportEntityInterface public function getFileName(): string { - return (string) $this->_getData(self::FILE_NAME); + return (string)$this->_getData(self::FILE_NAME); } public function setFileName(string $filename): ExportEntityInterface @@ -62,7 +62,7 @@ public function setFileName(string $filename): ExportEntityInterface public function getFilePath(): ?string { - return $this->_getData(self::FILE_PATH) === null ? null : (string) $this->_getData(self::FILE_PATH); + return $this->_getData(self::FILE_PATH) === null ? null : (string)$this->_getData(self::FILE_PATH); } public function setFilePath(?string $filePath): ExportEntityInterface @@ -72,7 +72,7 @@ public function setFilePath(?string $filePath): ExportEntityInterface public function getCreatedAt(): string { - return (string) $this->_getData(self::CREATED_AT); + return (string)$this->_getData(self::CREATED_AT); } public function setCreatedAt(string $createdAt): ExportEntityInterface @@ -82,7 +82,7 @@ public function setCreatedAt(string $createdAt): ExportEntityInterface public function getExportedAt(): ?string { - return $this->_getData(self::EXPORTED_AT) === null ? null : (string) $this->_getData(self::EXPORTED_AT); + return $this->_getData(self::EXPORTED_AT) === null ? null : (string)$this->_getData(self::EXPORTED_AT); } public function setExportedAt(string $exportedAt): ExportEntityInterface @@ -92,7 +92,7 @@ public function setExportedAt(string $exportedAt): ExportEntityInterface public function getExpiredAt(): string { - return (string) $this->_getData(self::EXPIRED_AT); + return (string)$this->_getData(self::EXPIRED_AT); } public function setExpiredAt(string $expiredAt): ExportEntityInterface diff --git a/Model/ExportEntityChecker.php b/Model/ExportEntityChecker.php index f274160c..ec45d2f8 100644 --- a/Model/ExportEntityChecker.php +++ b/Model/ExportEntityChecker.php @@ -11,7 +11,7 @@ use Opengento\Gdpr\Api\ExportEntityCheckerInterface; use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; -final class ExportEntityChecker implements ExportEntityCheckerInterface +class ExportEntityChecker implements ExportEntityCheckerInterface { private ExportEntityRepositoryInterface $exportRepository; @@ -24,7 +24,7 @@ public function __construct( public function exists(int $entityId, string $entityType): bool { try { - return (bool) $this->exportRepository->getByEntity($entityId, $entityType)->getExportId(); + return (bool)$this->exportRepository->getByEntity($entityId, $entityType)->getExportId(); } catch (NoSuchEntityException $e) { return false; } diff --git a/Model/ExportEntityManagement.php b/Model/ExportEntityManagement.php index 50739254..08c1b937 100644 --- a/Model/ExportEntityManagement.php +++ b/Model/ExportEntityManagement.php @@ -8,7 +8,6 @@ namespace Opengento\Gdpr\Model; use DateTime; -use Exception; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\AlreadyExistsException; use Magento\Framework\Phrase; @@ -21,37 +20,18 @@ use Opengento\Gdpr\Api\ExportEntityRepositoryInterface; use Opengento\Gdpr\Model\Export\ExportToFile; -final class ExportEntityManagement implements ExportEntityManagementInterface +class ExportEntityManagement implements ExportEntityManagementInterface { private const CONFIG_PATH_EXPORT_FILE_NAME = 'gdpr/export/file_name'; private const CONFIG_PATH_EXPORT_LIFE_TIME = 'gdpr/export/life_time'; - private ExportEntityInterfaceFactory $exportEntityFactory; - - private ExportEntityRepositoryInterface $exportRepository; - - private ExportEntityCheckerInterface $exportEntityChecker; - - /** - * @var ExportToFile - */ - private ExportToFile $exportToFile; - - private ScopeConfigInterface $scopeConfig; - public function __construct( - ExportEntityInterfaceFactory $exportEntityFactory, - ExportEntityRepositoryInterface $exportRepository, - ExportEntityCheckerInterface $exportEntityChecker, - ExportToFile $exportToFile, - ScopeConfigInterface $scopeConfig - ) { - $this->exportEntityFactory = $exportEntityFactory; - $this->exportRepository = $exportRepository; - $this->exportEntityChecker = $exportEntityChecker; - $this->exportToFile = $exportToFile; - $this->scopeConfig = $scopeConfig; - } + private ExportEntityInterfaceFactory $exportEntityFactory, + private ExportEntityRepositoryInterface $exportRepository, + private ExportEntityCheckerInterface $exportEntityChecker, + private ExportToFile $exportToFile, + private ScopeConfigInterface $scopeConfig + ) {} public function create(int $entityId, string $entityType, ?string $fileName = null): ExportEntityInterface { @@ -69,26 +49,20 @@ public function create(int $entityId, string $entityType, ?string $fileName = nu $exportEntity->setEntityId($entityId); $exportEntity->setEntityType($entityType); $exportEntity->setFileName($fileName ?? $this->resolveDefaultFileName()); - $exportEntity = $this->exportRepository->save($exportEntity); - return $exportEntity; + return $this->exportRepository->save($exportEntity); } - /** - * @inheritdoc - * @throws Exception - */ public function export(ExportEntityInterface $exportEntity): ExportEntityInterface { - $lifeTime = (int) $this->scopeConfig->getValue(self::CONFIG_PATH_EXPORT_LIFE_TIME, ScopeInterface::SCOPE_STORE); + $lifeTime = (int)$this->scopeConfig->getValue(self::CONFIG_PATH_EXPORT_LIFE_TIME); $exportEntity->setFilePath($this->exportToFile->export($exportEntity)); $exportEntity->setExpiredAt( (new DateTime('+' . $lifeTime . 'minutes'))->format(DateTimeFormat::DATETIME_PHP_FORMAT) ); $exportEntity->setExportedAt((new DateTime())->format(DateTimeFormat::DATETIME_PHP_FORMAT)); - $this->exportRepository->save($exportEntity); - return $exportEntity; + return $this->exportRepository->save($exportEntity); } public function invalidate(ExportEntityInterface $exportEntity): ExportEntityInterface @@ -100,6 +74,6 @@ public function invalidate(ExportEntityInterface $exportEntity): ExportEntityInt private function resolveDefaultFileName(): string { - return (string) $this->scopeConfig->getValue(self::CONFIG_PATH_EXPORT_FILE_NAME, ScopeInterface::SCOPE_STORE); + return (string)$this->scopeConfig->getValue(self::CONFIG_PATH_EXPORT_FILE_NAME, ScopeInterface::SCOPE_STORE); } } diff --git a/Model/ExportEntityRepository.php b/Model/ExportEntityRepository.php index f8e37897..cd798436 100644 --- a/Model/ExportEntityRepository.php +++ b/Model/ExportEntityRepository.php @@ -26,7 +26,7 @@ use Opengento\Gdpr\Model\ResourceModel\ExportEntity\Collection; use Opengento\Gdpr\Model\ResourceModel\ExportEntity\CollectionFactory; -final class ExportEntityRepository implements ExportEntityRepositoryInterface +class ExportEntityRepository implements ExportEntityRepositoryInterface { private ExportEntityResource $exportEntityResource; diff --git a/Model/Newsletter/Subscriber.php b/Model/Newsletter/Subscriber.php index a5f82208..cf75368c 100644 --- a/Model/Newsletter/Subscriber.php +++ b/Model/Newsletter/Subscriber.php @@ -11,12 +11,12 @@ use Magento\Newsletter\Model\SubscriberFactory; /** - * `\Opengento\Gdpr\Model\Newsletter\Subscriber` class is the final state of `\Magento\Newsletter\Model\Subscriber`. + * `\Opengento\Gdpr\Model\Newsletter\Subscriber` class is the state of `\Magento\Newsletter\Model\Subscriber`. * * @method SubscriberModel loadByCustomerId(int $customerId) * @method SubscriberModel loadByEmail(string $email) */ -final class Subscriber +class Subscriber { private $subscriber; diff --git a/Model/Notifier/AbstractMailSender.php b/Model/Notifier/AbstractMailSender.php index 3018b0fa..c349b26a 100644 --- a/Model/Notifier/AbstractMailSender.php +++ b/Model/Notifier/AbstractMailSender.php @@ -13,39 +13,23 @@ use Magento\Framework\Exception\MailException; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Store\Model\ScopeInterface; + use function explode; abstract class AbstractMailSender { - protected TransportBuilder $transportBuilder; - - private ScopeConfigInterface $scopeConfig; - - /** - * @var string[] - */ - private array $configPaths; + private const CONFIG_PATH_ENABLED = 'gdpr/notification/enabled'; /** - * @param TransportBuilder $transportBuilder - * @param ScopeConfigInterface $scopeConfig * @param string[] $configPaths */ public function __construct( - TransportBuilder $transportBuilder, - ScopeConfigInterface $scopeConfig, - array $configPaths - ) { - $this->transportBuilder = $transportBuilder; - $this->scopeConfig = $scopeConfig; - $this->configPaths = $configPaths; - } + protected TransportBuilder $transportBuilder, + private ScopeConfigInterface $scopeConfig, + private array $configPaths = [] + ) {} /** - * @param string $sendTo - * @param string|null $name [optional] Specify the to name. - * @param int|null $storeId [optional Current store ID is used by default. - * @param array $vars * @throws LocalizedException * @throws MailException */ @@ -76,10 +60,6 @@ protected function sendMail(string $sendTo, ?string $name = null, ?int $storeId } /** - * @param string $sendTo - * @param string|null $name [optional] Specify the to name. - * @param int|null $storeId [optional Current store ID is used by default. - * @param array $vars * @throws MailException */ protected function prepareMail(string $sendTo, ?string $name = null, ?int $storeId = null, array $vars = []): void @@ -91,36 +71,21 @@ protected function prepareMail(string $sendTo, ?string $name = null, ?int $store ->addTo($sendTo, $name); } - /** - * @param int|null $storeId [optional] Retrieves the value by scope. - * @return bool - */ protected function isAvailable(?int $storeId = null): bool { - return $this->scopeConfig->isSetFlag( - $this->configPaths['is_available'], - ScopeInterface::SCOPE_STORE, - $storeId - ); + return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_ENABLED, ScopeInterface::SCOPE_STORE, $storeId) + && $this->scopeConfig->isSetFlag($this->configPaths['is_available'], ScopeInterface::SCOPE_STORE, $storeId); } - /** - * @param int|null $storeId [optional] Retrieves the value by scope. - * @return string - */ protected function getFrom(?int $storeId = null): string { - return (string) $this->scopeConfig->getValue( + return (string)$this->scopeConfig->getValue( $this->configPaths['from'], ScopeInterface::SCOPE_STORE, $storeId ); } - /** - * @param int|null $storeId [optional] Retrieves the value by scope. - * @return array - */ protected function getCopyTo(?int $storeId = null): array { return explode( @@ -133,26 +98,18 @@ protected function getCopyTo(?int $storeId = null): array ); } - /** - * @param int|null $storeId [optional] Retrieves the value by scope. - * @return string - */ protected function getCopyMethod(?int $storeId = null): string { - return (string) $this->scopeConfig->getValue( + return (string)$this->scopeConfig->getValue( $this->configPaths['copy_method'], ScopeInterface::SCOPE_STORE, $storeId ); } - /** - * @param int|null $storeId [optional] Retrieves the value by scope. - * @return string - */ protected function getTemplateIdentifier(?int $storeId = null): string { - return (string) $this->scopeConfig->getValue( + return (string)$this->scopeConfig->getValue( $this->configPaths['template_identifier'], ScopeInterface::SCOPE_STORE, $storeId diff --git a/Model/Order/Anonymize/Processor/OrderDataProcessor.php b/Model/Order/Anonymize/Processor/OrderDataProcessor.php index 4168772c..1fdf9c8d 100644 --- a/Model/Order/Anonymize/Processor/OrderDataProcessor.php +++ b/Model/Order/Anonymize/Processor/OrderDataProcessor.php @@ -17,7 +17,7 @@ use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class OrderDataProcessor implements ProcessorInterface +class OrderDataProcessor implements ProcessorInterface { private AnonymizerInterface $anonymizer; @@ -50,7 +50,7 @@ public function execute(int $orderId): bool $lastActive = new DateTime($order->getUpdatedAt()); if ($this->salesInformation->isAlive($lastActive)) { - $this->salesInformation->scheduleEraseEntity((int) $order->getEntityId(), 'order', $lastActive); + $this->salesInformation->scheduleEraseEntity((int)$order->getEntityId(), 'order', $lastActive); return true; } diff --git a/Model/Order/Anonymize/Processor/QuoteDataProcessor.php b/Model/Order/Anonymize/Processor/QuoteDataProcessor.php index 492433b1..ea519804 100644 --- a/Model/Order/Anonymize/Processor/QuoteDataProcessor.php +++ b/Model/Order/Anonymize/Processor/QuoteDataProcessor.php @@ -17,7 +17,7 @@ use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class QuoteDataProcessor implements ProcessorInterface +class QuoteDataProcessor implements ProcessorInterface { private AnonymizerInterface $anonymizer; diff --git a/Model/Order/Anonymize/Processor/SubscriberDataProcessor.php b/Model/Order/Anonymize/Processor/SubscriberDataProcessor.php index fd3a071a..1ae870ef 100644 --- a/Model/Order/Anonymize/Processor/SubscriberDataProcessor.php +++ b/Model/Order/Anonymize/Processor/SubscriberDataProcessor.php @@ -15,7 +15,7 @@ use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class SubscriberDataProcessor implements ProcessorInterface +class SubscriberDataProcessor implements ProcessorInterface { private AnonymizerInterface $anonymizer; diff --git a/Model/Order/Delete/Processor/OrderDataProcessor.php b/Model/Order/Delete/Processor/OrderDataProcessor.php index 1bb0942e..f274eb50 100644 --- a/Model/Order/Delete/Processor/OrderDataProcessor.php +++ b/Model/Order/Delete/Processor/OrderDataProcessor.php @@ -13,7 +13,7 @@ use Opengento\Gdpr\Api\EraseSalesInformationInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class OrderDataProcessor implements ProcessorInterface +class OrderDataProcessor implements ProcessorInterface { private OrderRepositoryInterface $orderRepository; @@ -37,7 +37,7 @@ public function execute(int $orderId): bool $lastActive = new DateTime($order->getUpdatedAt()); if ($this->salesInformation->isAlive($lastActive)) { - $this->salesInformation->scheduleEraseEntity((int) $order->getEntityId(), 'order', $lastActive); + $this->salesInformation->scheduleEraseEntity((int)$order->getEntityId(), 'order', $lastActive); return true; } diff --git a/Model/Order/Delete/Processor/QuoteDataProcessor.php b/Model/Order/Delete/Processor/QuoteDataProcessor.php index 08a9fb68..a8793f32 100644 --- a/Model/Order/Delete/Processor/QuoteDataProcessor.php +++ b/Model/Order/Delete/Processor/QuoteDataProcessor.php @@ -12,7 +12,7 @@ use Magento\Sales\Api\OrderRepositoryInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class QuoteDataProcessor implements ProcessorInterface +class QuoteDataProcessor implements ProcessorInterface { private OrderRepositoryInterface $orderRepository; diff --git a/Model/Order/Delete/Processor/SubscriberDataProcessor.php b/Model/Order/Delete/Processor/SubscriberDataProcessor.php index d7919ccd..beda160c 100644 --- a/Model/Order/Delete/Processor/SubscriberDataProcessor.php +++ b/Model/Order/Delete/Processor/SubscriberDataProcessor.php @@ -15,7 +15,7 @@ use Magento\Store\Model\StoreManagerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; -final class SubscriberDataProcessor implements ProcessorInterface +class SubscriberDataProcessor implements ProcessorInterface { private OrderRepositoryInterface $orderRepository; @@ -49,7 +49,7 @@ public function execute(int $orderId): bool $subscriber = $this->subscriberFactory->create(); $subscriber->loadBySubscriberEmail( $order->getCustomerEmail(), - (int) $this->storeManager->getStore($order->getStoreId())->getWebsiteId() + (int)$this->storeManager->getStore($order->getStoreId())->getWebsiteId() ); $this->subscriberResource->delete($subscriber); diff --git a/Model/Order/Erase/Notifier.php b/Model/Order/Erase/Notifier.php index 497e0393..5e3c7a86 100644 --- a/Model/Order/Erase/Notifier.php +++ b/Model/Order/Erase/Notifier.php @@ -14,7 +14,7 @@ use Opengento\Gdpr\Model\Order\Notifier\SenderInterface; use Psr\Log\LoggerInterface; -final class Notifier implements NotifierInterface +class Notifier implements NotifierInterface { /** @var SenderInterface[] */ private array $senders; @@ -41,7 +41,7 @@ public function notify(EraseEntityInterface $eraseEntity): void try { $sender->send($order); } catch (LocalizedException $e) { - $this->logger->error($e->getLogMessage(), $e->getTrace()); + $this->logger->error($e->getLogMessage(), ['exception' => $e]); } } } diff --git a/Model/Order/Export/Notifier.php b/Model/Order/Export/Notifier.php index 584dad66..7261ebf3 100644 --- a/Model/Order/Export/Notifier.php +++ b/Model/Order/Export/Notifier.php @@ -14,7 +14,7 @@ use Opengento\Gdpr\Model\Order\Notifier\SenderInterface; use Psr\Log\LoggerInterface; -final class Notifier implements NotifierInterface +class Notifier implements NotifierInterface { /** @var SenderInterface[] */ private array $senders; @@ -44,7 +44,7 @@ public function notify(ExportEntityInterface $exportEntity): void try { $sender->send($order); } catch (LocalizedException $e) { - $this->logger->error($e->getLogMessage(), $e->getTrace()); + $this->logger->error($e->getLogMessage(), ['exception' => $e]); } } } diff --git a/Model/Order/Export/Processor/OrderDataProcessor.php b/Model/Order/Export/Processor/OrderDataProcessor.php index ed51842a..18d7a5ac 100644 --- a/Model/Order/Export/Processor/OrderDataProcessor.php +++ b/Model/Order/Export/Processor/OrderDataProcessor.php @@ -11,7 +11,7 @@ use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order; -final class OrderDataProcessor extends AbstractDataProcessor +class OrderDataProcessor extends AbstractDataProcessor { protected function export(OrderInterface $order, array $data): array { diff --git a/Model/Order/Export/Processor/QuoteDataProcessor.php b/Model/Order/Export/Processor/QuoteDataProcessor.php index 99bf3984..b6cbf01d 100644 --- a/Model/Order/Export/Processor/QuoteDataProcessor.php +++ b/Model/Order/Export/Processor/QuoteDataProcessor.php @@ -15,7 +15,7 @@ use Magento\Sales\Api\OrderRepositoryInterface; use Opengento\Gdpr\Model\Entity\DataCollectorInterface; -final class QuoteDataProcessor extends AbstractDataProcessor +class QuoteDataProcessor extends AbstractDataProcessor { private CartRepositoryInterface $quoteRepository; diff --git a/Model/Order/Export/Processor/SubscriberDataProcessor.php b/Model/Order/Export/Processor/SubscriberDataProcessor.php index d9846da0..66f01db7 100644 --- a/Model/Order/Export/Processor/SubscriberDataProcessor.php +++ b/Model/Order/Export/Processor/SubscriberDataProcessor.php @@ -13,7 +13,7 @@ use Opengento\Gdpr\Model\Newsletter\Subscriber; use Opengento\Gdpr\Model\Newsletter\SubscriberFactory; -final class SubscriberDataProcessor extends AbstractDataProcessor +class SubscriberDataProcessor extends AbstractDataProcessor { private SubscriberFactory $subscriberFactory; diff --git a/Model/Order/Notifier/MailSender.php b/Model/Order/Notifier/MailSender.php index ca3c94df..bd7afabc 100644 --- a/Model/Order/Notifier/MailSender.php +++ b/Model/Order/Notifier/MailSender.php @@ -14,55 +14,38 @@ use Magento\Sales\Api\Data\OrderInterface; use Magento\Store\Model\StoreManagerInterface; use Opengento\Gdpr\Model\Notifier\AbstractMailSender; -use Psr\Log\LoggerInterface; -final class MailSender extends AbstractMailSender implements SenderInterface +class MailSender extends AbstractMailSender implements SenderInterface { - /** - * @var LoggerInterface - */ - private LoggerInterface $logger; - - /** - * @var StoreManagerInterface - */ - private StoreManagerInterface $storeManager; - public function __construct( - LoggerInterface $logger, + private StoreManagerInterface $storeManager, TransportBuilder $transportBuilder, ScopeConfigInterface $scopeConfig, - StoreManagerInterface $storeManager, array $configPaths ) { - $this->logger = $logger; - $this->storeManager = $storeManager; parent::__construct($transportBuilder, $scopeConfig, $configPaths); } /** - * @inheritdoc * @throws LocalizedException * @throws MailException */ public function send(OrderInterface $order): void { - $storeId = $order->getStoreId() === null ? null : (int) $order->getStoreId(); - $vars = [ - 'order' => $order, - 'billing' => $order->getBillingAddress(), - 'store' => $this->storeManager->getStore($order->getStoreId()), - 'customer_data' => [ - 'customer_name' => $order->getCustomerName(), - ], - ]; + $storeId = $order->getStoreId() === null ? null : (int)$order->getStoreId(); - try { - $this->sendMail($order->getCustomerEmail(), $order->getCustomerName(), $storeId, $vars); - $this->logger->debug(__('GDPR Email Success')); - } catch (MailException $exc) { - $this->logger->error(__('GDPR Email Error: %1', $exc->getMessage())); - } - + $this->sendMail( + $order->getCustomerEmail(), + $order->getCustomerName(), + $storeId, + [ + 'order' => $order, + 'billing' => $order->getBillingAddress(), + 'store' => $this->storeManager->getStore($storeId), + 'customer_data' => [ + 'customer_name' => $order->getCustomerName(), + ] + ] + ); } } diff --git a/Model/Order/OrderChecker.php b/Model/Order/OrderChecker.php index f021bae6..3fefb907 100644 --- a/Model/Order/OrderChecker.php +++ b/Model/Order/OrderChecker.php @@ -7,29 +7,46 @@ namespace Opengento\Gdpr\Model\Order; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\OrderRepositoryInterface; -use Opengento\Gdpr\Model\Config; +use Magento\Store\Model\StoreManagerInterface; +use Opengento\Gdpr\Model\Config\Entity\Erasure as ErasureConfig; use Opengento\Gdpr\Model\Entity\EntityCheckerInterface; + use function in_array; -final class OrderChecker implements EntityCheckerInterface +class OrderChecker implements EntityCheckerInterface { - private OrderRepositoryInterface $orderRepository; + public function __construct( + private OrderRepositoryInterface $orderRepository, + private StoreManagerInterface $storeManager, + private ErasureConfig $erasureConfig + ) {} - private Config $config; + /** + * @throws NoSuchEntityException + */ + public function canErase(int $entityId): bool + { + $order = $this->orderRepository->get($entityId); - public function __construct( - OrderRepositoryInterface $orderRepository, - Config $config - ) { - $this->orderRepository = $orderRepository; - $this->config = $config; + return in_array($order->getState(), $this->allowedStates($order), true); } - public function canErase(int $orderId): bool + /** + * @throws NoSuchEntityException + */ + private function allowedStates(OrderInterface $order): array { - $order = $this->orderRepository->get($orderId); + return $this->erasureConfig->getAllowedStatesToErase($this->resolveWebsiteId($order)); + } - return in_array($order->getState(), $this->config->getAllowedStatesToErase(), true); + /** + * @throws NoSuchEntityException + */ + private function resolveWebsiteId(OrderInterface $order): int + { + return (int)$this->storeManager->getStore($order->getStoreId())->getWebsiteId(); } } diff --git a/Model/Order/SourceProvider/GuestFilterModifier.php b/Model/Order/SourceProvider/GuestFilterModifier.php index 43ddbe75..a7954115 100644 --- a/Model/Order/SourceProvider/GuestFilterModifier.php +++ b/Model/Order/SourceProvider/GuestFilterModifier.php @@ -7,30 +7,23 @@ namespace Opengento\Gdpr\Model\Order\SourceProvider; -use Magento\Framework\Api\Filter; -use Magento\Framework\Data\Collection; -use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Sales\Api\Data\OrderInterface; -use Opengento\Gdpr\Model\Config; +use Magento\Store\Api\Data\WebsiteInterface; +use Opengento\Gdpr\Model\Config\Entity\Erasure as ErasureConfig; use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface; -final class GuestFilterModifier implements ModifierInterface +class GuestFilterModifier implements ModifierInterface { - private Config $config; + public function __construct(private ErasureConfig $erasureConfig) {} - public function __construct(Config $config) - { - $this->config = $config; - } - - /** - * @inheritdoc - * @throws LocalizedException - */ - public function apply(Collection $collection, Filter $filter): void + public function apply(AbstractDb $collection, WebsiteInterface $website): void { $collection->addFieldToFilter(OrderInterface::CUSTOMER_ID, ['null' => true]); $collection->addFieldToFilter(OrderInterface::CUSTOMER_IS_GUEST, ['eq' => 1]); - $collection->addFieldToFilter(OrderInterface::STATE, ['in' => $this->config->getAllowedStatesToErase()]); + $collection->addFieldToFilter( + 'main_table.' . OrderInterface::STATE, + ['in' => $this->erasureConfig->getAllowedStatesToErase($website->getId())] + ); } } diff --git a/Model/ResourceModel/ActionEntity.php b/Model/ResourceModel/ActionEntity.php deleted file mode 100755 index 647893a1..00000000 --- a/Model/ResourceModel/ActionEntity.php +++ /dev/null @@ -1,45 +0,0 @@ -validator = $validator; - parent::__construct($context, $entitySnapshot, $relationComposite, $connectionName); - } - - protected function _construct(): void - { - $this->_init(self::TABLE, ActionEntityInterface::ID); - $this->_serializableFields = [ActionEntityInterface::PARAMETERS => [[], []]]; - } - - public function getValidationRulesBeforeSave(): ValidatorInterface - { - return $this->validator; - } -} diff --git a/Model/ResourceModel/ActionEntity/Collection.php b/Model/ResourceModel/ActionEntity/Collection.php deleted file mode 100755 index 5e118b0d..00000000 --- a/Model/ResourceModel/ActionEntity/Collection.php +++ /dev/null @@ -1,22 +0,0 @@ -_init(ActionEntity::class, ActionEntityResourceModel::class); - $this->_setIdFieldName(ActionEntityInterface::ID); - } -} diff --git a/Model/ResourceModel/ActionEntity/Validator.php b/Model/ResourceModel/ActionEntity/Validator.php deleted file mode 100644 index 0f6dd1f0..00000000 --- a/Model/ResourceModel/ActionEntity/Validator.php +++ /dev/null @@ -1,38 +0,0 @@ -validators = $validators; - } - - public function isValid($value): bool - { - $this->_clearMessages(); - - foreach ($this->validators as $validator) { - if (!$validator->isValid($value)) { - $this->_addMessages($validator->getMessages()); - } - } - - return !$this->hasMessages(); - } -} diff --git a/Model/ResourceModel/ActionEntity/Validator/StateValidator.php b/Model/ResourceModel/ActionEntity/Validator/StateValidator.php deleted file mode 100644 index f80341fb..00000000 --- a/Model/ResourceModel/ActionEntity/Validator/StateValidator.php +++ /dev/null @@ -1,48 +0,0 @@ -actionStates = $actionStates; - } - - /** - * @param ActionEntityInterface $actionEntity - * @return bool - */ - public function isValid($actionEntity): bool - { - $this->_clearMessages(); - $isValid = in_array( - $actionEntity->getState(), - array_column($this->actionStates->toOptionArray(), 'value'), - true - ); - - if (!$isValid) { - $this->_addMessages([ - 'state' => new Phrase('State "%1" does not exists.', [$actionEntity->getState()]) - ]); - } - - return $isValid; - } -} diff --git a/Model/ResourceModel/EraseEntity.php b/Model/ResourceModel/EraseEntity.php index 993b7e0b..de5c3104 100755 --- a/Model/ResourceModel/EraseEntity.php +++ b/Model/ResourceModel/EraseEntity.php @@ -12,6 +12,7 @@ use Magento\Framework\Model\AbstractModel; use Magento\Framework\Model\ResourceModel\Db\VersionControl\AbstractDb; use Opengento\Gdpr\Api\Data\EraseEntityInterface; + use function is_array; use function sprintf; diff --git a/Model/ResourceModel/ExportEntity.php b/Model/ResourceModel/ExportEntity.php index b011579c..4530d3ea 100755 --- a/Model/ResourceModel/ExportEntity.php +++ b/Model/ResourceModel/ExportEntity.php @@ -12,6 +12,7 @@ use Magento\Framework\Model\AbstractModel; use Magento\Framework\Model\ResourceModel\Db\VersionControl\AbstractDb; use Opengento\Gdpr\Api\Data\ExportEntityInterface; + use function is_array; use function sprintf; diff --git a/Observer/DeleteExport.php b/Observer/DeleteExport.php index e5892bc1..1ab42343 100644 --- a/Observer/DeleteExport.php +++ b/Observer/DeleteExport.php @@ -22,52 +22,33 @@ use Opengento\Gdpr\Model\Entity\EntityTypeResolver; use Psr\Log\LoggerInterface; -final class DeleteExport implements ObserverInterface +class DeleteExport implements ObserverInterface { - private ExportEntityRepositoryInterface $exportRepository; - - private SearchCriteriaBuilder $criteriaBuilder; - - private FilterBuilder $filterBuilder; - - private EntityTypeResolver $entityTypeResolver; - - private LoggerInterface $logger; - public function __construct( - ExportEntityRepositoryInterface $exportRepository, - SearchCriteriaBuilder $criteriaBuilder, - FilterBuilder $filterBuilder, - EntityTypeResolver $entityTypeResolver, - LoggerInterface $logger - ) { - $this->exportRepository = $exportRepository; - $this->criteriaBuilder = $criteriaBuilder; - $this->filterBuilder = $filterBuilder; - $this->entityTypeResolver = $entityTypeResolver; - $this->logger = $logger; - } + private ExportEntityRepositoryInterface $exportRepository, + private SearchCriteriaBuilder $criteriaBuilder, + private FilterBuilder $filterBuilder, + private EntityTypeResolver $entityTypeResolver, + private LoggerInterface $logger + ) {} public function execute(Observer $observer): void { - /** @var DataObject $entity */ $entity = $observer->getData('data_object'); - if ($entity instanceof DataObject) { try { foreach ($this->fetchExportEntities($entity)->getItems() as $exportEntity) { $this->exportRepository->delete($exportEntity); } } catch (LocalizedException $e) { - $this->logger->error($e->getLogMessage(), $e->getTrace()); + $this->logger->error($e->getLogMessage(), ['exception' => $e]); } catch (Exception $e) { - $this->logger->error($e->getMessage(), $e->getTrace()); + $this->logger->error($e->getMessage(), ['exception' => $e]); } } } /** - * @param DataObject $entity * @return ExportEntitySearchResultsInterface * @throws LocalizedException * @throws Exception @@ -78,7 +59,7 @@ private function fetchExportEntities(DataObject $entity): SearchResultsInterface foreach ($entityTypes as $entityType => $idFieldName) { $this->criteriaBuilder->addFilters([ - $this->createEntityIdFilter((int) $entity->getData($idFieldName)), + $this->createEntityIdFilter((int)$entity->getData($idFieldName)), $this->createEntityTypeFilter($entityType) ]); } diff --git a/Observer/InvalidateExport.php b/Observer/InvalidateExport.php index fd32f250..44501299 100644 --- a/Observer/InvalidateExport.php +++ b/Observer/InvalidateExport.php @@ -23,55 +23,34 @@ use Opengento\Gdpr\Model\Entity\EntityTypeResolver; use Psr\Log\LoggerInterface; -final class InvalidateExport implements ObserverInterface +class InvalidateExport implements ObserverInterface { - private ExportEntityRepositoryInterface $exportRepository; - - private ExportEntityManagementInterface $exportManagement; - - private SearchCriteriaBuilder $criteriaBuilder; - - private FilterBuilder $filterBuilder; - - private EntityTypeResolver $entityTypeResolver; - - private LoggerInterface $logger; - public function __construct( - ExportEntityRepositoryInterface $exportRepository, - ExportEntityManagementInterface $exportManagement, - SearchCriteriaBuilder $criteriaBuilder, - FilterBuilder $filterBuilder, - EntityTypeResolver $entityTypeResolver, - LoggerInterface $logger - ) { - $this->exportRepository = $exportRepository; - $this->exportManagement = $exportManagement; - $this->criteriaBuilder = $criteriaBuilder; - $this->filterBuilder = $filterBuilder; - $this->entityTypeResolver = $entityTypeResolver; - $this->logger = $logger; - } + private ExportEntityRepositoryInterface $exportRepository, + private ExportEntityManagementInterface $exportManagement, + private SearchCriteriaBuilder $criteriaBuilder, + private FilterBuilder $filterBuilder, + private EntityTypeResolver $entityTypeResolver, + private LoggerInterface $logger + ) {} public function execute(Observer $observer): void { $entity = $observer->getData('data_object'); - if ($entity instanceof DataObject) { try { foreach ($this->fetchExportEntities($entity)->getItems() as $exportEntity) { $this->exportManagement->invalidate($exportEntity); } } catch (LocalizedException $e) { - $this->logger->error($e->getLogMessage(), $e->getTrace()); + $this->logger->error($e->getLogMessage(), ['exception' => $e]); } catch (Exception $e) { - $this->logger->error($e->getMessage(), $e->getTrace()); + $this->logger->error($e->getMessage(), ['exception' => $e]); } } } /** - * @param DataObject $entity * @return ExportEntitySearchResultsInterface * @throws LocalizedException * @throws Exception @@ -82,7 +61,7 @@ private function fetchExportEntities(DataObject $entity): SearchResultsInterface foreach ($entityTypes as $entityType => $idFieldName) { $this->criteriaBuilder->addFilters([ - $this->createEntityIdFilter((int) $entity->getData($idFieldName)), + $this->createEntityIdFilter((int)$entity->getData($idFieldName)), $this->createEntityTypeFilter($entityType) ]); } diff --git a/Service/Anonymize/Anonymizer/AlphaLower.php b/Service/Anonymize/Anonymizer/AlphaLower.php index 3a0d3ac9..5ae87c29 100644 --- a/Service/Anonymize/Anonymizer/AlphaLower.php +++ b/Service/Anonymize/Anonymizer/AlphaLower.php @@ -11,7 +11,7 @@ use Magento\Framework\Math\Random; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; -final class AlphaLower implements AnonymizerInterface +class AlphaLower implements AnonymizerInterface { private const DEFAULT_LENGTH = 5; diff --git a/Service/Anonymize/Anonymizer/AlphaNum.php b/Service/Anonymize/Anonymizer/AlphaNum.php index 7181d622..abcf8c0f 100644 --- a/Service/Anonymize/Anonymizer/AlphaNum.php +++ b/Service/Anonymize/Anonymizer/AlphaNum.php @@ -11,7 +11,7 @@ use Magento\Framework\Math\Random; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; -final class AlphaNum implements AnonymizerInterface +class AlphaNum implements AnonymizerInterface { private const DEFAULT_LENGTH = 5; diff --git a/Service/Anonymize/Anonymizer/AlphaUpper.php b/Service/Anonymize/Anonymizer/AlphaUpper.php index 18a6c032..e3674f5e 100644 --- a/Service/Anonymize/Anonymizer/AlphaUpper.php +++ b/Service/Anonymize/Anonymizer/AlphaUpper.php @@ -11,7 +11,7 @@ use Magento\Framework\Math\Random; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; -final class AlphaUpper implements AnonymizerInterface +class AlphaUpper implements AnonymizerInterface { private const DEFAULT_LENGTH = 5; diff --git a/Service/Anonymize/Anonymizer/Anonymous.php b/Service/Anonymize/Anonymizer/Anonymous.php index 32b0a1e6..61f72101 100644 --- a/Service/Anonymize/Anonymizer/Anonymous.php +++ b/Service/Anonymize/Anonymizer/Anonymous.php @@ -12,37 +12,26 @@ use Magento\Framework\Phrase; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; -final class Anonymous implements AnonymizerInterface +class Anonymous implements AnonymizerInterface { - private const PHRASE = '%1Anonymous%2'; - private const PREFIX_LENGTH = 3; - private const SUFFIX_LENGTH = 2; + public function __construct(private Random $mathRandom) {} /** - * @var Random + * @throws LocalizedException */ - private Random $mathRandom; - - public function __construct( - Random $mathRandom - ) { - $this->mathRandom = $mathRandom; + public function anonymize($value): ?string + { + return $value ? $this->createPhrase()->render() : null; } /** - * @inheritdoc * @throws LocalizedException */ - public function anonymize($value): ?string + private function createPhrase(): Phrase { - return $value - ? (new Phrase( - self::PHRASE, - [ - $this->mathRandom->getRandomString(self::PREFIX_LENGTH), - $this->mathRandom->getRandomString(self::SUFFIX_LENGTH), - ] - ))->render() - : null; + return new Phrase( + '%1Anonymous%2', + [$this->mathRandom->getRandomString(3), $this->mathRandom->getRandomString(2)] + ); } } diff --git a/Service/Anonymize/Anonymizer/Date.php b/Service/Anonymize/Anonymizer/Date.php index c8a947e5..17f88188 100644 --- a/Service/Anonymize/Anonymizer/Date.php +++ b/Service/Anonymize/Anonymizer/Date.php @@ -13,7 +13,7 @@ use Magento\Framework\Stdlib\DateTime as StdlibDateTime; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; -final class Date implements AnonymizerInterface +class Date implements AnonymizerInterface { private const MIN_TIMESTAMP = 0; private const MAX_TIMESTAMP = 1557480188; diff --git a/Service/Anonymize/Anonymizer/Email.php b/Service/Anonymize/Anonymizer/Email.php index 4c09bb62..6393bf73 100644 --- a/Service/Anonymize/Anonymizer/Email.php +++ b/Service/Anonymize/Anonymizer/Email.php @@ -12,37 +12,29 @@ use Magento\Framework\Phrase; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; -final class Email implements AnonymizerInterface +class Email implements AnonymizerInterface { - private const PHRASE = '%1-anonymous-%2@gdpr.org'; - private const PREFIX_LENGTH = 3; - private const SUFFIX_LENGTH = 2; + public function __construct(private Random $mathRandom) {} /** - * @var Random + * @throws LocalizedException */ - private Random $mathRandom; - - public function __construct( - Random $mathRandom - ) { - $this->mathRandom = $mathRandom; + public function anonymize($value): ?string + { + return $value ? $this->createPhrase()->render() : null; } /** - * @inheritdoc * @throws LocalizedException */ - public function anonymize($value): ?string + private function createPhrase(): Phrase { - return $value - ? (new Phrase( - self::PHRASE, - [ - $this->mathRandom->getRandomString(self::PREFIX_LENGTH, Random::CHARS_LOWERS), - $this->mathRandom->getRandomString(self::SUFFIX_LENGTH, Random::CHARS_LOWERS), - ] - ))->render() - : null; + return new Phrase( + '%1-anonymous-%2@gdpr.org', + [ + $this->mathRandom->getRandomString(3, Random::CHARS_LOWERS), + $this->mathRandom->getRandomString(2, Random::CHARS_LOWERS) + ] + ); } } diff --git a/Service/Anonymize/Anonymizer/Entity.php b/Service/Anonymize/Anonymizer/Entity.php index d5007374..b70e893a 100644 --- a/Service/Anonymize/Anonymizer/Entity.php +++ b/Service/Anonymize/Anonymizer/Entity.php @@ -9,47 +9,43 @@ use Exception; use InvalidArgumentException; +use Magento\Framework\EntityManager\HydratorInterface; use Magento\Framework\EntityManager\HydratorPool; use Magento\Framework\EntityManager\TypeResolver; use Opengento\Gdpr\Model\Entity\DataCollectorInterface; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; + use function gettype; use function is_object; use function sprintf; -final class Entity implements AnonymizerInterface +class Entity implements AnonymizerInterface { - private DataCollectorInterface $dataCollector; - - private TypeResolver $typeResolver; - - private HydratorPool $hydratorPool; - public function __construct( - DataCollectorInterface $dataCollector, - TypeResolver $typeResolver, - HydratorPool $hydratorPool - ) { - $this->dataCollector = $dataCollector; - $this->typeResolver = $typeResolver; - $this->hydratorPool = $hydratorPool; - } + private DataCollectorInterface $dataCollector, + private TypeResolver $typeResolver, + private HydratorPool $hydratorPool + ) {} /** - * @inheritdoc * @throws Exception */ - public function anonymize($entity): object + public function anonymize($value): object { - if (!is_object($entity)) { + if (!is_object($value)) { throw new InvalidArgumentException( - sprintf('Argument "$entity" must be an object, type "%s" given.', gettype($entity)) + sprintf('Argument "$entity" must be an object, type "%s" given.', gettype($value)) ); } - $hydrator = $this->hydratorPool->getHydrator($this->typeResolver->resolve($entity)); - $hydrator->hydrate($entity, $this->dataCollector->collect($entity)); + return $this->resolveHydrator($value)->hydrate($value, $this->dataCollector->collect($value)); + } - return $entity; + /** + * @throws Exception + */ + private function resolveHydrator(object $entity): HydratorInterface + { + return $this->hydratorPool->getHydrator($this->typeResolver->resolve($entity)); } } diff --git a/Service/Anonymize/Anonymizer/NullValue.php b/Service/Anonymize/Anonymizer/NullValue.php index 881cf83c..3a595f9c 100644 --- a/Service/Anonymize/Anonymizer/NullValue.php +++ b/Service/Anonymize/Anonymizer/NullValue.php @@ -9,7 +9,7 @@ use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; -final class NullValue implements AnonymizerInterface +class NullValue implements AnonymizerInterface { public function anonymize($value) { diff --git a/Service/Anonymize/Anonymizer/Number.php b/Service/Anonymize/Anonymizer/Number.php index 960cbf50..1caca0f8 100644 --- a/Service/Anonymize/Anonymizer/Number.php +++ b/Service/Anonymize/Anonymizer/Number.php @@ -10,10 +10,11 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Math\Random; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; + use const PHP_INT_MAX; use const PHP_INT_MIN; -final class Number implements AnonymizerInterface +class Number implements AnonymizerInterface { /** * @var int|null diff --git a/Service/Anonymize/Anonymizer/Phone.php b/Service/Anonymize/Anonymizer/Phone.php index 34410948..05a85942 100644 --- a/Service/Anonymize/Anonymizer/Phone.php +++ b/Service/Anonymize/Anonymizer/Phone.php @@ -9,7 +9,7 @@ use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; -final class Phone implements AnonymizerInterface +class Phone implements AnonymizerInterface { private const PHONE_NUMBER = '9999999999'; diff --git a/Service/Anonymize/Anonymizer/Street.php b/Service/Anonymize/Anonymizer/Street.php index bdb6bcaf..baf91e8b 100644 --- a/Service/Anonymize/Anonymizer/Street.php +++ b/Service/Anonymize/Anonymizer/Street.php @@ -10,9 +10,10 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Math\Random; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; + use function sprintf; -final class Street implements AnonymizerInterface +class Street implements AnonymizerInterface { private const STREET_LENGTH = 5; private const MIN_NUM = 0; diff --git a/Service/Anonymize/AnonymizerFactory.php b/Service/Anonymize/AnonymizerFactory.php index 803c2569..a0a9da98 100644 --- a/Service/Anonymize/AnonymizerFactory.php +++ b/Service/Anonymize/AnonymizerFactory.php @@ -9,9 +9,10 @@ use InvalidArgumentException; use Magento\Framework\ObjectManagerInterface; + use function sprintf; -final class AnonymizerFactory +class AnonymizerFactory { public const DEFAULT_KEY = 'default'; diff --git a/Service/Anonymize/Metadata.php b/Service/Anonymize/Metadata.php index 2d1d4a99..4720a1ea 100644 --- a/Service/Anonymize/Metadata.php +++ b/Service/Anonymize/Metadata.php @@ -9,48 +9,35 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Serialize\SerializerInterface; + use function array_column; use function array_combine; use function array_keys; +use function is_array; -final class Metadata implements MetadataInterface +class Metadata implements MetadataInterface { - private ScopeConfigInterface $scopeConfig; - - /** - * @var SerializerInterface - */ - private SerializerInterface $serializer; - - private string $configPath; - - private string $scopeType; - /** * @var string[][] */ private array $cache; public function __construct( - ScopeConfigInterface $scopeConfig, - SerializerInterface $serializer, - string $configPath, - string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT - ) { - $this->scopeConfig = $scopeConfig; - $this->serializer = $serializer; - $this->configPath = $configPath; - $this->scopeType = $scopeType; - } + private ScopeConfigInterface $scopeConfig, + private SerializerInterface $serializer, + private string $configPath, + private string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT + ) {} public function getAnonymizerStrategiesByAttributes(?string $scopeCode = null): array { $scope = $scopeCode ?? 'current_scope'; if (!isset($this->cache[$scope])) { - $metadata = $this->serializer->unserialize( - $this->scopeConfig->getValue($this->configPath, $this->scopeType, $scopeCode) ?? '{}' - ); + $metadata = $this->scopeConfig->getValue($this->configPath, $this->scopeType, $scopeCode); + if (!is_array($metadata)) { + $metadata = $this->serializer->unserialize($metadata ?? '{}'); + } $this->cache[$scope] = array_combine( array_column($metadata, 'attribute'), diff --git a/Service/Anonymize/Processor/Entity/EntityValue/Processor.php b/Service/Anonymize/Processor/Entity/EntityValue/Processor.php index 26ea70ed..a3969c82 100644 --- a/Service/Anonymize/Processor/Entity/EntityValue/Processor.php +++ b/Service/Anonymize/Processor/Entity/EntityValue/Processor.php @@ -11,9 +11,10 @@ use Opengento\Gdpr\Model\Entity\EntityValueProcessorInterface; use Opengento\Gdpr\Model\Entity\MetadataInterface; use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface; + use function in_array; -final class Processor implements EntityValueProcessorInterface +class Processor implements EntityValueProcessorInterface { /** * @var DocumentInterface diff --git a/Service/Anonymize/Processor/Entity/EntityValue/SmartProcessor.php b/Service/Anonymize/Processor/Entity/EntityValue/SmartProcessor.php index b2abd4ca..56d60ed8 100644 --- a/Service/Anonymize/Processor/Entity/EntityValue/SmartProcessor.php +++ b/Service/Anonymize/Processor/Entity/EntityValue/SmartProcessor.php @@ -11,9 +11,10 @@ use Opengento\Gdpr\Model\Entity\EntityValueProcessorInterface; use Opengento\Gdpr\Service\Anonymize\AnonymizerFactory; use Opengento\Gdpr\Service\Anonymize\MetadataInterface; + use function in_array; -final class SmartProcessor implements EntityValueProcessorInterface +class SmartProcessor implements EntityValueProcessorInterface { /** * @var DocumentInterface diff --git a/Service/Erase/Metadata.php b/Service/Erase/Metadata.php index 231fd68d..44c833a1 100644 --- a/Service/Erase/Metadata.php +++ b/Service/Erase/Metadata.php @@ -10,48 +10,34 @@ use InvalidArgumentException; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Serialize\SerializerInterface; + use function array_column; use function array_combine; use function sprintf; -final class Metadata implements MetadataInterface +class Metadata implements MetadataInterface { - private ScopeConfigInterface $scopeConfig; - - /** - * @var SerializerInterface - */ - private SerializerInterface $serializer; - - private string $configPath; - - private string $scopeType; - /** * @var string[][] */ private array $cache; public function __construct( - ScopeConfigInterface $scopeConfig, - SerializerInterface $serializer, - string $configPath, - string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT - ) { - $this->scopeConfig = $scopeConfig; - $this->serializer = $serializer; - $this->configPath = $configPath; - $this->scopeType = $scopeType; - } + private ScopeConfigInterface $scopeConfig, + private SerializerInterface $serializer, + private string $configPath, + private string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT + ) {} public function getComponentsProcessors(?string $scopeCode = null): array { $scope = $scopeCode ?? 'current_scope'; if (!isset($this->cache[$scope])) { - $metadata = $this->serializer->unserialize( - $this->scopeConfig->getValue($this->configPath, $this->scopeType, $scopeCode) ?? '{}' - ); + $metadata = $this->scopeConfig->getValue($this->configPath, $this->scopeType, $scopeCode); + if (!is_array($metadata)) { + $metadata = $this->serializer->unserialize($metadata ?? '{}'); + } $this->cache[$scope] = array_combine( array_column($metadata, 'component'), @@ -67,14 +53,9 @@ public function getComponentsProcessors(?string $scopeCode = null): array */ public function getComponentProcessor(string $component, ?string $scopeCode = null): string { - $componentsProcessors = $this->getComponentsProcessors($scopeCode); - - if (!isset($componentsProcessors[$component])) { - throw new InvalidArgumentException( + return $this->getComponentsProcessors($scopeCode)[$component] + ?? throw new InvalidArgumentException( sprintf('There is no erasure processor registered for the component "%s".', $component) ); - } - - return $componentsProcessors[$component]; } } diff --git a/Service/Erase/Processor/EraseProcessor.php b/Service/Erase/Processor/EraseProcessor.php index 860398d3..f7e2c448 100644 --- a/Service/Erase/Processor/EraseProcessor.php +++ b/Service/Erase/Processor/EraseProcessor.php @@ -10,9 +10,10 @@ use Opengento\Gdpr\Model\Config\Source\EraseComponents; use Opengento\Gdpr\Service\Erase\ProcessorInterface; use Opengento\Gdpr\Service\Erase\ProcessorResolverInterface; + use function array_column; -final class EraseProcessor implements ProcessorInterface +class EraseProcessor implements ProcessorInterface { /** * @var ProcessorResolverInterface diff --git a/Service/Erase/ProcessorFactory.php b/Service/Erase/ProcessorFactory.php index bf425260..a548bdb4 100644 --- a/Service/Erase/ProcessorFactory.php +++ b/Service/Erase/ProcessorFactory.php @@ -9,12 +9,13 @@ use InvalidArgumentException; use Magento\Framework\ObjectManagerInterface; + use function sprintf; /** * @api */ -final class ProcessorFactory +class ProcessorFactory { /** * @var string[] diff --git a/Service/Erase/ProcessorResolver/ProcessorResolver.php b/Service/Erase/ProcessorResolver/ProcessorResolver.php index dfb6be1e..f787da43 100644 --- a/Service/Erase/ProcessorResolver/ProcessorResolver.php +++ b/Service/Erase/ProcessorResolver/ProcessorResolver.php @@ -11,9 +11,10 @@ use Magento\Framework\ObjectManagerInterface; use Opengento\Gdpr\Service\Erase\ProcessorInterface; use Opengento\Gdpr\Service\Erase\ProcessorResolverInterface; + use function sprintf; -final class ProcessorResolver implements ProcessorResolverInterface +class ProcessorResolver implements ProcessorResolverInterface { /** * @var ProcessorInterface[] diff --git a/Service/Erase/ProcessorResolver/ProcessorResolverStrategy.php b/Service/Erase/ProcessorResolver/ProcessorResolverStrategy.php index 7c3c205d..010f24a2 100644 --- a/Service/Erase/ProcessorResolver/ProcessorResolverStrategy.php +++ b/Service/Erase/ProcessorResolver/ProcessorResolverStrategy.php @@ -12,7 +12,7 @@ use Opengento\Gdpr\Service\Erase\ProcessorResolverFactory; use Opengento\Gdpr\Service\Erase\ProcessorResolverInterface; -final class ProcessorResolverStrategy implements ProcessorResolverInterface +class ProcessorResolverStrategy implements ProcessorResolverInterface { /** * @var ProcessorResolverFactory diff --git a/Service/Erase/ProcessorResolverFactory.php b/Service/Erase/ProcessorResolverFactory.php index d8e37821..2f76fc0c 100644 --- a/Service/Erase/ProcessorResolverFactory.php +++ b/Service/Erase/ProcessorResolverFactory.php @@ -9,12 +9,13 @@ use InvalidArgumentException; use Magento\Framework\ObjectManagerInterface; + use function sprintf; /** * @api */ -final class ProcessorResolverFactory +class ProcessorResolverFactory { /** * @var string[] diff --git a/Service/Export/Processor/CompositeProcessor.php b/Service/Export/Processor/CompositeProcessor.php index edff6d42..13120286 100644 --- a/Service/Export/Processor/CompositeProcessor.php +++ b/Service/Export/Processor/CompositeProcessor.php @@ -8,9 +8,10 @@ namespace Opengento\Gdpr\Service\Export\Processor; use Opengento\Gdpr\Service\Export\ProcessorInterface; + use function array_reduce; -final class CompositeProcessor implements ProcessorInterface +class CompositeProcessor implements ProcessorInterface { /** * @var ProcessorInterface[] diff --git a/Service/Export/Processor/Entity/EntityValue/DataProcessor.php b/Service/Export/Processor/Entity/EntityValue/DataProcessor.php index 3ca529e2..fb747eba 100644 --- a/Service/Export/Processor/Entity/EntityValue/DataProcessor.php +++ b/Service/Export/Processor/Entity/EntityValue/DataProcessor.php @@ -10,9 +10,10 @@ use Opengento\Gdpr\Model\Entity\DocumentInterface; use Opengento\Gdpr\Model\Entity\EntityValueProcessorInterface; use Opengento\Gdpr\Model\Entity\MetadataInterface; + use function in_array; -final class DataProcessor implements EntityValueProcessorInterface +class DataProcessor implements EntityValueProcessorInterface { /** * @var DocumentInterface diff --git a/Service/Export/Processor/Entity/EntityValue/EntityProcessor.php b/Service/Export/Processor/Entity/EntityValue/EntityProcessor.php index a7a34985..00043a8f 100644 --- a/Service/Export/Processor/Entity/EntityValue/EntityProcessor.php +++ b/Service/Export/Processor/Entity/EntityValue/EntityProcessor.php @@ -11,9 +11,10 @@ use Opengento\Gdpr\Model\Entity\DocumentInterface; use Opengento\Gdpr\Model\Entity\EntityValueProcessorInterface; use Opengento\Gdpr\Model\Entity\MetadataInterface; + use function in_array; -final class EntityProcessor implements EntityValueProcessorInterface +class EntityProcessor implements EntityValueProcessorInterface { /** * @var DocumentInterface diff --git a/Service/Export/ProcessorFactory.php b/Service/Export/ProcessorFactory.php index b0321430..8dc548ed 100644 --- a/Service/Export/ProcessorFactory.php +++ b/Service/Export/ProcessorFactory.php @@ -9,12 +9,13 @@ use InvalidArgumentException; use Magento\Framework\ObjectManagerInterface; + use function sprintf; /** * @api */ -final class ProcessorFactory +class ProcessorFactory { /** * @var string[] diff --git a/Service/Export/Renderer/CsvRenderer.php b/Service/Export/Renderer/CsvRenderer.php index 35dd8ccc..507eccfd 100644 --- a/Service/Export/Renderer/CsvRenderer.php +++ b/Service/Export/Renderer/CsvRenderer.php @@ -8,12 +8,14 @@ namespace Opengento\Gdpr\Service\Export\Renderer; use Magento\Framework\Filesystem; + use function is_array; use function rtrim; use function str_replace; + use const PHP_EOL; -final class CsvRenderer extends AbstractRenderer +class CsvRenderer extends AbstractRenderer { public function __construct( Filesystem $filesystem diff --git a/Service/Export/Renderer/HtmlRenderer.php b/Service/Export/Renderer/HtmlRenderer.php index 57c540f7..efa68031 100644 --- a/Service/Export/Renderer/HtmlRenderer.php +++ b/Service/Export/Renderer/HtmlRenderer.php @@ -20,12 +20,13 @@ use Magento\Framework\View\Page\Config; use Opengento\Gdpr\Service\Export\Renderer\HtmlRenderer\LayoutInitiatorInterface; use Opengento\Gdpr\Service\Export\Renderer\HtmlRenderer\View\RendererFactory; + use function extract; use function ob_end_clean; use function ob_get_clean; use function ob_start; -final class HtmlRenderer extends AbstractRenderer +class HtmlRenderer extends AbstractRenderer { private State $appState; diff --git a/Service/Export/Renderer/HtmlRenderer/LayoutInitiator.php b/Service/Export/Renderer/HtmlRenderer/LayoutInitiator.php index 679d4d5e..8f101265 100644 --- a/Service/Export/Renderer/HtmlRenderer/LayoutInitiator.php +++ b/Service/Export/Renderer/HtmlRenderer/LayoutInitiator.php @@ -16,9 +16,10 @@ use Magento\Framework\View\Model\Layout\Merge; use Magento\Framework\View\Page\Config; use Magento\Framework\View\Page\Layout\Reader; + use function str_replace; -final class LayoutInitiator implements LayoutInitiatorInterface +class LayoutInitiator implements LayoutInitiatorInterface { private LayoutFactory $layoutFactory; diff --git a/Service/Export/Renderer/HtmlRenderer/View/Renderer.php b/Service/Export/Renderer/HtmlRenderer/View/Renderer.php index 6ec54a30..ac7eb146 100644 --- a/Service/Export/Renderer/HtmlRenderer/View/Renderer.php +++ b/Service/Export/Renderer/HtmlRenderer/View/Renderer.php @@ -12,7 +12,9 @@ use Magento\Framework\View\Asset\GroupedCollection; use Magento\Framework\View\Asset\PropertyGroup; use Magento\Framework\View\Page\Config\Renderer as ViewRenderer; + use function sprintf; + use const PHP_EOL; class Renderer extends ViewRenderer @@ -42,7 +44,7 @@ private function inlineAsset(string $contentType, File $asset, ?string $attribut $this->addDefaultAttributes($this->getAssetContentType($asset), $attributes) ); } - + private function inlineHtml(string $contentType, File $asset, ?string $attributes): string { switch ($contentType) { diff --git a/Service/Export/Renderer/JsonRenderer.php b/Service/Export/Renderer/JsonRenderer.php index b43fde41..fd064f62 100644 --- a/Service/Export/Renderer/JsonRenderer.php +++ b/Service/Export/Renderer/JsonRenderer.php @@ -10,7 +10,7 @@ use Magento\Framework\Filesystem; use Magento\Framework\Serialize\Serializer\Json; -final class JsonRenderer extends AbstractRenderer +class JsonRenderer extends AbstractRenderer { private Json $jsonSerializer; diff --git a/Service/Export/Renderer/PdfRenderer.php b/Service/Export/Renderer/PdfRenderer.php index 1df6f631..b952d154 100644 --- a/Service/Export/Renderer/PdfRenderer.php +++ b/Service/Export/Renderer/PdfRenderer.php @@ -11,7 +11,7 @@ use Magento\Framework\Filesystem; use TCPDF; -final class PdfRenderer extends AbstractRenderer +class PdfRenderer extends AbstractRenderer { private HtmlRenderer $htmlRenderer; diff --git a/Service/Export/Renderer/XmlRenderer.php b/Service/Export/Renderer/XmlRenderer.php index cbfbd9db..855b8e7b 100644 --- a/Service/Export/Renderer/XmlRenderer.php +++ b/Service/Export/Renderer/XmlRenderer.php @@ -11,7 +11,7 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem; -final class XmlRenderer extends AbstractRenderer +class XmlRenderer extends AbstractRenderer { private const ROOT_NAME = 'data'; diff --git a/Service/Export/RendererFactory.php b/Service/Export/RendererFactory.php index a0cfaccc..ebee203d 100644 --- a/Service/Export/RendererFactory.php +++ b/Service/Export/RendererFactory.php @@ -9,12 +9,13 @@ use InvalidArgumentException; use Magento\Framework\ObjectManagerInterface; + use function sprintf; /** * @api */ -final class RendererFactory +class RendererFactory { /** * @var string[] diff --git a/Block/Adminhtml/Customer/Edit/EraseButton.php b/Ui/Component/Customer/Form/EraseButton.php similarity index 59% rename from Block/Adminhtml/Customer/Edit/EraseButton.php rename to Ui/Component/Customer/Form/EraseButton.php index f29dc37c..b35e2683 100644 --- a/Block/Adminhtml/Customer/Edit/EraseButton.php +++ b/Ui/Component/Customer/Form/EraseButton.php @@ -5,41 +5,46 @@ */ declare(strict_types=1); -namespace Opengento\Gdpr\Block\Adminhtml\Customer\Edit; +namespace Opengento\Gdpr\Ui\Component\Customer\Form; use Magento\Backend\Block\Widget\Context; +use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Block\Adminhtml\Edit\GenericButton; +use Magento\Framework\AuthorizationInterface; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Phrase; use Magento\Framework\Registry; use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; use Opengento\Gdpr\Api\EraseEntityCheckerInterface; use Opengento\Gdpr\Model\Config; -final class EraseButton extends GenericButton implements ButtonProviderInterface +class EraseButton extends GenericButton implements ButtonProviderInterface { - private EraseEntityCheckerInterface $eraseCustomerChecker; - - private Config $config; - public function __construct( Context $context, Registry $registry, - EraseEntityCheckerInterface $eraseCustomerChecker, - Config $config + private AuthorizationInterface $authorization, + private CustomerRepositoryInterface $customerRepository, + private EraseEntityCheckerInterface $eraseCustomerChecker, + private Config $config ) { - $this->eraseCustomerChecker = $eraseCustomerChecker; - $this->config = $config; parent::__construct($context, $registry); } + /** + * @throws LocalizedException + * @throws NoSuchEntityException + */ public function getButtonData(): array { $customerId = $this->getCustomerId(); $buttonData = []; - if ($customerId && - $this->config->isModuleEnabled() && - $this->eraseCustomerChecker->canCreate($customerId, 'customer') + if ($customerId + && $this->authorization->isAllowed('Opengento_Gdpr::customer_erase') + && $this->config->isErasureEnabled($this->customerRepository->getById($customerId)->getWebsiteId()) + && $this->eraseCustomerChecker->canCreate($customerId, 'customer') ) { $buttonData = [ 'label' => new Phrase('Erase Personal Data'), diff --git a/Block/Adminhtml/Customer/Edit/ExportButton.php b/Ui/Component/Customer/Form/ExportButton.php similarity index 68% rename from Block/Adminhtml/Customer/Edit/ExportButton.php rename to Ui/Component/Customer/Form/ExportButton.php index 80218807..af3fc209 100644 --- a/Block/Adminhtml/Customer/Edit/ExportButton.php +++ b/Ui/Component/Customer/Form/ExportButton.php @@ -5,25 +5,26 @@ */ declare(strict_types=1); -namespace Opengento\Gdpr\Block\Adminhtml\Customer\Edit; +namespace Opengento\Gdpr\Ui\Component\Customer\Form; use Magento\Backend\Block\Widget\Context; +use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Block\Adminhtml\Edit\GenericButton; +use Magento\Framework\AuthorizationInterface; use Magento\Framework\Phrase; use Magento\Framework\Registry; use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; use Opengento\Gdpr\Model\Config; -final class ExportButton extends GenericButton implements ButtonProviderInterface +class ExportButton extends GenericButton implements ButtonProviderInterface { - private Config $config; - public function __construct( Context $context, Registry $registry, - Config $config + private AuthorizationInterface $authorization, + private CustomerRepositoryInterface $customerRepository, + private Config $config ) { - $this->config = $config; parent::__construct($context, $registry); } @@ -32,7 +33,9 @@ public function getButtonData(): array $customerId = $this->getCustomerId(); $buttonData = []; - if ($customerId && $this->config->isModuleEnabled()) { + if ($customerId + && $this->authorization->isAllowed('Opengento_Gdpr::customer_export') + && $this->config->isExportEnabled($this->customerRepository->getById($customerId)->getWebsiteId())) { $buttonData = [ 'label' => new Phrase('Export Personal Data'), 'class' => 'Export', diff --git a/Ui/Component/Order/Form/EraseButton.php b/Ui/Component/Order/Form/EraseButton.php new file mode 100644 index 00000000..a911a635 --- /dev/null +++ b/Ui/Component/Order/Form/EraseButton.php @@ -0,0 +1,57 @@ +getLayout()->getBlock('sales_order_edit'); + if ($orderView instanceof View) { + $orderId = (int)$orderView->getOrderId(); + + if ($this->_authorization->isAllowed('Opengento_Gdpr::order_erase') + && $this->config->isErasureEnabled($orderView->getOrder()->getStore()->getWebsiteId()) + && $this->eraseEntityChecker->canCreate($orderId, 'order') + ) { + $orderView->addButton( + 'opengento-gdpr-order-view-erase-button', + [ + 'label' => new Phrase('Erase Personal Data'), + 'class' => 'action-secondary erase', + 'onclick' => 'deleteConfirm("' . new Phrase('Are you sure you want to do this?') . '", "' + . $this->getUrl('sales/guest/erase', ['id' => $orderId]) . '", {"data":{}})', + ], + 1 + ); + } + } + } +} diff --git a/Ui/Component/Order/Form/ExportButton.php b/Ui/Component/Order/Form/ExportButton.php new file mode 100644 index 00000000..95432fe6 --- /dev/null +++ b/Ui/Component/Order/Form/ExportButton.php @@ -0,0 +1,52 @@ +getLayout()->getBlock('sales_order_edit'); + if ($orderView instanceof View) { + $orderId = (int)$orderView->getOrderId(); + + if ($this->_authorization->isAllowed('Opengento_Gdpr::order_export') + && $this->config->isErasureEnabled($orderView->getOrder()->getStore()->getWebsiteId()) + ) { + $orderView->addButton( + 'opengento-gdpr-order-view-export-button', + [ + 'label' => new Phrase('Export Personal Data'), + 'class' => 'export', + 'onclick' => 'setLocation("' . $this->getUrl('sales/guest/export', ['id' => $orderId]) . '")', + ] + ); + } + } + } +} diff --git a/ViewModel/Cookie/NoticeDataProvider.php b/ViewModel/Cookie/NoticeDataProvider.php deleted file mode 100644 index 5dfdb397..00000000 --- a/ViewModel/Cookie/NoticeDataProvider.php +++ /dev/null @@ -1,36 +0,0 @@ -privacyMessage = $privacyMessage; - } - - public function getTemplate(string $defaultTemplate, string $customTemplate): string - { - return $this->privacyMessage->isEnabled() ? $customTemplate : $defaultTemplate; - } - - public function getLearnMoreUrl(): ?string - { - return $this->privacyMessage->getLearnMoreUrl(); - } - - public function getNoticeHtml(): string - { - return $this->privacyMessage->getDisclosureInformationHtml(); - } -} diff --git a/ViewModel/Customer/Guest/EraseDataProvider.php b/ViewModel/Customer/Guest/EraseDataProvider.php index f15efbbd..31777eec 100644 --- a/ViewModel/Customer/Guest/EraseDataProvider.php +++ b/ViewModel/Customer/Guest/EraseDataProvider.php @@ -12,40 +12,24 @@ use Magento\Sales\Api\Data\OrderInterface; use Opengento\Gdpr\Api\EraseEntityCheckerInterface; -final class EraseDataProvider implements ArgumentInterface +class EraseDataProvider implements ArgumentInterface { - private EraseEntityCheckerInterface $eraseEntityChecker; - - private Registry $registry; - - /** - * @var null|bool - */ - private ?bool $canCancel; - - /** - * @var null|bool - */ - private ?bool $canCreate; + private ?bool $canCancel = null; + private ?bool $canCreate = null; public function __construct( - EraseEntityCheckerInterface $eraseEntityChecker, - Registry $registry - ) { - $this->eraseEntityChecker = $eraseEntityChecker; - $this->registry = $registry; - } + private EraseEntityCheckerInterface $eraseEntityChecker, + private Registry $registry + ) {} public function canCancel(): bool { - return $this->canCancel ?? - $this->canCancel = $this->eraseEntityChecker->canCancel($this->currentOrderId(), 'order'); + return $this->canCancel ??= $this->eraseEntityChecker->canCancel($this->currentOrderId(), 'order'); } public function canCreate(): bool { - return $this->canCreate ?? - $this->canCreate = $this->eraseEntityChecker->canCreate($this->currentOrderId(), 'order'); + return $this->canCreate ??= $this->eraseEntityChecker->canCreate($this->currentOrderId(), 'order'); } private function currentOrderId(): int @@ -53,6 +37,6 @@ private function currentOrderId(): int /** @var OrderInterface $order */ $order = $this->registry->registry('current_order'); - return (int) $order->getEntityId(); + return (int)$order->getEntityId(); } } diff --git a/ViewModel/Customer/Guest/ExportDataProvider.php b/ViewModel/Customer/Guest/ExportDataProvider.php index 8aa04ed5..f041ce8b 100644 --- a/ViewModel/Customer/Guest/ExportDataProvider.php +++ b/ViewModel/Customer/Guest/ExportDataProvider.php @@ -12,40 +12,24 @@ use Magento\Sales\Api\Data\OrderInterface; use Opengento\Gdpr\Api\ExportEntityCheckerInterface; -final class ExportDataProvider implements ArgumentInterface +class ExportDataProvider implements ArgumentInterface { - private ExportEntityCheckerInterface $exportEntityChecker; - - private Registry $registry; - - /** - * @var bool|null - */ - private ?bool $isExportEntityExists; - - /** - * @var bool|null - */ - private ?bool $isExported; + private ?bool $isExportEntityExists = null; + private ?bool $isExported = null; public function __construct( - ExportEntityCheckerInterface $exportEntityChecker, - Registry $registry - ) { - $this->exportEntityChecker = $exportEntityChecker; - $this->registry = $registry; - } + private ExportEntityCheckerInterface $exportEntityChecker, + private Registry $registry + ) {} public function hasExport(): bool { - return $this->isExportEntityExists ?? - $this->isExportEntityExists = $this->exportEntityChecker->exists($this->currentOrderId(), 'order'); + return $this->isExportEntityExists ??= $this->exportEntityChecker->exists($this->currentOrderId(), 'order'); } public function isExported(): bool { - return $this->isExported ?? - $this->isExported = $this->exportEntityChecker->isExported($this->currentOrderId(), 'order'); + return $this->isExported ??= $this->exportEntityChecker->isExported($this->currentOrderId(), 'order'); } private function currentOrderId(): int @@ -53,6 +37,6 @@ private function currentOrderId(): int /** @var OrderInterface $order */ $order = $this->registry->registry('current_order'); - return (int) $order->getEntityId(); + return (int)$order->getEntityId(); } } diff --git a/ViewModel/Customer/Privacy/EraseCustomerDataProvider.php b/ViewModel/Customer/Privacy/EraseCustomerDataProvider.php index b6a77900..b731151e 100644 --- a/ViewModel/Customer/Privacy/EraseCustomerDataProvider.php +++ b/ViewModel/Customer/Privacy/EraseCustomerDataProvider.php @@ -11,32 +11,15 @@ use Magento\Framework\View\Element\Block\ArgumentInterface; use Opengento\Gdpr\Api\EraseEntityCheckerInterface; -final class EraseCustomerDataProvider implements ArgumentInterface +class EraseCustomerDataProvider implements ArgumentInterface { - private EraseEntityCheckerInterface $eraseEntityChecker; - - /** - * @var Session - */ - private Session $session; - - /** - * @var null|bool - */ - private ?bool $canCancel; - - /** - * @var null|bool - */ - private ?bool $canCreate; + private ?bool $canCancel = null; + private ?bool $canCreate = null; public function __construct( - EraseEntityCheckerInterface $eraseEntityChecker, - Session $session - ) { - $this->eraseEntityChecker = $eraseEntityChecker; - $this->session = $session; - } + private EraseEntityCheckerInterface $eraseEntityChecker, + private Session $session + ) {} public function canCancel(): bool { @@ -50,6 +33,6 @@ public function canCreate(): bool private function currentCustomerId(): int { - return (int) $this->session->getCustomerId(); + return (int)$this->session->getCustomerId(); } } diff --git a/ViewModel/Customer/Privacy/EraseDataProvider.php b/ViewModel/Customer/Privacy/EraseDataProvider.php index 1bdcc634..0772c94a 100644 --- a/ViewModel/Customer/Privacy/EraseDataProvider.php +++ b/ViewModel/Customer/Privacy/EraseDataProvider.php @@ -13,32 +13,24 @@ use Magento\Framework\View\Element\BlockFactory; use Magento\Store\Model\ScopeInterface; -final class EraseDataProvider implements ArgumentInterface +class EraseDataProvider implements ArgumentInterface { private const CONFIG_PATH_ERASURE_INFORMATION_BLOCK = 'gdpr/erasure/block_id'; private const CONFIG_PATH_ANONYMIZE_INFORMATION_BLOCK = 'gdpr/anonymize/block_id'; - private ScopeConfigInterface $scopeConfig; - - private BlockFactory $blockFactory; - - private ?string $erasureInformation; - - private ?string $anonymizeInformation; + private ?string $erasureInformation = null; + private ?string $anonymizeInformation = null; public function __construct( - ScopeConfigInterface $scopeConfig, - BlockFactory $blockFactory - ) { - $this->scopeConfig = $scopeConfig; - $this->blockFactory = $blockFactory; - } + private ScopeConfigInterface $scopeConfig, + private BlockFactory $blockFactory + ) {} public function getErasureInformationHtml(): string { return $this->erasureInformation ??= $this->blockFactory->createBlock( BlockByIdentifier::class, - ['data' => ['identifier' => (string) $this->scopeConfig->getValue( + ['data' => ['identifier' => (string)$this->scopeConfig->getValue( self::CONFIG_PATH_ERASURE_INFORMATION_BLOCK, ScopeInterface::SCOPE_STORE )]] @@ -49,7 +41,7 @@ public function getAnonymizeInformationHtml(): string { return $this->anonymizeInformation ??= $this->blockFactory->createBlock( BlockByIdentifier::class, - ['data' => ['identifier' => (string) $this->scopeConfig->getValue( + ['data' => ['identifier' => (string)$this->scopeConfig->getValue( self::CONFIG_PATH_ANONYMIZE_INFORMATION_BLOCK, ScopeInterface::SCOPE_STORE )]] diff --git a/ViewModel/Customer/Privacy/ExportCustomerDataProvider.php b/ViewModel/Customer/Privacy/ExportCustomerDataProvider.php index 4d55f526..f022288f 100644 --- a/ViewModel/Customer/Privacy/ExportCustomerDataProvider.php +++ b/ViewModel/Customer/Privacy/ExportCustomerDataProvider.php @@ -11,32 +11,15 @@ use Magento\Framework\View\Element\Block\ArgumentInterface; use Opengento\Gdpr\Api\ExportEntityCheckerInterface; -final class ExportCustomerDataProvider implements ArgumentInterface +class ExportCustomerDataProvider implements ArgumentInterface { - private ExportEntityCheckerInterface $exportEntityChecker; - - /** - * @var Session - */ - private Session $session; - - /** - * @var null|bool - */ - private ?bool $isExportEntityExists; - - /** - * @var null|bool - */ - private ?bool $isExported; + private ?bool $isExportEntityExists = null; + private ?bool $isExported = null; public function __construct( - ExportEntityCheckerInterface $exportEntityChecker, - Session $session - ) { - $this->exportEntityChecker = $exportEntityChecker; - $this->session = $session; - } + private ExportEntityCheckerInterface $exportEntityChecker, + private Session $session + ) {} public function hasExport(): bool { @@ -50,6 +33,6 @@ public function isExported(): bool private function currentCustomerId(): int { - return (int) $this->session->getCustomerId(); + return (int)$this->session->getCustomerId(); } } diff --git a/ViewModel/Customer/Privacy/ExportDataProvider.php b/ViewModel/Customer/Privacy/ExportDataProvider.php index 37aef3f6..3a5455d1 100644 --- a/ViewModel/Customer/Privacy/ExportDataProvider.php +++ b/ViewModel/Customer/Privacy/ExportDataProvider.php @@ -13,29 +13,22 @@ use Magento\Framework\View\Element\BlockFactory; use Magento\Store\Model\ScopeInterface; -final class ExportDataProvider implements ArgumentInterface +class ExportDataProvider implements ArgumentInterface { private const CONFIG_PATH_EXPORT_INFORMATION_BLOCK = 'gdpr/export/block_id'; - private ScopeConfigInterface $scopeConfig; - - private BlockFactory $blockFactory; - - private ?string $exportInformation; + private ?string $exportInformation = null; public function __construct( - ScopeConfigInterface $scopeConfig, - BlockFactory $blockFactory - ) { - $this->scopeConfig = $scopeConfig; - $this->blockFactory = $blockFactory; - } + private ScopeConfigInterface $scopeConfig, + private BlockFactory $blockFactory + ) {} public function getExportInformationHtml(): string { return $this->exportInformation ??= $this->blockFactory->createBlock( BlockByIdentifier::class, - ['data' => ['identifier' => (string) $this->scopeConfig->getValue( + ['data' => ['identifier' => (string)$this->scopeConfig->getValue( self::CONFIG_PATH_EXPORT_INFORMATION_BLOCK, ScopeInterface::SCOPE_STORE )]] diff --git a/ViewModel/Customer/Privacy/SettingsDataProvider.php b/ViewModel/Customer/Privacy/SettingsDataProvider.php index eb688b77..188e19bf 100644 --- a/ViewModel/Customer/Privacy/SettingsDataProvider.php +++ b/ViewModel/Customer/Privacy/SettingsDataProvider.php @@ -13,29 +13,22 @@ use Magento\Framework\View\Element\BlockFactory; use Magento\Store\Model\ScopeInterface; -final class SettingsDataProvider implements ArgumentInterface +class SettingsDataProvider implements ArgumentInterface { private const CONFIG_PATH_GENERAL_INFORMATION_BLOCK = 'gdpr/general/block_id'; - private ScopeConfigInterface $scopeConfig; - - private BlockFactory $blockFactory; - - private ?string $informationHtml; + private ?string $informationHtml = null; public function __construct( - ScopeConfigInterface $scopeConfig, - BlockFactory $blockFactory - ) { - $this->scopeConfig = $scopeConfig; - $this->blockFactory = $blockFactory; - } + private ScopeConfigInterface $scopeConfig, + private BlockFactory $blockFactory + ) {} public function getPrivacyInformationHtml(): string { return $this->informationHtml ??= $this->blockFactory->createBlock( BlockByIdentifier::class, - ['data' => ['identifier' => (string) $this->scopeConfig->getValue( + ['data' => ['identifier' => (string)$this->scopeConfig->getValue( self::CONFIG_PATH_GENERAL_INFORMATION_BLOCK, ScopeInterface::SCOPE_STORE )]] diff --git a/composer.json b/composer.json index 87113612..f3dd66f8 100755 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "privacy" ], "require": { - "php": "^7.4||^8.0", + "php": "^8.2", "ext-zip": "*", "tecnickcom/tcpdf": "^6.4", "magento/framework": "^103.0", @@ -28,8 +28,7 @@ }, "require-dev": { "magento/magento-coding-standard": "^5", - "magento/marketplace-eqp": "^4.0", - "roave/security-advisories": "dev-master" + "magento/marketplace-eqp": "^4.0" }, "type": "magento2-module", "license": [ diff --git a/etc/acl.xml b/etc/acl.xml index 48270a77..d657f60c 100755 --- a/etc/acl.xml +++ b/etc/acl.xml @@ -28,13 +28,6 @@ - - - - - - - diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index d6ce69ab..7b57f68d 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -6,59 +6,7 @@ */ --> - - - - - - Opengento\Gdpr\Api\Data\ActionEntityInterface::MESSAGE - - - - - - - Opengento\Gdpr\Model\Action\EraseCreateExecuteAction - - - - - Opengento\Gdpr\Model\Action\EraseCreateExecuteAction - - - - - Opengento\Gdpr\Model\Action\EraseCreateExecuteAction - - - - - Opengento\Gdpr\Model\Action\ExportCreateOrExecuteAction - - - - - Opengento\Gdpr\Model\Action\ExportCreateOrExecuteAction - - - - - Opengento\Gdpr\Model\Action\ExportCreateOrExecuteAction - Opengento\Gdpr\Model\Archive\MoveToZip - - - - - Opengento\Gdpr\Model\Action\ActionFactory - actions - - - - - Magento\Framework\Model\EntitySnapshot\AttributeProvider - - Magento\Customer\Api\CustomerMetadataInterface diff --git a/etc/adminhtml/menu.xml b/etc/adminhtml/menu.xml deleted file mode 100644 index 5ae370ed..00000000 --- a/etc/adminhtml/menu.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - diff --git a/etc/adminhtml/routes.xml b/etc/adminhtml/routes.xml index f8bb8ba8..81c6c761 100644 --- a/etc/adminhtml/routes.xml +++ b/etc/adminhtml/routes.xml @@ -7,9 +7,6 @@ --> - - - diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 0f697234..e40310e8 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -12,15 +12,11 @@ - - - - diff --git a/etc/adminhtml/system/action.xml b/etc/adminhtml/system/action.xml deleted file mode 100644 index 4a847710..00000000 --- a/etc/adminhtml/system/action.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - -
- separator-top - - opengento_gdpr - Opengento_Gdpr::config - - - -
-
diff --git a/etc/adminhtml/system/cookie.xml b/etc/adminhtml/system/cookie.xml deleted file mode 100644 index 0e2b4065..00000000 --- a/etc/adminhtml/system/cookie.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - diff --git a/etc/adminhtml/system/erasure.xml b/etc/adminhtml/system/erasure.xml index e586a386..00135518 100644 --- a/etc/adminhtml/system/erasure.xml +++ b/etc/adminhtml/system/erasure.xml @@ -13,7 +13,7 @@ Opengento_Gdpr::config - + It will enable the erase action to the storefront. Magento\Config\Model\Config\Source\Enabledisable @@ -27,7 +27,7 @@ gdpr/erasure/block_id - + Erasure delay in minute before the execution by the cron. From 60 to 43800. validate-number validate-number-range number-range-60-43800 @@ -36,14 +36,14 @@ gdpr/erasure/delay - + 1 gdpr/erasure/entity_schedule - + The time is in days. validate-number validate-number-range number-range-0-1095 @@ -52,14 +52,14 @@ gdpr/erasure/entity_max_age - + 1 gdpr/erasure/entity_max_age_schedule - + The time is in days. validate-number validate-number-range number-range-0-3650 @@ -68,7 +68,7 @@ gdpr/erasure/sales_max_age - + Opengento\Gdpr\Model\Config\Source\OrderPendingStates @@ -77,7 +77,7 @@ 0 gdpr/erasure/allowed_states - + Defines the components erasure strategy with the component/erase processor mapper for the customers. Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\Customer\EraseComponentsProcessors @@ -88,7 +88,7 @@ 1 gdpr/erasure/customer_components_processors - + Defines the components erasure strategy with the component/erase processor mapper for the guests. Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\Order\EraseComponentsProcessors @@ -110,7 +110,7 @@ Magento\Cms\Model\Config\Source\Block gdpr/anonymize/block_id - + We will delete the customer if he has no orders. It's only applicable if the component "customer" use the "anonymize" processor. Magento\Config\Model\Config\Source\Yesno @@ -118,7 +118,7 @@ - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -127,7 +127,7 @@ gdpr/anonymize/customer_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -136,7 +136,7 @@ gdpr/anonymize/customer_custom_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -148,7 +148,7 @@ - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -157,7 +157,7 @@ gdpr/anonymize/customer_address_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -166,7 +166,7 @@ gdpr/anonymize/customer_address_custom_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -178,7 +178,7 @@ - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -187,7 +187,7 @@ gdpr/anonymize/quote_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -196,7 +196,7 @@ gdpr/anonymize/quote_custom_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -208,7 +208,7 @@ - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -217,7 +217,7 @@ gdpr/anonymize/quote_address_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -226,7 +226,7 @@ gdpr/anonymize/quote_address_custom_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -238,7 +238,7 @@ - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -247,7 +247,7 @@ gdpr/anonymize/order_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -256,7 +256,7 @@ gdpr/anonymize/order_custom_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -268,7 +268,7 @@ - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -277,7 +277,7 @@ gdpr/anonymize/order_address_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -286,7 +286,7 @@ gdpr/anonymize/order_address_custom_attributes - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized @@ -298,7 +298,7 @@ - + Opengento\Gdpr\Block\Adminhtml\Config\Form\Field\AttributesAnonymizers Magento\Config\Model\Config\Backend\Serialized\ArraySerialized diff --git a/etc/adminhtml/system/export.xml b/etc/adminhtml/system/export.xml index 60e768a5..7fca75cb 100644 --- a/etc/adminhtml/system/export.xml +++ b/etc/adminhtml/system/export.xml @@ -13,7 +13,7 @@ Opengento_Gdpr::config - + It will enable the export action to the storefront. Magento\Config\Model\Config\Source\Enabledisable @@ -28,7 +28,7 @@ gdpr/export/block_id - + Select formats of the export. Notice: At least one human and one machine readable format should be selected. Opengento\Gdpr\Model\Config\Source\ExportRenderer @@ -48,14 +48,14 @@ gdpr/export/file_name - + 1 gdpr/export/entity_schedule - + Export life time in minute before it is removed from the server. Opengento\Gdpr\Model\Config\Backend\Export @@ -65,7 +65,7 @@ gdpr/export/life_time - + 1 @@ -74,7 +74,10 @@ - + + 1 + + This attributes list will be exported when processed. Opengento\Gdpr\Model\Config\Source\CustomerAttributes @@ -85,7 +88,7 @@ gdpr/export/customer_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -95,7 +98,7 @@ gdpr/export/customer_custom_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -108,7 +111,10 @@ - + + 1 + + This attributes list will be exported when processed. Opengento\Gdpr\Model\Config\Source\CustomerAddressAttributes @@ -119,7 +125,7 @@ gdpr/export/customer_address_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -129,7 +135,7 @@ gdpr/export/customer_address_custom_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -142,7 +148,10 @@ - + + 1 + + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -152,7 +161,7 @@ gdpr/export/quote_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -162,7 +171,7 @@ gdpr/export/quote_custom_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -175,7 +184,10 @@ - + + 1 + + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -185,7 +197,7 @@ gdpr/export/quote_address_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -195,7 +207,7 @@ gdpr/export/quote_address_custom_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -208,7 +220,10 @@ - + + 1 + + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -218,7 +233,7 @@ gdpr/export/order_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -228,7 +243,7 @@ gdpr/export/order_custom_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -241,7 +256,10 @@ - + + 1 + + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -251,7 +269,7 @@ gdpr/export/order_address_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -261,7 +279,7 @@ gdpr/export/order_address_custom_attributes - + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export @@ -274,7 +292,10 @@ - + + 1 + + Comma-separated Opengento\Gdpr\Model\Config\Backend\Export diff --git a/etc/adminhtml/system/general.xml b/etc/adminhtml/system/general.xml index e28a9bf0..6967dce5 100644 --- a/etc/adminhtml/system/general.xml +++ b/etc/adminhtml/system/general.xml @@ -13,7 +13,7 @@ Opengento_Gdpr::config - + It will enable the module features in the admin and frontend ui. Magento\Config\Model\Config\Source\Yesno diff --git a/etc/adminhtml/system/notification.xml b/etc/adminhtml/system/notification.xml index 99ceef56..14652d02 100644 --- a/etc/adminhtml/system/notification.xml +++ b/etc/adminhtml/system/notification.xml @@ -19,7 +19,7 @@ It will enable the module features in the admin and frontend ui. Magento\Config\Model\Config\Source\Yesno - gdpr/notification/erase_enabled + gdpr/notification/enabled diff --git a/etc/config.xml b/etc/config.xml index b03705ce..cbdb411e 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -12,111 +12,320 @@ 0 privacy-policy-cookie-restriction-mode - - - + + email + email + + + prefix + alphaUpper + + + firstname + anonymous + + + middlename + anonymous + + + lastname + anonymous + + + suffix + alphaUpper + + + dob + date + + + gender + number + + + taxvat + alphaUpper + - + + city + alphaUpper + + + company + anonymous + + + country_id + nullValue + + + fax + phone + + + prefix + alphaUpper + + + firstname + anonymous + + + middlename + anonymous + + + lastname + anonymous + + + suffix + alphaUpper + + + postcode + number + + + region + nullValue + + + street + street + + + telephone + phone + + + vat_id + alphaUpper + - + + customer_email + email + + + customer_prefix + alphaUpper + + + customer_firstname + anonymous + + + customer_middlename + anonymous + + + lastname + anonymous + + + customer_suffix + alphaUpper + + + customer_dob + date + + + customer_gender + number + + + customer_taxvat + alphaUpper + + + remote_ip + nullValue + - + + city + alphaUpper + + + company + anonymous + + + country_id + nullValue + + + fax + phone + + + email + email + + + prefix + alphaUpper + + + firstname + anonymous + + + middlename + anonymous + + + lastname + anonymous + + + suffix + alphaUpper + + + postcode + number + + + region + nullValue + + + street + street + + + telephone + phone + + + vat_id + alphaUpper + - + + customer_email + email + + + customer_prefix + alphaUpper + + + customer_firstname + anonymous + + + customer_middlename + anonymous + + + lastname + anonymous + + + customer_suffix + alphaUpper + + + customer_dob + date + + + customer_gender + number + + + customer_taxvat + alphaUpper + + + remote_ip + nullValue + + + x_forwarded_for + nullValue + - + + city + alphaUpper + + + company + anonymous + + + country_id + nullValue + + + fax + phone + + + email + email + + + prefix + alphaUpper + + + firstname + anonymous + + + middlename + anonymous + + + lastname + anonymous + + + suffix + alphaUpper + + + postcode + number + + + region + nullValue + + + street + street + + + telephone + phone + + + vat_id + alphaUpper + - + + email + email + @@ -129,20 +338,40 @@ canceled,closed,complete 1 - + + customer + anonymize + + + customer_address + anonymize + + + quote + delete + + + order + anonymize + + + subscriber + delete + - + + quote + delete + + + order + anonymize + + + subscriber + delete + @@ -161,87 +390,33 @@ email - - 0 - - - - - 0 - - general - bcc - - - 0 - - general - bcc - - - - - 0 - - general - bcc - - - 0 - - general - bcc - - - - - 0 - - general - bcc - - - 0 - - general - bcc - - - - - - - 0 - - general - bcc - - - 0 - - general - bcc - - - - - 0 - - general - bcc - - - 0 - - general - bcc - - - - - 0 - + 1 + general + bcc + opengento_gdpr_notification_notification_erase_pending_template + opengento_gdpr_notification_notification_erase_pending_guest_template + 1 + general + bcc + opengento_gdpr_notification_notification_erase_succeeded_template + opengento_gdpr_notification_notification_erase_succeeded_guest_template + 1 + general + bcc + opengento_gdpr_notification_notification_erase_canceled_template + opengento_gdpr_notification_notification_erase_canceled_guest_template + 1 + general + bcc + opengento_gdpr_notification_notification_export_pending_template + opengento_gdpr_notification_notification_export_pending_guest_template + 1 + general + bcc + opengento_gdpr_notification_notification_export_ready_template + opengento_gdpr_notification_notification_export_ready_guest_template +
diff --git a/etc/db_schema.xml b/etc/db_schema.xml index b2c891ad..8c90064d 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -6,6 +6,7 @@ */ --> + @@ -18,15 +19,15 @@ - + - + @@ -55,23 +56,4 @@
- - - - - - - - - - - - - - - - - - -
diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json index 8829420a..28ff885d 100644 --- a/etc/db_schema_whitelist.json +++ b/etc/db_schema_whitelist.json @@ -13,8 +13,8 @@ "index": { "OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID": true, "OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_TYPE": true, - "OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_TYPE_ENTITY_ID": true, - "OPENGENTO_GDPR_ERASE_ENTITY_SCHEDULED_AT_STATE_STATUS": true + "OPENGENTO_GDPR_ERASE_ENTITY_IDENTITY": true, + "OPENGENTO_GDPR_ERASE_ENTITY_SCHEDULED_PROCESS": true }, "constraint": { "PRIMARY": true, @@ -35,31 +35,12 @@ "index": { "OPENGENTO_GDPR_EXPORT_ENTITY_ENTITY_ID": true, "OPENGENTO_GDPR_EXPORT_ENTITY_ENTITY_TYPE": true, - "OPENGENTO_GDPR_EXPORT_ENTITY_ENTITY_ID_ENTITY_TYPE": true, + "OPENGENTO_GDPR_EXPORT_ENTITY_IDENTITY": true, "OPENGENTO_GDPR_EXPORT_ENTITY_EXPORTED_AT": true, "OPENGENTO_GDPR_EXPORT_ENTITY_EXPIRED_AT": true }, "constraint": { "PRIMARY": true } - }, - "opengento_gdpr_action_entity": { - "column": { - "action_id": true, - "type": true, - "performed_from": true, - "performed_by": true, - "performed_at": true, - "state": true, - "message": true, - "parameters": true - }, - "index": { - "OPENGENTO_GDPR_ACTION_ENTITY_TYPE": true, - "OPENGENTO_GDPR_ACTION_ENTITY_STATE": true - }, - "constraint": { - "PRIMARY": true - } } -} \ No newline at end of file +} diff --git a/etc/di.xml b/etc/di.xml index 7e1a1864..7289651d 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -6,29 +6,21 @@ */ --> - - - - - - - - - - - Opengento\Gdpr\Model\ResourceModel\ActionEntity\Validator\StateValidator - - - - + - Opengento\Gdpr\Model\EraseEntityManagement + Opengento\Gdpr\Model\Erase\NotifyEraseEntityManagement + + + + + Opengento\Gdpr\Model\EraseEntityManagement\Proxy + Opengento\Gdpr\Model\Erase\NotifierRepository\Proxy @@ -36,13 +28,18 @@ - + + + + Opengento\Gdpr\Model\ExportEntityManagement\Proxy + Opengento\Gdpr\Model\Export\NotifierRepository\Proxy + + - Opengento\Gdpr\Api\ActionEntityRepositoryInterface Opengento\Gdpr\Api\EraseEntityRepositoryInterface Opengento\Gdpr\Api\ExportEntityRepositoryInterface @@ -51,7 +48,6 @@ - Magento\Framework\EntityManager\AbstractModelHydrator Magento\Framework\EntityManager\AbstractModelHydrator Magento\Framework\EntityManager\AbstractModelHydrator Magento\Framework\EntityManager\AbstractModelHydrator @@ -63,122 +59,6 @@ - - - - - Opengento\Gdpr\Model\Customer\Erase\Notifier\Pending - Opengento\Gdpr\Model\Order\Erase\Notifier\Pending - - - - - - - Opengento\Gdpr\Model\Customer\Erase\Notifier\Succeeded - Opengento\Gdpr\Model\Order\Erase\Notifier\Succeeded - - - - - - - Opengento\Gdpr\Model\Customer\Erase\Notifier\Canceled - Opengento\Gdpr\Model\Order\Erase\Notifier\Canceled - - - - - - - - Opengento\Gdpr\Model\Customer\Export\Notifier\Pending - Opengento\Gdpr\Model\Order\Export\Notifier\Pending - - - - - - - Opengento\Gdpr\Model\Customer\Export\Notifier\Ready - Opengento\Gdpr\Model\Order\Export\Notifier\Ready - - - - - - - - Opengento\Gdpr\Model\Action\EraseCreateAction - Opengento\Gdpr\Model\Action\EraseExecuteAction - Opengento\Gdpr\Model\Action\EraseCancelAction - Opengento\Gdpr\Model\Action\EraseCreateExecuteAction - Opengento\Gdpr\Model\Action\ExportCreateAction - Opengento\Gdpr\Model\Action\ExportExecuteAction - Opengento\Gdpr\Model\Action\ExportCreateOrExecuteAction - - - - - - erase_create - - Opengento\Gdpr\Model\Action\Erase\CreateAction - Opengento\Gdpr\Model\Action\Erase\CreateNotifier - - - - - - erase_execute - - Opengento\Gdpr\Model\Action\Erase\ExecuteAction - Opengento\Gdpr\Model\Action\Erase\ExecuteNotifier - - - - - - erase_cancel - - Opengento\Gdpr\Model\Action\Erase\CancelAction - Opengento\Gdpr\Model\Action\Erase\CancelNotifier - - - - - - erase_create_execute - - Opengento\Gdpr\Model\Action\Erase\CreateAction - Opengento\Gdpr\Model\Action\Erase\ExecuteAction - - - - - - export_create - - Opengento\Gdpr\Model\Action\Export\CreateAction - - - - - - export_execute - - Opengento\Gdpr\Model\Action\Export\ExportAction - - - - - - export_create_or_execute - - Opengento\Gdpr\Model\Action\Export\CreateOrExportAction - - - @@ -828,9 +708,8 @@ Opengento\Gdpr\Model\Config\Source\Order\EraseComponents - + - created_at Magento\Sales\Api\Data\OrderInterface::UPDATED_AT @@ -843,7 +722,7 @@ Opengento\Gdpr\Model\Order\SourceProvider\GuestFilterModifier - Opengento\Gdpr\Model\Order\SourceProvider\UpdatedAtFilterModifier + Opengento\Gdpr\Model\Order\SourceProvider\ExpireFilterModifier Opengento\Gdpr\Model\Order\SourceProvider\NotErasedFilterModifier @@ -865,16 +744,15 @@ - + - created_at created_at - Opengento\Gdpr\Model\Entity\SourceProvider\DefaultFilterModifier + Opengento\Gdpr\Model\Entity\SourceProvider\DefaultExpireFilterModifier @@ -1553,11 +1431,11 @@ - gdpr/notification/erasure/pending/customer/enabled - gdpr/notification/erasure/pending/customer/identity - gdpr/notification/erasure/pending/customer/copy_to - gdpr/notification/erasure/pending/customer/copy_method - gdpr/notification/erasure/pending/customer/template + gdpr/notification/erase_pending_enabled + gdpr/notification/erase_pending_identity + gdpr/notification/erase_pending_copy_to + gdpr/notification/erase_pending_copy_method + gdpr/notification/erase_pending_template @@ -1571,11 +1449,11 @@ - gdpr/notification/erasure/succeeded/customer/enabled - gdpr/notification/erasure/succeeded/customer/identity - gdpr/notification/erasure/succeeded/customer/copy_to - gdpr/notification/erasure/succeeded/customer/copy_method - gdpr/notification/erasure/succeeded/customer/template + gdpr/notification/erase_succeeded_enabled + gdpr/notification/erase_succeeded_identity + gdpr/notification/erase_succeeded_copy_to + gdpr/notification/erase_succeeded_copy_method + gdpr/notification/erase_succeeded_template @@ -1589,11 +1467,11 @@ - gdpr/notification/erasure/canceled/customer/enabled - gdpr/notification/erasure/canceled/customer/identity - gdpr/notification/erasure/canceled/customer/copy_to - gdpr/notification/erasure/canceled/customer/copy_method - gdpr/notification/erasure/canceled/customer/template + gdpr/notification/erase_canceled_enabled + gdpr/notification/erase_canceled_identity + gdpr/notification/erase_canceled_copy_to + gdpr/notification/erase_canceled_copy_method + gdpr/notification/erase_canceled_template @@ -1608,11 +1486,11 @@ - gdpr/notification/erasure/pending/order/enabled - gdpr/notification/erasure/pending/order/identity - gdpr/notification/erasure/pending/order/copy_to - gdpr/notification/erasure/pending/order/copy_method - gdpr/notification/erasure/pending/order/template + gdpr/notification/erase_pending_enabled + gdpr/notification/erase_pending_identity + gdpr/notification/erase_pending_copy_to + gdpr/notification/erase_pending_copy_method + gdpr/notification/erase_pending_guest_template @@ -1626,11 +1504,11 @@ - gdpr/notification/erasure/succeeded/order/enabled - gdpr/notification/erasure/succeeded/order/identity - gdpr/notification/erasure/succeeded/order/copy_to - gdpr/notification/erasure/succeeded/order/copy_method - gdpr/notification/erasure/succeeded/order/template + gdpr/notification/erase_succeeded_enabled + gdpr/notification/erase_succeeded_identity + gdpr/notification/erase_succeeded_copy_to + gdpr/notification/erase_succeeded_copy_method + gdpr/notification/erase_succeeded_guest_template @@ -1644,11 +1522,11 @@ - gdpr/notification/erasure/canceled/order/enabled - gdpr/notification/erasure/canceled/order/identity - gdpr/notification/erasure/canceled/order/copy_to - gdpr/notification/erasure/canceled/order/copy_method - gdpr/notification/erasure/canceled/order/template + gdpr/notification/erase_canceled_enabled + gdpr/notification/erase_canceled_identity + gdpr/notification/erase_canceled_copy_to + gdpr/notification/erase_canceled_copy_method + gdpr/notification/erase_canceled_guest_template @@ -1659,15 +1537,34 @@ + + + + + + Opengento\Gdpr\Model\Customer\Erase\Notifier\Pending + Opengento\Gdpr\Model\Order\Erase\Notifier\Pending + + + Opengento\Gdpr\Model\Customer\Erase\Notifier\Succeeded + Opengento\Gdpr\Model\Order\Erase\Notifier\Succeeded + + + Opengento\Gdpr\Model\Customer\Erase\Notifier\Canceled + Opengento\Gdpr\Model\Order\Erase\Notifier\Canceled + + + + - gdpr/notification/export/pending/customer/enabled - gdpr/notification/export/pending/customer/identity - gdpr/notification/export/pending/customer/copy_to - gdpr/notification/export/pending/customer/copy_method - gdpr/notification/export/pending/customer/template + gdpr/notification/export_pending_enabled + gdpr/notification/export_pending_identity + gdpr/notification/export_pending_copy_to + gdpr/notification/export_pending_copy_method + gdpr/notification/export_pending_template @@ -1681,11 +1578,11 @@ - gdpr/notification/export/ready/customer/enabled - gdpr/notification/export/ready/customer/identity - gdpr/notification/export/ready/customer/copy_to - gdpr/notification/export/ready/customer/copy_method - gdpr/notification/export/ready/customer/template + gdpr/notification/export_ready_enabled + gdpr/notification/export_ready_identity + gdpr/notification/export_ready_copy_to + gdpr/notification/export_ready_copy_method + gdpr/notification/export_ready_template @@ -1700,11 +1597,11 @@ - gdpr/notification/export/pending/order/enabled - gdpr/notification/export/pending/order/identity - gdpr/notification/export/pending/order/copy_to - gdpr/notification/export/pending/order/copy_method - gdpr/notification/export/pending/order/template + gdpr/notification/export_pending_enabled + gdpr/notification/export_pending_identity + gdpr/notification/export_pending_copy_to + gdpr/notification/export_pending_copy_method + gdpr/notification/export_pending_guest_template @@ -1718,11 +1615,11 @@ - gdpr/notification/export/ready/order/enabled - gdpr/notification/export/ready/order/identity - gdpr/notification/export/ready/order/copy_to - gdpr/notification/export/ready/order/copy_method - gdpr/notification/export/ready/order/template + gdpr/notification/export_ready_enabled + gdpr/notification/export_ready_identity + gdpr/notification/export_ready_copy_to + gdpr/notification/export_ready_copy_method + gdpr/notification/export_ready_guest_template @@ -1733,18 +1630,18 @@ - - - - opengento_gdpr_action_entity - Opengento\Gdpr\Model\ResourceModel\ActionEntity - - - + + - - Opengento\Gdpr\Model\ResourceModel\ActionEntity\SearchResult - Opengento\Gdpr\Model\ResourceModel\ActionEntity\SearchResult + + + Opengento\Gdpr\Model\Customer\Export\Notifier\Pending + Opengento\Gdpr\Model\Order\Export\Notifier\Pending + + + Opengento\Gdpr\Model\Customer\Export\Notifier\Ready + Opengento\Gdpr\Model\Order\Export\Notifier\Ready + @@ -1753,13 +1650,11 @@ Magento\Framework\App\State\Proxy Magento\Framework\Registry\Proxy - Opengento\Gdpr\Model\Action\EraseCreateExecuteAction Magento\Framework\App\State\Proxy - Opengento\Gdpr\Model\Action\ExportCreateOrExecuteAction diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index defe7395..edf7003a 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -6,73 +6,10 @@ */ --> - - - - Opengento\Gdpr\Model\Action\Export\CreateAction - Opengento\Gdpr\Model\Action\Export\CreateNotifier - - - - - - - Opengento\Gdpr\Model\Action\Export\ExportAction - Opengento\Gdpr\Model\Action\Export\ExportNotifier - - - - - - - Opengento\Gdpr\Model\Action\Export\CreateOrExportAction - Opengento\Gdpr\Model\Action\Export\ExportNotifier - - - - - - - Opengento\Gdpr\Model\Action\PerformedBy\Guest - Opengento\Gdpr\Model\Action\PerformedBy\Customer - - - - Magento\Sales\Controller\Guest\OrderLoader - - - Opengento\Gdpr\Model\Action\EraseCreateAction - - - - - Opengento\Gdpr\Model\Action\EraseCreateAction - - - - - Opengento\Gdpr\Model\Action\EraseCancelAction - - - - - Opengento\Gdpr\Model\Action\EraseCancelAction - - - - - Opengento\Gdpr\Model\Action\ExportCreateAction - - - - - Opengento\Gdpr\Model\Action\ExportCreateAction - - diff --git a/view/adminhtml/layout/gdpr_action_index.xml b/view/adminhtml/layout/gdpr_action_index.xml deleted file mode 100644 index f8303a82..00000000 --- a/view/adminhtml/layout/gdpr_action_index.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - diff --git a/view/adminhtml/layout/gdpr_action_new.xml b/view/adminhtml/layout/gdpr_action_new.xml deleted file mode 100644 index 99e6e74c..00000000 --- a/view/adminhtml/layout/gdpr_action_new.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - diff --git a/view/adminhtml/layout/sales_order_view.xml b/view/adminhtml/layout/sales_order_view.xml index 17478eb6..8da82ce7 100644 --- a/view/adminhtml/layout/sales_order_view.xml +++ b/view/adminhtml/layout/sales_order_view.xml @@ -8,8 +8,8 @@ - - + + diff --git a/view/adminhtml/ui_component/customer_form.xml b/view/adminhtml/ui_component/customer_form.xml index e7eb29e6..ccd5a5d5 100644 --- a/view/adminhtml/ui_component/customer_form.xml +++ b/view/adminhtml/ui_component/customer_form.xml @@ -8,8 +8,8 @@
- - - gdpr_action_columns - - gdpr_action_listing.gdpr_action_listing_data_source - -
- - - - action_id - - - - Opengento_Gdpr::gdpr_actions - - - id - action_id - - - - - - true - - - - - - - - - - - editSelected - gdpr_action_listing.gdpr_action_listing.gdpr_action_columns_editor - - edit - - - - - - - Are you sure you want to delete the action log? - Delete items - - - delete - - - - - - - - - - - - false - - action_id - true - gdpr_action_listing.gdpr_action_listing.gdpr_action_columns.ids - - - - gdpr_action_listing.gdpr_action_listing.gdpr_action_columns_editor - startEdit - - ${ $.$data.rowIndex } - true - - - - - - - action_id - - - - - textRange - - asc - - - - - text - - true - - - - - text - - true - - - - - text - - true - - - - - dateRange - date - - true - - - - - - select - select - - - - - - text - - text - - - true - - - - - text - - text - - - true - - - - diff --git a/view/base/templates/export/renderer/default.phtml b/view/base/templates/export/renderer/default.phtml index 7fc707aa..a05b2f91 100644 --- a/view/base/templates/export/renderer/default.phtml +++ b/view/base/templates/export/renderer/default.phtml @@ -24,7 +24,7 @@ $exportData = array_filter($viewModel->toArray()); if (!function_exists('formatLabel')) { function formatLabel($label): string { - return ucwords(str_replace('_', ' ', (string) $label)); + return ucwords(str_replace('_', ' ', (string)$label)); } } if (!function_exists('renderNestedItems')) { diff --git a/view/frontend/email/erase_pending.html b/view/frontend/email/erase_pending.html index a526e4d7..8e192d2e 100644 --- a/view/frontend/email/erase_pending.html +++ b/view/frontend/email/erase_pending.html @@ -19,7 +19,7 @@

{{trans "We have received a request to erase the information associated with your account at %store_name." store_name=$store.getFrontendName()}}

-

{{trans 'You can cancel the erase within %delay hours by logging into your account.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}

+

{{trans 'You can cancel the erase within %delay hours by logging into your account.' delay=$delay account_url=$this.getUrl($store,'customer/privacy/settings',[_nosid:1]) |raw}}

diff --git a/view/frontend/email/erase_pending_guest.html b/view/frontend/email/erase_pending_guest.html index e5d34c39..e971c6bf 100644 --- a/view/frontend/email/erase_pending_guest.html +++ b/view/frontend/email/erase_pending_guest.html @@ -19,7 +19,7 @@

{{trans "We have received a request to erase the information associated with your account at %store_name." store_name=$store.getFrontendName()}}

-

{{trans 'You can cancel the erase within %delay hours by logging into your account.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}

+

{{trans 'You can cancel the erase within %delay hours by logging into your account.' delay=$delay account_url=$this.getUrl($store,'sales/guest/form',[_nosid:1]) |raw}}

diff --git a/view/frontend/email/export_pending.html b/view/frontend/email/export_pending.html index 327177ea..d509b559 100644 --- a/view/frontend/email/export_pending.html +++ b/view/frontend/email/export_pending.html @@ -19,7 +19,7 @@

{{trans "We have received a request to export the information associated with your account at %store_name." store_name=$store.getFrontendName()}}

-

{{trans "We will notify you when the export will be ready. The action will be available in your account."}}

+

{{trans "We will notify you when the export will be ready. The action will be available by logging into your account." account_url=$this.getUrl($store,'customer/privacy/settings',[_nosid:1]) |raw}}

diff --git a/view/frontend/email/export_pending_guest.html b/view/frontend/email/export_pending_guest.html index 752396b1..cf379f27 100644 --- a/view/frontend/email/export_pending_guest.html +++ b/view/frontend/email/export_pending_guest.html @@ -19,7 +19,7 @@

{{trans "We have received a request to export the information associated with your account at %store_name." store_name=$store.getFrontendName()}}

-

{{trans "We will notify you when the export will be ready. The action will be available in your account."}}

+

{{trans "We will notify you when the export will be ready. The action will be available by logging into your account." account_url=$this.getUrl($store,'sales/guest/form',[_nosid:1]) |raw}}

diff --git a/view/frontend/email/export_ready.html b/view/frontend/email/export_ready.html index 2b443699..3191253c 100644 --- a/view/frontend/email/export_ready.html +++ b/view/frontend/email/export_ready.html @@ -19,7 +19,7 @@

{{trans "We have received a request to export the information associated with your account at %store_name." store_name=$store.getFrontendName()}}

-

{{trans "The export of you personal data is ready. The action is now available in your account."}}

+

{{trans "The export of you personal data is ready. The action is now available by logging into your account." account_url=$this.getUrl($store,'customer/privacy/settings',[_nosid:1]) |raw}}

diff --git a/view/frontend/email/export_ready_guest.html b/view/frontend/email/export_ready_guest.html index 6ad736c9..a92864f0 100644 --- a/view/frontend/email/export_ready_guest.html +++ b/view/frontend/email/export_ready_guest.html @@ -19,7 +19,7 @@

{{trans "We have received a request to export the information associated with your account at %store_name." store_name=$store.getFrontendName()}}

-

{{trans "The export of you personal data is ready. The action is now available in your account."}}

+

{{trans "The export of you personal data is ready. The action is now available by logging into your account." account_url=$this.getUrl($store,'sales/guest/form',[_nosid:1]) |raw}}

diff --git a/view/frontend/layout/default.xml b/view/frontend/layout/default.xml deleted file mode 100644 index 1ba1a722..00000000 --- a/view/frontend/layout/default.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - Magento_Cookie::html/notices.phtml - Opengento_Gdpr::cookie/notices.phtml - - Opengento\Gdpr\ViewModel\Cookie\NoticeDataProvider - - - - diff --git a/view/frontend/templates/account/erase.phtml b/view/frontend/templates/account/erase.phtml index 0dea7a27..467f6178 100755 --- a/view/frontend/templates/account/erase.phtml +++ b/view/frontend/templates/account/erase.phtml @@ -11,8 +11,6 @@ use Opengento\Gdpr\ViewModel\Customer\Privacy\SettingsDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var SettingsDataProvider $settingsDataProvider */ $settingsDataProvider = $block->getData('settingsDataProvider'); ?> diff --git a/view/frontend/templates/account/privacy/erase.phtml b/view/frontend/templates/account/privacy/erase.phtml index 3f6100ea..19d7f582 100755 --- a/view/frontend/templates/account/privacy/erase.phtml +++ b/view/frontend/templates/account/privacy/erase.phtml @@ -12,8 +12,6 @@ use Opengento\Gdpr\ViewModel\Customer\Privacy\EraseDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var EraseDataProvider $eraseDataProvider */ $eraseDataProvider = $block->getData('eraseDataProvider'); /** @var EraseCustomerDataProvider $eraseCustomerDataProvider */ diff --git a/view/frontend/templates/account/privacy/export.phtml b/view/frontend/templates/account/privacy/export.phtml index 5af9dd66..04c07931 100755 --- a/view/frontend/templates/account/privacy/export.phtml +++ b/view/frontend/templates/account/privacy/export.phtml @@ -12,8 +12,6 @@ use Opengento\Gdpr\ViewModel\Customer\Privacy\ExportDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var ExportDataProvider $exportDataProvider */ $exportDataProvider = $block->getData('exportDataProvider'); /** @var ExportCustomerDataProvider $exportCustomerDataProvider */ diff --git a/view/frontend/templates/account/settings.phtml b/view/frontend/templates/account/settings.phtml index 4c9b26fc..9ef424e1 100755 --- a/view/frontend/templates/account/settings.phtml +++ b/view/frontend/templates/account/settings.phtml @@ -11,8 +11,6 @@ use Opengento\Gdpr\ViewModel\Customer\Privacy\SettingsDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var SettingsDataProvider $settingsDataProvider */ $settingsDataProvider = $block->getData('settingsDataProvider'); ?> diff --git a/view/frontend/templates/cookie/notices.phtml b/view/frontend/templates/cookie/notices.phtml deleted file mode 100644 index 1149bd6d..00000000 --- a/view/frontend/templates/cookie/notices.phtml +++ /dev/null @@ -1,59 +0,0 @@ -getData('cookieHelper'); -/** @var NoticeDataProvider $noticeDataProvider */ -$noticeDataProvider = $block->getData('noticeDataProvider'); - -$learnMoreUrl = $noticeDataProvider->getLearnMoreUrl() ?: $block->getPrivacyPolicyLink() -?> -isCookieRestrictionModeEnabled()): ?> - - renderStyleAsTag('display: none;', 'div#notice-cookie-block') ?> - - diff --git a/view/frontend/templates/order/info/buttons/download.phtml b/view/frontend/templates/order/info/buttons/download.phtml index 75f04dc4..2426e29f 100644 --- a/view/frontend/templates/order/info/buttons/download.phtml +++ b/view/frontend/templates/order/info/buttons/download.phtml @@ -11,8 +11,6 @@ use Opengento\Gdpr\ViewModel\Customer\Guest\ExportDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var ExportDataProvider $exportDataProvider */ $exportDataProvider = $block->getData('exportDataProvider'); ?> diff --git a/view/frontend/templates/order/info/buttons/erase.phtml b/view/frontend/templates/order/info/buttons/erase.phtml index 3248a10e..3d6c2476 100644 --- a/view/frontend/templates/order/info/buttons/erase.phtml +++ b/view/frontend/templates/order/info/buttons/erase.phtml @@ -11,8 +11,6 @@ use Opengento\Gdpr\ViewModel\Customer\Guest\EraseDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var EraseDataProvider $eraseDataProvider */ $eraseDataProvider = $block->getData('eraseDataProvider'); ?> diff --git a/view/frontend/templates/order/info/buttons/export.phtml b/view/frontend/templates/order/info/buttons/export.phtml index f54a9477..34310fb6 100644 --- a/view/frontend/templates/order/info/buttons/export.phtml +++ b/view/frontend/templates/order/info/buttons/export.phtml @@ -11,8 +11,6 @@ use Opengento\Gdpr\ViewModel\Customer\Guest\ExportDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var ExportDataProvider $exportDataProvider */ $exportDataProvider = $block->getData('exportDataProvider'); ?> diff --git a/view/frontend/templates/order/info/erase.phtml b/view/frontend/templates/order/info/erase.phtml index f9f8aebc..9d3a6b65 100644 --- a/view/frontend/templates/order/info/erase.phtml +++ b/view/frontend/templates/order/info/erase.phtml @@ -11,8 +11,6 @@ use Opengento\Gdpr\ViewModel\Customer\Privacy\EraseDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var EraseDataProvider $eraseDataProvider */ $eraseDataProvider = $block->getData('eraseDataProvider'); ?> diff --git a/view/frontend/templates/order/info/export.phtml b/view/frontend/templates/order/info/export.phtml index 7126aa11..ca7fe610 100644 --- a/view/frontend/templates/order/info/export.phtml +++ b/view/frontend/templates/order/info/export.phtml @@ -11,8 +11,6 @@ use Opengento\Gdpr\ViewModel\Customer\Privacy\ExportDataProvider; /** @var Template $block */ /** @var Escaper $escaper */ -$escaper = $escaper ?? $block; - /** @var ExportDataProvider $exportDataProvider */ $exportDataProvider = $block->getData('exportDataProvider'); ?>