diff --git a/Console/Command/EraseCommand.php b/Console/Command/EraseCommand.php
index 4655796..ac8b4df 100644
--- a/Console/Command/EraseCommand.php
+++ b/Console/Command/EraseCommand.php
@@ -7,16 +7,14 @@
namespace Opengento\Gdpr\Console\Command;
-use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Area;
use Magento\Framework\App\State;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
-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;
@@ -30,8 +28,6 @@ public function __construct(
private State $appState,
private Registry $registry,
private EraseEntityManagementInterface $eraseManagement,
- private EraseEntityRepositoryInterface $eraseEntityRepository,
- private SearchCriteriaBuilder $searchCriteriaBuilder,
string $name = 'gdpr:entity:erase'
) {
parent::__construct($name);
@@ -71,17 +67,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$entityIds = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_ID);
$entityType = $input->getArgument(self::INPUT_ARGUMENT_ENTITY_TYPE);
- try {
- $this->searchCriteriaBuilder->addFilter(EraseEntityInterface::ENTITY_ID, $entityIds, 'in');
- $this->searchCriteriaBuilder->addFilter(EraseEntityInterface::ENTITY_TYPE, $entityType);
- $eraseEntityList = $this->eraseEntityRepository->getList($this->searchCriteriaBuilder->create());
- foreach ($eraseEntityList->getItems() as $eraseEntity) {
- $this->eraseManagement->process($eraseEntity);
+ $progressBar = new ProgressBar($output, count($entityIds));
+ $progressBar->start();
- $output->writeln(
- 'Entity\'s (' . $entityType . ') with ID "' . $eraseEntity->getEntityId() . '" has been erased.'
- );
+ try {
+ foreach ($entityIds as $entityId) {
+ $this->eraseManagement->process($this->eraseManagement->create($entityId, $entityType));
+ $progressBar->advance();
}
+ $progressBar->finish();
+ $output->writeln('Entities has been erased.');
} catch (LocalizedException $e) {
$output->writeln('' . $e->getMessage() . '');
$returnCode = Cli::RETURN_FAILURE;
diff --git a/Console/Command/ExportCommand.php b/Console/Command/ExportCommand.php
index 77eed26..2ad719a 100644
--- a/Console/Command/ExportCommand.php
+++ b/Console/Command/ExportCommand.php
@@ -8,31 +8,25 @@
namespace Opengento\Gdpr\Console\Command;
use Exception;
-use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Area;
use Magento\Framework\App\State;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;
-use Opengento\Gdpr\Api\Data\ExportEntityInterface;
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';
public function __construct(
private State $appState,
private ExportEntityManagementInterface $exportEntityManagement,
- private ExportEntityRepositoryInterface $exportEntityRepository,
- private SearchCriteriaBuilder $searchCriteriaBuilder,
string $name = 'gdpr:entity:export'
) {
parent::__construct($name);
@@ -53,13 +47,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'
)
]);
}
@@ -75,18 +62,23 @@ 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 {
- $this->searchCriteriaBuilder->addFilter(ExportEntityInterface::ENTITY_ID, $entityIds, 'in');
- $this->searchCriteriaBuilder->addFilter(ExportEntityInterface::ENTITY_TYPE, $entityType);
- $exportEntityList = $this->exportEntityRepository->getList($this->searchCriteriaBuilder->create());
- foreach ($exportEntityList->getItems() as $exportEntity) {
+ foreach ($entityIds as $entityId) {
+ $exportEntity = $this->exportEntityManagement->create($entityId, $entityType);
$this->exportEntityManagement->export($exportEntity);
-
- $output->writeln(
- 'Entity\'s related data have been exported to: ' . $exportEntity->getFilePath() . '.'
- );
+ $files[] = $exportEntity->getFilePath();
+ $progressBar->advance();
+ }
+ $progressBar->finish();
+ $output->writeln('Entities data have been exported to:');
+ foreach ($files as $file) {
+ $output->writeln($file);
}
} catch (Exception $e) {
$output->writeln('' . $e->getMessage() . '');
diff --git a/Controller/Guest/Download.php b/Controller/Guest/Download.php
index 2417b32..8d790e2 100755
--- a/Controller/Guest/Download.php
+++ b/Controller/Guest/Download.php
@@ -53,7 +53,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isExportEnabled();
+ return $this->config->isExportEnabled();
}
protected function executeAction(): ResultInterface|ResponseInterface|Redirect
diff --git a/Controller/Guest/Erase.php b/Controller/Guest/Erase.php
index eb39ac1..56c9ea5 100644
--- a/Controller/Guest/Erase.php
+++ b/Controller/Guest/Erase.php
@@ -37,7 +37,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isErasureEnabled();
+ return $this->config->isErasureEnabled();
}
protected function executeAction(): Redirect
diff --git a/Controller/Guest/Export.php b/Controller/Guest/Export.php
index 8159eed..2361ace 100755
--- a/Controller/Guest/Export.php
+++ b/Controller/Guest/Export.php
@@ -38,7 +38,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isExportEnabled();
+ return $this->config->isExportEnabled();
}
protected function executeAction(): Redirect
diff --git a/Controller/Guest/UndoErase.php b/Controller/Guest/UndoErase.php
index f0e95fa..b8dd31d 100644
--- a/Controller/Guest/UndoErase.php
+++ b/Controller/Guest/UndoErase.php
@@ -37,7 +37,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isErasureEnabled();
+ return $this->config->isErasureEnabled();
}
protected function executeAction(): Redirect
diff --git a/Controller/Privacy/Download.php b/Controller/Privacy/Download.php
index a84353a..acabbc5 100755
--- a/Controller/Privacy/Download.php
+++ b/Controller/Privacy/Download.php
@@ -43,7 +43,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isExportEnabled();
+ return $this->config->isExportEnabled();
}
protected function executeAction(): ResultInterface|ResponseInterface|Redirect
diff --git a/Controller/Privacy/Erase.php b/Controller/Privacy/Erase.php
index 05b9384..bf1210d 100755
--- a/Controller/Privacy/Erase.php
+++ b/Controller/Privacy/Erase.php
@@ -36,7 +36,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isErasureEnabled();
+ return $this->config->isErasureEnabled();
}
protected function executeAction(): Page|Redirect
diff --git a/Controller/Privacy/ErasePost.php b/Controller/Privacy/ErasePost.php
index 7bb81fa..263818b 100755
--- a/Controller/Privacy/ErasePost.php
+++ b/Controller/Privacy/ErasePost.php
@@ -42,7 +42,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isErasureEnabled();
+ return $this->config->isErasureEnabled();
}
protected function executeAction(): Redirect
diff --git a/Controller/Privacy/Export.php b/Controller/Privacy/Export.php
index eb5ad6d..9e563b4 100755
--- a/Controller/Privacy/Export.php
+++ b/Controller/Privacy/Export.php
@@ -38,7 +38,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isExportEnabled();
+ return $this->config->isExportEnabled();
}
protected function executeAction(): Redirect
diff --git a/Controller/Privacy/UndoErase.php b/Controller/Privacy/UndoErase.php
index e54e51e..bd04b45 100755
--- a/Controller/Privacy/UndoErase.php
+++ b/Controller/Privacy/UndoErase.php
@@ -37,7 +37,7 @@ public function __construct(
protected function isAllowed(): bool
{
- return parent::isAllowed() && $this->config->isErasureEnabled();
+ return $this->config->isErasureEnabled();
}
protected function executeAction(): Redirect
diff --git a/Cron/EraseEntity.php b/Cron/EraseEntity.php
index 0783e69..3329f0d 100755
--- a/Cron/EraseEntity.php
+++ b/Cron/EraseEntity.php
@@ -17,7 +17,6 @@
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;
/**
@@ -27,7 +26,6 @@ class EraseEntity
{
public function __construct(
private LoggerInterface $logger,
- private Config $config,
private Registry $registry,
private EraseEntityManagementInterface $eraseManagement,
private EraseEntityRepositoryInterface $eraseRepository,
@@ -37,24 +35,27 @@ public function __construct(
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
{
@@ -74,12 +75,6 @@ private function retrieveEraseEntityList(): SearchResultsInterface
'in'
);
- try {
- $eraseCustomerList = $this->eraseRepository->getList($this->criteriaBuilder->create());
- } catch (LocalizedException) {
- $eraseCustomerList = [];
- }
-
- return $eraseCustomerList;
+ return $this->eraseRepository->getList($this->criteriaBuilder->create());
}
}
diff --git a/Cron/EraseEntityScheduler.php b/Cron/EraseEntityScheduler.php
index 4381ddd..5be647c 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;
@@ -24,44 +19,26 @@
*/
class EraseEntityScheduler
{
- private const CONFIG_PATH_ERASURE_MAX_AGE = 'gdpr/erasure/entity_max_age';
public function __construct(
private LoggerInterface $logger,
- private ScopeConfigInterface $scopeConfig,
private Config $config,
private EraseEntitySchedulerService $eraseEntityScheduler,
- private FilterBuilder $filterBuilder,
- private EntityTypeList $entityTypeList
- ) {
- }
+ 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) {
+ $websiteId = $website->getId();
+ if ($this->config->isErasureEnabled($websiteId)) {
+ 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 587e78d..94ea42d 100644
--- a/Cron/ExportEntity.php
+++ b/Cron/ExportEntity.php
@@ -13,7 +13,6 @@
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;
/**
@@ -23,7 +22,6 @@ class ExportEntity
{
public function __construct(
private LoggerInterface $logger,
- private Config $config,
private ExportEntityRepositoryInterface $exportRepository,
private ExportEntityManagementInterface $exportManagement,
private SearchCriteriaBuilder $criteriaBuilder
@@ -31,24 +29,22 @@ public function __construct(
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');
+ $this->criteriaBuilder->addFilter(ExportEntityInterface::EXPORTED_AT, true, 'null');
+ $this->criteriaBuilder->addFilter(ExportEntityInterface::FILE_PATH, true, 'null');
- try {
- $exportList = $this->exportRepository->getList($this->criteriaBuilder->create());
+ 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);
- }
+ 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 17444ce..d372fb8 100644
--- a/Cron/ExportEntityExpired.php
+++ b/Cron/ExportEntityExpired.php
@@ -22,29 +22,26 @@ class ExportEntityExpired
{
public function __construct(
private LoggerInterface $logger,
- private Config $config,
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/Archive/ArchiveManager.php b/Model/Archive/ArchiveManager.php
index 2f2df50..8d52578 100644
--- a/Model/Archive/ArchiveManager.php
+++ b/Model/Archive/ArchiveManager.php
@@ -16,23 +16,12 @@
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 38cfcb4..2bb47c5 100644
--- a/Model/Archive/Zip.php
+++ b/Model/Archive/Zip.php
@@ -20,28 +20,19 @@
*/
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 a0ca28d..dc6fa1f 100644
--- a/Model/Config.php
+++ b/Model/Config.php
@@ -10,58 +10,28 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
-use function explode;
-
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 ScopeConfigInterface $scopeConfig;
-
- public function __construct(
- ScopeConfigInterface $scopeConfig
- ) {
- $this->scopeConfig = $scopeConfig;
- }
+ 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';
- public function isModuleEnabled(): bool
- {
- return $this->scopeConfig->isSetFlag(
- self::CONFIG_PATH_GENERAL_ENABLED,
- ScopeInterface::SCOPE_STORE
- );
- }
+ public function __construct(private ScopeConfigInterface $scopeConfig) {}
- 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 ed7a1f5..52823b5 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 0000000..e651df0
--- /dev/null
+++ b/Model/Config/Entity/Erasure.php
@@ -0,0 +1,54 @@
+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
+ ));
+ }
+}
diff --git a/Model/Customer/Anonymize/Processor/CustomerDataProcessor.php b/Model/Customer/Anonymize/Processor/CustomerDataProcessor.php
index f586ec2..c13463d 100644
--- a/Model/Customer/Anonymize/Processor/CustomerDataProcessor.php
+++ b/Model/Customer/Anonymize/Processor/CustomerDataProcessor.php
@@ -78,7 +78,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) {
@@ -116,8 +116,12 @@ private function anonymizeCustomer(CustomerInterface $customer): void
$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/CustomerChecker.php b/Model/Customer/CustomerChecker.php
index a7421e1..2b5449b 100644
--- a/Model/Customer/CustomerChecker.php
+++ b/Model/Customer/CustomerChecker.php
@@ -9,21 +9,21 @@
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
-use Opengento\Gdpr\Model\Config;
+use Opengento\Gdpr\Model\Config\Entity\Erasure as ErasureConfig;
use Opengento\Gdpr\Model\Entity\EntityCheckerInterface;
class CustomerChecker implements EntityCheckerInterface
{
public function __construct(
private CollectionFactory $collectionFactory,
- private Config $config
+ private ErasureConfig $erasureConfig
) {}
- public function canErase(int $customerId): bool
+ public function canErase(int $entityId): bool
{
$collection = $this->collectionFactory->create();
- $collection->addFieldToFilter(OrderInterface::CUSTOMER_ID, $customerId);
- $collection->addFieldToFilter(OrderInterface::STATE, ['nin' => $this->config->getAllowedStatesToErase()]);
+ $collection->addFieldToFilter(OrderInterface::CUSTOMER_ID, $entityId);
+ $collection->addFieldToFilter(OrderInterface::STATE, ['nin' => $this->erasureConfig->getAllowedStatesToErase()]);//ToDo scope Website
return $collection->getSize() > 0;
}
diff --git a/Model/Customer/Erase/Notifier.php b/Model/Customer/Erase/Notifier.php
index b0ce7fa..7c4e9b5 100644
--- a/Model/Customer/Erase/Notifier.php
+++ b/Model/Customer/Erase/Notifier.php
@@ -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 d53f486..524dfdb 100644
--- a/Model/Customer/Export/Notifier.php
+++ b/Model/Customer/Export/Notifier.php
@@ -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/SourceProvider/IdleFilterModifier.php b/Model/Customer/SourceProvider/IdleFilterModifier.php
index a366e21..6f08c2f 100644
--- a/Model/Customer/SourceProvider/IdleFilterModifier.php
+++ b/Model/Customer/SourceProvider/IdleFilterModifier.php
@@ -7,40 +7,47 @@
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;
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->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/SourceProvider/ExpireFilterModifier.php b/Model/Entity/SourceProvider/ExpireFilterModifier.php
new file mode 100644
index 0000000..1a5c5bb
--- /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 e9108b4..0000000
--- 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 1af430e..dc8ebf2 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
*/
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/ModifierInterface.php b/Model/Entity/SourceProvider/ModifierInterface.php
index dcf4993..eb940cf 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 709f02c..96ceca8 100644
--- a/Model/Entity/SourceProvider/NotErasedFilterModifier.php
+++ b/Model/Entity/SourceProvider/NotErasedFilterModifier.php
@@ -7,47 +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;
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 7efb324..02ce18b 100644
--- a/Model/Entity/SourceProviderFactory.php
+++ b/Model/Entity/SourceProviderFactory.php
@@ -8,7 +8,7 @@
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;
@@ -18,26 +18,15 @@
*/
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 a3b490f..53498bf 100644
--- a/Model/Erase/EraseEntityScheduler.php
+++ b/Model/Erase/EraseEntityScheduler.php
@@ -8,44 +8,33 @@
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;
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);
}
@@ -54,14 +43,12 @@ public function schedule(array $entityTypes, Filter $filter): void
/**
* @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 e9e4007..ca641ca 100644
--- a/Model/Erase/EraseSalesInformation.php
+++ b/Model/Erase/EraseSalesInformation.php
@@ -62,6 +62,6 @@ public function isAlive(DateTimeInterface $lastActive): bool
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, ScopeInterface::SCOPE_STORE);//Todo scope website
}
}
diff --git a/Model/EraseEntityManagement.php b/Model/EraseEntityManagement.php
index bf69441..40230c9 100644
--- a/Model/EraseEntityManagement.php
+++ b/Model/EraseEntityManagement.php
@@ -122,6 +122,6 @@ private function retrieveScheduledAt(): string
private function resolveErasureDelay(): int
{
- return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE);
+ return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE);//Todo scope website
}
}
diff --git a/Model/Export/ExportToFile.php b/Model/Export/ExportToFile.php
index 7080b50..f0e5854 100644
--- a/Model/Export/ExportToFile.php
+++ b/Model/Export/ExportToFile.php
@@ -73,7 +73,7 @@ public function resolveExportRendererCodes(): array
{
return explode(',', (string)$this->scopeConfig->getValue(
self::CONFIG_PATH_EXPORT_RENDERERS,
- ScopeInterface::SCOPE_STORE
+ ScopeInterface::SCOPE_STORE //ToDo scope website
));
}
diff --git a/Model/ExportEntityManagement.php b/Model/ExportEntityManagement.php
index 0eb094b..0192ea5 100644
--- a/Model/ExportEntityManagement.php
+++ b/Model/ExportEntityManagement.php
@@ -80,7 +80,7 @@ public function create(int $entityId, string $entityType, ?string $fileName = nu
*/
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, ScopeInterface::SCOPE_STORE);//Todo scope website
$exportEntity->setFilePath($this->exportToFile->export($exportEntity));
$exportEntity->setExpiredAt(
(new DateTime('+' . $lifeTime . 'minutes'))->format(DateTimeFormat::DATETIME_PHP_FORMAT)
@@ -100,6 +100,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);//Todo scope website
}
}
diff --git a/Model/Order/Erase/Notifier.php b/Model/Order/Erase/Notifier.php
index 3976753..5e3c7a8 100644
--- a/Model/Order/Erase/Notifier.php
+++ b/Model/Order/Erase/Notifier.php
@@ -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 f1be5a3..7261ebf 100644
--- a/Model/Order/Export/Notifier.php
+++ b/Model/Order/Export/Notifier.php
@@ -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/OrderChecker.php b/Model/Order/OrderChecker.php
index 1668ef6..3fefb90 100644
--- a/Model/Order/OrderChecker.php
+++ b/Model/Order/OrderChecker.php
@@ -7,8 +7,11 @@
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;
@@ -17,13 +20,33 @@ class OrderChecker implements EntityCheckerInterface
{
public function __construct(
private OrderRepositoryInterface $orderRepository,
- private Config $config
+ private StoreManagerInterface $storeManager,
+ private ErasureConfig $erasureConfig
) {}
- public function canErase(int $orderId): bool
+ /**
+ * @throws NoSuchEntityException
+ */
+ public function canErase(int $entityId): bool
{
- $order = $this->orderRepository->get($orderId);
+ $order = $this->orderRepository->get($entityId);
- return in_array($order->getState(), $this->config->getAllowedStatesToErase(), true);
+ return in_array($order->getState(), $this->allowedStates($order), true);
+ }
+
+ /**
+ * @throws NoSuchEntityException
+ */
+ private function allowedStates(OrderInterface $order): array
+ {
+ return $this->erasureConfig->getAllowedStatesToErase($this->resolveWebsiteId($order));
+ }
+
+ /**
+ * @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 a669de0..5e97df3 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;
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(
+ OrderInterface::STATE,
+ ['in' => $this->erasureConfig->getAllowedStatesToErase($website->getId())]
+ );
}
}
diff --git a/Observer/DeleteExport.php b/Observer/DeleteExport.php
index eb97ba6..502383f 100644
--- a/Observer/DeleteExport.php
+++ b/Observer/DeleteExport.php
@@ -59,9 +59,9 @@ public function execute(Observer $observer): void
$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]);
}
}
}
diff --git a/Observer/InvalidateExport.php b/Observer/InvalidateExport.php
index ec5eaa8..f7feaab 100644
--- a/Observer/InvalidateExport.php
+++ b/Observer/InvalidateExport.php
@@ -63,9 +63,9 @@ public function execute(Observer $observer): void
$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]);
}
}
}
diff --git a/etc/db_schema.xml b/etc/db_schema.xml
index b80e24a..3743380 100644
--- a/etc/db_schema.xml
+++ b/etc/db_schema.xml
@@ -56,23 +56,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json
index 8829420..5fbd8e8 100644
--- a/etc/db_schema_whitelist.json
+++ b/etc/db_schema_whitelist.json
@@ -42,24 +42,5 @@
"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 9ed029b..02da045 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -696,9 +696,8 @@
Opengento\Gdpr\Model\Config\Source\Order\EraseComponents
-
+
- created_at
Magento\Sales\Api\Data\OrderInterface::UPDATED_AT
@@ -711,7 +710,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
@@ -733,16 +732,15 @@
-
+
- created_at
created_at
- - Opengento\Gdpr\Model\Entity\SourceProvider\DefaultFilterModifier
+ - Opengento\Gdpr\Model\Entity\SourceProvider\DefaultExpireFilterModifier