Skip to content

Commit 6b4e4fa

Browse files
committed
Merge branch 'master' into magento2.4.x
2 parents db7c51f + f0bbc19 commit 6b4e4fa

19 files changed

+347
-52
lines changed

Api/ExportEntityManagementInterface.php

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

1010
use Magento\Framework\Exception\AlreadyExistsException;
11+
use Magento\Framework\Exception\CouldNotDeleteException;
1112
use Magento\Framework\Exception\CouldNotSaveException;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Opengento\Gdpr\Api\Data\ExportEntityInterface;
@@ -39,4 +40,16 @@ public function create(int $entityId, string $entityType, ?string $fileName = nu
3940
* @throws LocalizedException
4041
*/
4142
public function export(ExportEntityInterface $exportEntity): ExportEntityInterface;
43+
44+
/**
45+
* Invalidate the export entity and create a new one to process
46+
*
47+
* @param ExportEntityInterface $exportEntity
48+
* @return ExportEntityInterface
49+
* @throws AlreadyExistsException
50+
* @throws CouldNotDeleteException
51+
* @throws CouldNotSaveException
52+
* @throws LocalizedException
53+
*/
54+
public function invalidate(ExportEntityInterface $exportEntity): ExportEntityInterface;
4255
}

Block/Adminhtml/Action/Edit/BackButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getButtonData(): array
3030
'label' => new Phrase('Back'),
3131
'on_click' => 'location.href = "' . $this->urlBuilder->getUrl('*/*/') . '";',
3232
'class' => 'back',
33-
'sort_order' => 10
33+
'sort_order' => 10,
3434
];
3535
}
3636
}

Block/Adminhtml/Action/Edit/ResetButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function getButtonData(): array
1818
'label' => new Phrase('Reset'),
1919
'class' => 'reset',
2020
'on_click' => 'location.reload();',
21-
'sort_order' => 20
21+
'sort_order' => 20,
2222
];
2323
}
2424
}

Cron/EraseEntityScheduler.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
use Exception;
1212
use Magento\Framework\Api\FilterBuilder;
1313
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\Exception\CouldNotSaveException;
15+
use Magento\Framework\Exception\LocalizedException;
1416
use Magento\Store\Model\ScopeInterface;
1517
use Opengento\Gdpr\Model\Config;
18+
use Opengento\Gdpr\Model\Entity\EntityTypeList;
1619
use Opengento\Gdpr\Model\Erase\EraseEntityScheduler as EraseEntitySchedulerService;
1720
use Psr\Log\LoggerInterface;
1821

@@ -49,40 +52,50 @@ final class EraseEntityScheduler
4952
private $filterBuilder;
5053

5154
/**
52-
* @var string[]
55+
* @var EntityTypeList
5356
*/
54-
private $entityTypes;
57+
private $entityTypeList;
5558

5659
public function __construct(
5760
LoggerInterface $logger,
5861
ScopeConfigInterface $scopeConfig,
5962
Config $config,
6063
EraseEntitySchedulerService $eraseEntityScheduler,
6164
FilterBuilder $filterBuilder,
62-
array $entityTypes
65+
EntityTypeList $entityTypeList
6366
) {
6467
$this->logger = $logger;
6568
$this->scopeConfig = $scopeConfig;
6669
$this->config = $config;
6770
$this->eraseEntityScheduler = $eraseEntityScheduler;
6871
$this->filterBuilder = $filterBuilder;
69-
$this->entityTypes = $entityTypes;
72+
$this->entityTypeList = $entityTypeList;
7073
}
7174

7275
public function execute(): void
7376
{
7477
if ($this->config->isModuleEnabled() && $this->config->isErasureEnabled()) {
7578
try {
76-
$this->filterBuilder->setField('created_at');
77-
$this->filterBuilder->setValue(new DateTime('-' . $this->resolveErasureMaxAge() . 'days'));
78-
$this->filterBuilder->setConditionType('lteq');
79-
$this->eraseEntityScheduler->schedule($this->entityTypes, $this->filterBuilder->create());
79+
$this->scheduleEntitiesErasure();
8080
} catch (Exception $e) {
8181
$this->logger->error($e->getMessage(), $e->getTrace());
8282
}
8383
}
8484
}
8585

