diff --git a/Model/Config/Entity/Erasure.php b/Model/Config/Entity/Erasure.php index e651df0..57f98a7 100644 --- a/Model/Config/Entity/Erasure.php +++ b/Model/Config/Entity/Erasure.php @@ -18,6 +18,7 @@ class Erasure { private const CONFIG_PATH_ERASURE_MAX_AGE = 'gdpr/erasure/entity_max_age'; private const CONFIG_PATH_ERASURE_ALLOWED_STATES = 'gdpr/erasure/allowed_states'; + private const CONFIG_PATH_ERASURE_DELAY = 'gdpr/erasure/delay'; public function __construct( private ScopeConfigInterface $scopeConfig @@ -51,4 +52,18 @@ public function getAllowedStatesToErase(int|string|null $website = null): array $website )); } + + /** + * @param int|string|null $website + * + * @return int + */ + public function getDelay(int|string|null $website = null): int + { + return (int)$this->scopeConfig->getValue( + self::CONFIG_PATH_ERASURE_DELAY, + ScopeInterface::SCOPE_WEBSITE, + $website + ); + } } diff --git a/Model/Customer/Notifier/MailSender.php b/Model/Customer/Notifier/MailSender.php index 74e3c16..6aa4bd0 100644 --- a/Model/Customer/Notifier/MailSender.php +++ b/Model/Customer/Notifier/MailSender.php @@ -15,25 +15,19 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Store\Model\StoreManagerInterface; -use Opengento\Gdpr\Model\EraseEntityManagement; +use Opengento\Gdpr\Model\Config\Entity\Erasure; use Opengento\Gdpr\Model\Notifier\AbstractMailSender; class MailSender extends AbstractMailSender implements SenderInterface { - private View $customerViewHelper; - - private StoreManagerInterface $storeManager; - public function __construct( - protected EraseEntityManagement $entityManagement, - 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); } @@ -44,7 +38,7 @@ public function __construct( */ public function send(CustomerInterface $customer): void { - $delay = $this->entityManagement->resolveErasureDelay(); + $delay = $this->erasureConfig->getDelay(); $storeId = $customer->getStoreId() === null ? null : (int)$customer->getStoreId(); $vars = [ diff --git a/Model/EraseEntityManagement.php b/Model/EraseEntityManagement.php index f44ed74..f66bccf 100644 --- a/Model/EraseEntityManagement.php +++ b/Model/EraseEntityManagement.php @@ -18,13 +18,13 @@ 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; class EraseEntityManagement implements EraseEntityManagementInterface { - private const CONFIG_PATH_ERASURE_DELAY = 'gdpr/erasure/delay'; - public function __construct( + private Erasure $erasureConfig, private EraseEntityInterfaceFactory $eraseEntityFactory, private EraseEntityRepositoryInterface $eraseRepository, private ProcessorFactory $processorFactory, @@ -94,12 +94,7 @@ private function retrieveScheduledAt(): string { return $this->localeDate->gmtDate( DateTimeFormat::DATETIME_PHP_FORMAT, - $this->resolveErasureDelay() * 60 + $this->localeDate->gmtTimestamp() + $this->erasureConfig->getDelay() * 60 + $this->localeDate->gmtTimestamp() ); } - - public function resolveErasureDelay(): int - { - return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY); - } }