Skip to content

Commit

Permalink
refactoring get erasure delay
Browse files Browse the repository at this point in the history
  • Loading branch information
kpitn committed Aug 22, 2024
1 parent ebabae0 commit 2234a18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
15 changes: 15 additions & 0 deletions Model/Config/Entity/Erasure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}
}
16 changes: 5 additions & 11 deletions Model/Customer/Notifier/MailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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 = [
Expand Down
11 changes: 3 additions & 8 deletions Model/EraseEntityManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2234a18

Please sign in to comment.