86+
/**
87+
* @throws CouldNotSaveException
88+
* @throws LocalizedException
89+
* @throws Exception
90+
*/
91+
private function scheduleEntitiesErasure(): void
92+
{
93+
$this->filterBuilder->setField('created_at');
94+
$this->filterBuilder->setValue(new DateTime('-' . $this->resolveErasureMaxAge() . 'days'));
95+
$this->filterBuilder->setConditionType('lteq');
96+
$this->eraseEntityScheduler->schedule($this->entityTypeList->getEntityTypes(), $this->filterBuilder->create());
97+
}
98+
8699
private function resolveErasureMaxAge(): int
87100
{
88101
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_MAX_AGE, ScopeInterface::SCOPE_STORE);

Model/Action/Erase/CancelAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function execute(ActionContextInterface $actionContext): ActionResultInte
4848
return $this->createActionResult(
4949
[
5050
ArgumentReader::ERASE_ENTITY => $this->resolveEntity(...$arguments),
51-
'canceled' => $this->eraseManagement->cancel(...$arguments)
51+
'canceled' => $this->eraseManagement->cancel(...$arguments),
5252
]
5353
);
5454
}

Model/Action/Erase/CreateAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function execute(ActionContextInterface $actionContext): ActionResultInte
3737
[
3838
ArgumentReader::ERASE_ENTITY => $this->eraseManagement->create(
3939
...$this->getArguments($actionContext)
40-
)
40+
),
4141
]
4242
);
4343
}

Model/Action/Export/CreateAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function execute(ActionContextInterface $actionContext): ActionResultInte
3737
[
3838
ArgumentReader::EXPORT_ENTITY => $this->exporter->create(
3939
...$this->getArguments($actionContext)
40-
)
40+
),
4141
]
4242
);
4343
}

Model/Action/Export/CreateOrExportAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function execute(ActionContextInterface $actionContext): ActionResultInte
3838
[
3939
ExportArgumentReader::EXPORT_ENTITY => $this->exportEntityData->export(
4040
...$this->getArguments($actionContext)
41-
)
41+
),
4242
]
4343
);
4444
}

Model/Action/PerformedBy/AdminUser.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ public function __construct(
3434

3535
public function get(): string
3636
{
37-
return self::PERFORMED_BY . ($this->authSession->getUser()
38-
? $this->authSession->getUser()->getData($this->attributeName)
39-
: '');
37+
return self::PERFORMED_BY . $this->resolveUserName();
38+
}
39+
40+
private function resolveUserName(): string
41+
{
42+
return $this->authSession->getUser() ? $this->authSession->getUser()->getData($this->attributeName) : 'Unknown';
4043
}
4144
}

Model/Config/PrivacyMessage.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ public function __construct(
5050

5151
public function getDisclosureInformationHtml(): string
5252
{
53-
return $this->blockHtml ?? $this->blockHtml = $this->blockFactory->createBlock(
54-
Block::class,
55-
['data' => ['block_id' => (string) $this->scopeConfig->getValue(
56-
self::CONFIG_PATH_COOKIE_INFORMATION_BLOCK,
57-
ScopeInterface::SCOPE_STORE
58-
)]]
59-
)->toHtml();
53+
return $this->blockHtml ?? $this->blockHtml = $this->createDisclosureInformationBlockHtml();
6054
}
6155

6256
public function getLearnMoreUrl(): string
@@ -66,4 +60,19 @@ public function getLearnMoreUrl(): string
6660
ScopeInterface::SCOPE_STORE
6761
)) ?? '#';
6862
}
63+
64+
private function createDisclosureInformationBlockHtml(): string
65+
{
66+
return $this->blockFactory->createBlock(
67+
Block::class,
68+
[
69+
'data' => [
70+
'block_id' => (string) $this->scopeConfig->getValue(
71+
self::CONFIG_PATH_COOKIE_INFORMATION_BLOCK,
72+
ScopeInterface::SCOPE_STORE
73+
),
74+
],
75+
]
76+
)->toHtml();
77+
}
6978
}

0 commit comments

Comments
 (0)