Skip to content

Commit 22d90fd

Browse files
committed
WIP fix scopable config
1 parent 41784af commit 22d90fd

Some content is hidden

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

45 files changed

+327
-449
lines changed

Console/Command/EraseCommand.php

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

88
namespace Opengento\Gdpr\Console\Command;
99

10-
use Magento\Framework\Api\SearchCriteriaBuilder;
1110
use Magento\Framework\App\Area;
1211
use Magento\Framework\App\State;
1312
use Magento\Framework\Console\Cli;
1413
use Magento\Framework\Exception\LocalizedException;
1514
use Magento\Framework\Registry;
16-
use Opengento\Gdpr\Api\Data\EraseEntityInterface;
1715
use Opengento\Gdpr\Api\EraseEntityManagementInterface;
18-
use Opengento\Gdpr\Api\EraseEntityRepositoryInterface;
1916
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Helper\ProgressBar;
2018
use Symfony\Component\Console\Input\InputArgument;
2119
use Symfony\Component\Console\Input\InputInterface;
2220
use Symfony\Component\Console\Output\OutputInterface;
@@ -30,8 +28,6 @@ public function __construct(
3028
private State $appState,
3129
private Registry $registry,
3230
private EraseEntityManagementInterface $eraseManagement,
33-
private EraseEntityRepositoryInterface $eraseEntityRepository,
34-
private SearchCriteriaBuilder $searchCriteriaBuilder,
3531
string $name = 'gdpr:entity:erase'
3632
) {
3733
parent::__construct($name);
@@ -71,17 +67,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7167
$entityIds = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_ID);
7268
$entityType = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_TYPE);
7369

74-
try {
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);
70+
$progressBar = new ProgressBar($output, count($entityIds));
71+
$progressBar->start();
8072

81-
$output->writeln(
82-
'<info>Entity\'s (' . $entityType . ') with ID "' . $eraseEntity->getEntityId() . '" has been erased.</info>'
83-
);
73+
try {
74+
foreach ($entityIds as $entityId) {
75+
$this->eraseManagement->process($this->eraseManagement->create($entityId, $entityType));
76+
$progressBar->advance();
8477
}
78+
$progressBar->finish();
79+
$output->writeln('<info>Entities has been erased.</info>');
8580
} catch (LocalizedException $e) {
8681
$output->writeln('<error>' . $e->getMessage() . '</error>');
8782
$returnCode = Cli::RETURN_FAILURE;

Console/Command/ExportCommand.php

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

1010
use Exception;
11-
use Magento\Framework\Api\SearchCriteriaBuilder;
1211
use Magento\Framework\App\Area;
1312
use Magento\Framework\App\State;
1413
use Magento\Framework\Console\Cli;
1514
use Magento\Framework\Exception\LocalizedException;
16-
use Opengento\Gdpr\Api\Data\ExportEntityInterface;
1715
use Opengento\Gdpr\Api\ExportEntityManagementInterface;
18-
use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
1916
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Helper\ProgressBar;
2018
use Symfony\Component\Console\Input\InputArgument;
2119
use Symfony\Component\Console\Input\InputInterface;
22-
use Symfony\Component\Console\Input\InputOption;
2320
use Symfony\Component\Console\Output\OutputInterface;
2421

2522
class ExportCommand extends Command
2623
{
2724
private const INPUT_ARGUMENT_ENTITY_ID = 'entity_id';
2825
private const INPUT_ARGUMENT_ENTITY_TYPE = 'entity_type';
29-
private const INPUT_OPTION_FILENAME = 'filename';
3026

3127
public function __construct(
3228
private State $appState,
3329
private ExportEntityManagementInterface $exportEntityManagement,
34-
private ExportEntityRepositoryInterface $exportEntityRepository,
35-
private SearchCriteriaBuilder $searchCriteriaBuilder,
3630
string $name = 'gdpr:entity:export'
3731
) {
3832
parent::__construct($name);
@@ -53,13 +47,6 @@ protected function configure(): void
5347
self::INPUT_ARGUMENT_ENTITY_ID,
5448
InputArgument::REQUIRED + InputArgument::IS_ARRAY,
5549
'Entity ID'
56-
),
57-
new InputOption(
58-
self::INPUT_OPTION_FILENAME,
59-
'-f',
60-
InputOption::VALUE_OPTIONAL,
61-
'Export file name',
62-
'personal_data'
6350
)
6451
]);
6552
}
@@ -75,18 +62,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7562
$resultCode = Cli::RETURN_SUCCESS;
7663
$entityIds = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_ID);
7764
$entityType = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_TYPE);
78-
$fileName = $input->getOption(self::INPUT_OPTION_FILENAME);
65+
66+
$progressBar = new ProgressBar($output, count($entityIds));
67+
$progressBar->start();
68+
69+
$files = [];
7970

