diff --git a/Model/Customer/Erase/Notifier.php b/Model/Customer/Erase/Notifier.php index 787c60d..af58e84 100644 --- a/Model/Customer/Erase/Notifier.php +++ b/Model/Customer/Erase/Notifier.php @@ -13,32 +13,29 @@ use Opengento\Gdpr\Model\Customer\Notifier\SenderInterface; use Opengento\Gdpr\Model\Customer\OrigDataRegistry; use Opengento\Gdpr\Model\Erase\NotifierInterface; +use Psr\Log\LoggerInterface; final class Notifier implements NotifierInterface { - /** - * @var SenderInterface[] - */ + /** @var SenderInterface[] */ private array $senders; - /** - * @var CustomerRepositoryInterface - */ private CustomerRepositoryInterface $customerRepository; - /** - * @var OrigDataRegistry - */ private OrigDataRegistry $origDataRegistry; + private LoggerInterface $logger; + public function __construct( array $senders, CustomerRepositoryInterface $customerRepository, - OrigDataRegistry $origDataRegistry + OrigDataRegistry $origDataRegistry, + LoggerInterface $logger ) { $this->senders = $senders; $this->customerRepository = $customerRepository; $this->origDataRegistry = $origDataRegistry; + $this->logger = $logger; } /** @@ -51,7 +48,11 @@ public function notify(EraseEntityInterface $eraseEntity): void $customer = $this->origDataRegistry->get($customerId) ?? $this->customerRepository->getById($customerId); foreach ($this->senders as $sender) { - $sender->send($customer); + try { + $sender->send($customer); + } catch (LocalizedException $e) { + $this->logger->error($e->getLogMessage(), $e->getTrace()); + } } } } diff --git a/Model/Customer/Export/Notifier.php b/Model/Customer/Export/Notifier.php index 5708956..07e0671 100644 --- a/Model/Customer/Export/Notifier.php +++ b/Model/Customer/Export/Notifier.php @@ -12,25 +12,25 @@ use Opengento\Gdpr\Api\Data\ExportEntityInterface; use Opengento\Gdpr\Model\Customer\Notifier\SenderInterface; use Opengento\Gdpr\Model\Export\NotifierInterface; +use Psr\Log\LoggerInterface; final class Notifier implements NotifierInterface { - /** - * @var SenderInterface[] - */ + /** @var SenderInterface[] */ private array $senders; - /** - * @var CustomerRepositoryInterface - */ private CustomerRepositoryInterface $customerRepository; + private LoggerInterface $logger; + public function __construct( array $senders, - CustomerRepositoryInterface $customerRepository + CustomerRepositoryInterface $customerRepository, + LoggerInterface $logger ) { $this->senders = $senders; $this->customerRepository = $customerRepository; + $this->logger = $logger; } /** @@ -42,7 +42,11 @@ public function notify(ExportEntityInterface $exportEntity): void $customer = $this->customerRepository->getById($exportEntity->getEntityId()); foreach ($this->senders as $sender) { - $sender->send($customer); + try { + $sender->send($customer); + } catch (LocalizedException $e) { + $this->logger->error($e->getLogMessage(), $e->getTrace()); + } } } } diff --git a/Model/Customer/Notifier/MailSender.php b/Model/Customer/Notifier/MailSender.php index a7e59db..3fb380d 100644 --- a/Model/Customer/Notifier/MailSender.php +++ b/Model/Customer/Notifier/MailSender.php @@ -16,42 +16,26 @@ use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Store\Model\StoreManagerInterface; use Opengento\Gdpr\Model\Notifier\AbstractMailSender; -use Psr\Log\LoggerInterface; final class MailSender extends AbstractMailSender implements SenderInterface { - /** - * @var LoggerInterface - */ - private LoggerInterface $logger; - - /** - * @var View - */ private View $customerViewHelper; - /** - * @var StoreManagerInterface - */ - private $storeManager; + private StoreManagerInterface $storeManager; public function __construct( - LoggerInterface $logger, View $customerViewHelper, TransportBuilder $transportBuilder, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, array $configPaths ) { - $this->logger = $logger; $this->customerViewHelper = $customerViewHelper; $this->storeManager = $storeManager; parent::__construct($transportBuilder, $scopeConfig, $configPaths); } /** - * @param CustomerInterface $customer - * @return void * @throws LocalizedException * @throws MailException * @throws NoSuchEntityException @@ -66,12 +50,7 @@ public function send(CustomerInterface $customer): void 'customer_name' => $this->customerViewHelper->getCustomerName($customer), ], ]; - - try { - $this->sendMail($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer), $storeId, $vars); - $this->logger->debug(__('GDPR Email Success')); - } catch (MailException $exc) { - $this->logger->error(__('GDPR Email Error: %1', $exc->getMessage())); - } + + $this->sendMail($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer), $storeId, $vars); } } diff --git a/Model/Customer/Notifier/SenderInterface.php b/Model/Customer/Notifier/SenderInterface.php index 603764b..4e437e6 100644 --- a/Model/Customer/Notifier/SenderInterface.php +++ b/Model/Customer/Notifier/SenderInterface.php @@ -8,11 +8,15 @@ namespace Opengento\Gdpr\Model\Customer\Notifier; use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Framework\Exception\LocalizedException; /** * @api */ interface SenderInterface { + /** + * @throws LocalizedException + */ public function send(CustomerInterface $customer): void; } diff --git a/Model/Order/Erase/Notifier.php b/Model/Order/Erase/Notifier.php index 748960b..497e039 100644 --- a/Model/Order/Erase/Notifier.php +++ b/Model/Order/Erase/Notifier.php @@ -7,26 +7,30 @@ namespace Opengento\Gdpr\Model\Order\Erase; +use Magento\Framework\Exception\LocalizedException; use Magento\Sales\Api\OrderRepositoryInterface; use Opengento\Gdpr\Api\Data\EraseEntityInterface; use Opengento\Gdpr\Model\Erase\NotifierInterface; use Opengento\Gdpr\Model\Order\Notifier\SenderInterface; +use Psr\Log\LoggerInterface; final class Notifier implements NotifierInterface { - /** - * @var SenderInterface[] - */ + /** @var SenderInterface[] */ private array $senders; private OrderRepositoryInterface $orderRepository; + private LoggerInterface $logger; + public function __construct( array $senders, - OrderRepositoryInterface $orderRepository + OrderRepositoryInterface $orderRepository, + LoggerInterface $logger ) { $this->senders = $senders; $this->orderRepository = $orderRepository; + $this->logger = $logger; } public function notify(EraseEntityInterface $eraseEntity): void @@ -34,7 +38,11 @@ public function notify(EraseEntityInterface $eraseEntity): void $order = $this->orderRepository->get($eraseEntity->getEntityId()); foreach ($this->senders as $sender) { - $sender->send($order); + try { + $sender->send($order); + } catch (LocalizedException $e) { + $this->logger->error($e->getLogMessage(), $e->getTrace()); + } } } } diff --git a/Model/Order/Export/Notifier.php b/Model/Order/Export/Notifier.php index bba4890..584dad6 100644 --- a/Model/Order/Export/Notifier.php +++ b/Model/Order/Export/Notifier.php @@ -7,26 +7,30 @@ namespace Opengento\Gdpr\Model\Order\Export; +use Magento\Framework\Exception\LocalizedException; use Magento\Sales\Api\OrderRepositoryInterface; use Opengento\Gdpr\Api\Data\ExportEntityInterface; use Opengento\Gdpr\Model\Export\NotifierInterface; use Opengento\Gdpr\Model\Order\Notifier\SenderInterface; +use Psr\Log\LoggerInterface; final class Notifier implements NotifierInterface { - /** - * @var SenderInterface[] - */ + /** @var SenderInterface[] */ private array $senders; private OrderRepositoryInterface $orderRepository; + private LoggerInterface $logger; + public function __construct( array $senders, - OrderRepositoryInterface $orderRepository + OrderRepositoryInterface $orderRepository, + LoggerInterface $logger ) { $this->senders = $senders; $this->orderRepository = $orderRepository; + $this->logger = $logger; } /** @@ -37,7 +41,11 @@ public function notify(ExportEntityInterface $exportEntity): void $order = $this->orderRepository->get($exportEntity->getEntityId()); foreach ($this->senders as $sender) { - $sender->send($order); + try { + $sender->send($order); + } catch (LocalizedException $e) { + $this->logger->error($e->getLogMessage(), $e->getTrace()); + } } } } diff --git a/Model/Order/Notifier/SenderInterface.php b/Model/Order/Notifier/SenderInterface.php index 79941ad..13a7cf7 100644 --- a/Model/Order/Notifier/SenderInterface.php +++ b/Model/Order/Notifier/SenderInterface.php @@ -7,6 +7,7 @@ namespace Opengento\Gdpr\Model\Order\Notifier; +use Magento\Framework\Exception\LocalizedException; use Magento\Sales\Api\Data\OrderInterface; /** @@ -14,5 +15,8 @@ */ interface SenderInterface { + /** + * @throws LocalizedException + */ public function send(OrderInterface $order): void; }