Skip to content

Commit 8685359

Browse files
committed
#138 - WIP Remove ActionInterface abstraction
1 parent db16ac2 commit 8685359

File tree

189 files changed

+354
-2205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+354
-2205
lines changed

Api/ActionInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
/**
1515
* @api
16+
* @todo remove
1617
*/
1718
interface ActionInterface
1819
{

Block/Adminhtml/Action/Edit/BackButton.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

Block/Adminhtml/Action/Edit/ExecuteButton.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

Block/Adminhtml/Action/Edit/ResetButton.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

Block/Adminhtml/Customer/Edit/EraseButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Opengento\Gdpr\Api\EraseEntityCheckerInterface;
1616
use Opengento\Gdpr\Model\Config;
1717

18-
final class EraseButton extends GenericButton implements ButtonProviderInterface
18+
class EraseButton extends GenericButton implements ButtonProviderInterface
1919
{
2020
private EraseEntityCheckerInterface $eraseCustomerChecker;
2121

Block/Adminhtml/Customer/Edit/ExportButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
1515
use Opengento\Gdpr\Model\Config;
1616

17-
final class ExportButton extends GenericButton implements ButtonProviderInterface
17+
class ExportButton extends GenericButton implements ButtonProviderInterface
1818
{
1919
private Config $config;
2020

Console/Command/EraseCommand.php

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
namespace Opengento\Gdpr\Console\Command;
99

10+
use Magento\Framework\Api\SearchCriteriaBuilder;
1011
use Magento\Framework\App\Area;
1112
use Magento\Framework\App\State;
1213
use Magento\Framework\Console\Cli;
1314
use Magento\Framework\Exception\LocalizedException;
1415
use Magento\Framework\Registry;
15-
use Opengento\Gdpr\Api\ActionInterface;
16-
use Opengento\Gdpr\Model\Action\ArgumentReader;
17-
use Opengento\Gdpr\Model\Action\ContextBuilder;
16+
use Opengento\Gdpr\Api\Data\EraseEntityInterface;
17+
use Opengento\Gdpr\Api\EraseEntityManagementInterface;
18+
use Opengento\Gdpr\Api\EraseEntityRepositoryInterface;
1819
use Symfony\Component\Console\Command\Command;
1920
use Symfony\Component\Console\Input\InputArgument;
2021
use Symfony\Component\Console\Input\InputInterface;
@@ -25,25 +26,14 @@ class EraseCommand extends Command
2526
private const INPUT_ARGUMENT_ENTITY_ID = 'entity_id';
2627
private const INPUT_ARGUMENT_ENTITY_TYPE = 'entity_type';
2728

28-
private State $appState;
29-
30-
private Registry $registry;
31-
32-
private ActionInterface $action;
33-
34-
private ContextBuilder $actionContextBuilder;
35-
3629
public function __construct(
37-
State $appState,
38-
Registry $registry,
39-
ActionInterface $action,
40-
ContextBuilder $actionContextBuilder,
30+
private State $appState,
31+
private Registry $registry,
32+
private EraseEntityManagementInterface $eraseManagement,
33+
private EraseEntityRepositoryInterface $eraseEntityRepository,
34+
private SearchCriteriaBuilder $searchCriteriaBuilder,
4135
string $name = 'gdpr:entity:erase'
4236
) {
43-
$this->appState = $appState;
44-
$this->registry = $registry;
45-
$this->action = $action;
46-
$this->actionContextBuilder = $actionContextBuilder;
4737
parent::__construct($name);
4838
}
4939

@@ -82,15 +72,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8272
$entityType = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_TYPE);
8373

8474
try {
85-
foreach ($entityIds as $entityId) {
86-
$this->action->execute(
87-
$this->actionContextBuilder->setParameters(
88-
[ArgumentReader::ENTITY_ID => $entityId, ArgumentReader::ENTITY_TYPE => $entityType]
89-
)->create()
90-
);
75+
$this->searchCriteriaBuilder->addFilter(EraseEntityInterface::ENTITY_ID, $entityIds, 'in');
76+
$this->searchCriteriaBuilder->addFilter(EraseEntityInterface::ENTITY_TYPE, $entityType);
77+
$eraseEntityList = $this->eraseEntityRepository->getList($this->searchCriteriaBuilder->create());
78+
foreach ($eraseEntityList->getItems() as $eraseEntity) {
79+
$this->eraseManagement->process($eraseEntity);
9180

9281
$output->writeln(
93-
'<info>Entity\'s (' . $entityType . ') with ID "' . $entityId . '" has been erased.</info>'
82+
'<info>Entity\'s (' . $entityType . ') with ID "' . $eraseEntity->getEntityId() . '" has been erased.</info>'
9483
);
9584
}
9685
} catch (LocalizedException $e) {

Console/Command/ExportCommand.php

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
namespace Opengento\Gdpr\Console\Command;
99

1010
use Exception;
11+
use Magento\Framework\Api\SearchCriteriaBuilder;
1112
use Magento\Framework\App\Area;
1213
use Magento\Framework\App\State;
1314
use Magento\Framework\Console\Cli;
1415
use Magento\Framework\Exception\LocalizedException;
15-
use Opengento\Gdpr\Api\ActionInterface;
1616
use Opengento\Gdpr\Api\Data\ExportEntityInterface;
17-
use Opengento\Gdpr\Model\Action\ArgumentReader;
18-
use Opengento\Gdpr\Model\Action\ContextBuilder;
19-
use Opengento\Gdpr\Model\Action\Export\ArgumentReader as ExportArgumentReader;
17+
use Opengento\Gdpr\Api\ExportEntityManagementInterface;
18+
use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
2019
use Symfony\Component\Console\Command\Command;
2120
use Symfony\Component\Console\Input\InputArgument;
2221
use Symfony\Component\Console\Input\InputInterface;
@@ -29,21 +28,13 @@ class ExportCommand extends Command
2928
private const INPUT_ARGUMENT_ENTITY_TYPE = 'entity_type';
3029
private const INPUT_OPTION_FILENAME = 'filename';
3130

32-
private State $appState;
33-
34-
private ActionInterface $action;
35-
36-
private ContextBuilder $actionContextBuilder;
37-
3831
public function __construct(
39-
State $appState,
40-
ActionInterface $action,
41-
ContextBuilder $actionContextBuilder,
32+
private State $appState,
33+
private ExportEntityManagementInterface $exportEntityManagement,
34+
private ExportEntityRepositoryInterface $exportEntityRepository,
35+
private SearchCriteriaBuilder $searchCriteriaBuilder,
4236
string $name = 'gdpr:entity:export'
4337
) {
44-
$this->appState = $appState;
45-
$this->action = $action;
46-
$this->actionContextBuilder = $actionContextBuilder;
4738
parent::__construct($name);
4839
}
4940

@@ -87,15 +78,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8778
$fileName = $input->getOption(self::INPUT_OPTION_FILENAME);
8879

8980
try {
90-
foreach ($entityIds as $entityId) {
91-
$this->actionContextBuilder->setParameters([
92-
ArgumentReader::ENTITY_ID => $entityId,
93-
ArgumentReader::ENTITY_TYPE => $entityType,
94-
ExportArgumentReader::EXPORT_FILE_NAME => $fileName . '_' . $entityId
95-
]);
96-
$result = $this->action->execute($this->actionContextBuilder->create())->getResult();
97-
/** @var ExportEntityInterface $exportEntity */
98-
$exportEntity = $result[ExportArgumentReader::EXPORT_ENTITY];
81+
$this->searchCriteriaBuilder->addFilter(ExportEntityInterface::ENTITY_ID, $entityIds, 'in');
82+
$this->searchCriteriaBuilder->addFilter(ExportEntityInterface::ENTITY_TYPE, $entityType);
83+
$exportEntityList = $this->exportEntityRepository->getList($this->searchCriteriaBuilder->create());
84+
foreach ($exportEntityList->getItems() as $exportEntity) {
85+
$this->exportEntityManagement->export($exportEntity);
9986

10087
$output->writeln(
10188
'<info>Entity\'s related data have been exported to: ' . $exportEntity->getFilePath() . '.</info>'

Controller/AbstractAction.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,31 @@
1919

2020
abstract class AbstractAction implements ActionInterface
2121
{
22-
protected RequestInterface $request;
23-
24-
protected ResultFactory $resultFactory;
25-
26-
protected ManagerInterface $messageManager;
27-
28-
protected Config $config;
29-
3022
public function __construct(
31-
RequestInterface $request,
32-
ResultFactory $resultFactory,
33-
ManagerInterface $messageManager,
34-
Config $config
35-
) {
36-
$this->request = $request;
37-
$this->resultFactory = $resultFactory;
38-
$this->messageManager = $messageManager;
39-
$this->config = $config;
40-
}
23+
protected RequestInterface $request,
24+
protected ResultFactory $resultFactory,
25+
protected ManagerInterface $messageManager,
26+
protected Config $config
27+
) {}
4128

42-
public function execute()
29+
public function execute(): ResultInterface|ResponseInterface
4330
{
4431
return $this->isAllowed() ? $this->executeAction() : $this->forwardNoRoute();
4532
}
4633

4734
/**
4835
* Execute action based on request and return result
4936
*
50-
* @return ResultInterface|ResponseInterface
5137
* @throws NotFoundException
5238
*/
53-
abstract protected function executeAction();
39+
abstract protected function executeAction(): ResultInterface|ResponseInterface;
5440

5541
protected function isAllowed(): bool
5642
{
5743
return $this->config->isModuleEnabled();
5844
}
5945

60-
protected function forwardNoRoute(): ResultInterface
46+
final protected function forwardNoRoute(): ResultInterface
6147
{
6248
/** @var Forward $resultForward */
6349
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);

Controller/AbstractGuest.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Opengento\Gdpr\Controller;
99

1010
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\App\ResponseInterface;
1112
use Magento\Framework\Controller\ResultFactory;
1213
use Magento\Framework\Controller\ResultInterface;
1314
use Magento\Framework\Message\ManagerInterface;
@@ -18,34 +19,25 @@
1819

1920
abstract class AbstractGuest extends AbstractAction
2021
{
21-
/**
22-
* @var OrderLoaderInterface
23-
*/
24-
protected OrderLoaderInterface $orderLoader;
25-
26-
protected Registry $registry;
27-
2822
public function __construct(
2923
RequestInterface $request,
3024
ResultFactory $resultFactory,
3125
ManagerInterface $messageManager,
3226
Config $config,
33-
OrderLoaderInterface $orderLoader,
34-
Registry $registry
27+
protected OrderLoaderInterface $orderLoader,
28+
protected Registry $registry
3529
) {
36-
$this->orderLoader = $orderLoader;
37-
$this->registry = $registry;
3830
parent::__construct($request, $resultFactory, $messageManager, $config);
3931
}
4032

41-
public function execute()
33+
final public function execute(): ResultInterface|ResponseInterface
4234
{
4335
$result = $this->orderLoader->load($this->request);
4436

4537
return $result instanceof ResultInterface ? $result : parent::execute();
4638
}
4739

48-
protected function currentOrder(): OrderInterface
40+
final protected function currentOrder(): OrderInterface
4941
{
5042
return $this->registry->registry('current_order');
5143
}

0 commit comments

Comments
 (0)