8071
try {
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) {
72+
foreach ($entityIds as $entityId) {
73+
$exportEntity = $this->exportEntityManagement->create($entityId, $entityType);
8574
$this->exportEntityManagement->export($exportEntity);
86-
87-
$output->writeln(
88-
'<info>Entity\'s related data have been exported to: ' . $exportEntity->getFilePath() . '.</info>'
89-
);
75+
$files[] = $exportEntity->getFilePath();
76+
$progressBar->advance();
77+
}
78+
$progressBar->finish();
79+
$output->writeln('<info>Entities data have been exported to:</info>');
80+
foreach ($files as $file) {
81+
$output->writeln($file);
9082
}
9183
} catch (Exception $e) {
9284
$output->writeln('<error>' . $e->getMessage() . '</error>');

Controller/Guest/Download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353

5454
protected function isAllowed(): bool
5555
{
56-
return parent::isAllowed() && $this->config->isExportEnabled();
56+
return $this->config->isExportEnabled();
5757
}
5858

5959
protected function executeAction(): ResultInterface|ResponseInterface|Redirect

Controller/Guest/Erase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737

3838
protected function isAllowed(): bool
3939
{
40-
return parent::isAllowed() && $this->config->isErasureEnabled();
40+
return $this->config->isErasureEnabled();
4141
}
4242

4343
protected function executeAction(): Redirect

Controller/Guest/Export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838

3939
protected function isAllowed(): bool
4040
{
41-
return parent::isAllowed() && $this->config->isExportEnabled();
41+
return $this->config->isExportEnabled();
4242
}
4343

4444
protected function executeAction(): Redirect

Controller/Guest/UndoErase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737

3838
protected function isAllowed(): bool
3939
{
40-
return parent::isAllowed() && $this->config->isErasureEnabled();
40+
return $this->config->isErasureEnabled();
4141
}
4242

4343
protected function executeAction(): Redirect

Controller/Privacy/Download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343

4444
protected function isAllowed(): bool
4545
{
46-
return parent::isAllowed() && $this->config->isExportEnabled();
46+
return $this->config->isExportEnabled();
4747
}
4848

4949
protected function executeAction(): ResultInterface|ResponseInterface|Redirect

Controller/Privacy/Erase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636

3737
protected function isAllowed(): bool
3838
{
39-
return parent::isAllowed() && $this->config->isErasureEnabled();
39+
return $this->config->isErasureEnabled();
4040
}
4141

4242
protected function executeAction(): Page|Redirect

Controller/Privacy/ErasePost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242

4343
protected function isAllowed(): bool
4444
{
45-
return parent::isAllowed() && $this->config->isErasureEnabled();
45+
return $this->config->isErasureEnabled();
4646
}
4747

4848
protected function executeAction(): Redirect

Controller/Privacy/Export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838

3939
protected function isAllowed(): bool
4040
{
41-
return parent::isAllowed() && $this->config->isExportEnabled();
41+
return $this->config->isExportEnabled();
4242
}
4343

4444
protected function executeAction(): Redirect

0 commit comments

Comments
 (0)