diff options
author | Sam <8619576+samjf@users.noreply.github.com> | 2022-01-10 18:37:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-10 18:37:28 +0300 |
commit | d17b842d09fa3726f2fee7c203601d6895d14bad (patch) | |
tree | b89eba80acaf5c7f85b140075ee2000f718703b7 /plugins/UsersManager | |
parent | 62f6d460f3358459f04e4a416b9400d65d563625 (diff) |
Refactor emails about user info change away from the generic Mail class into their own sub-class. (#18593)
Diffstat (limited to 'plugins/UsersManager')
-rw-r--r-- | plugins/UsersManager/API.php | 19 | ||||
-rw-r--r-- | plugins/UsersManager/Emails/UserInfoChangedEmail.php | 71 |
2 files changed, 73 insertions, 17 deletions
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 7bc1ae4068..5c258b54e4 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -18,8 +18,6 @@ use Piwik\Common; use Piwik\Config; use Piwik\Container\StaticContainer; use Piwik\Date; -use Piwik\IP; -use Piwik\Mail; use Piwik\Metrics\Formatter; use Piwik\NoAccessException; use Piwik\Option; @@ -27,9 +25,9 @@ use Piwik\Piwik; use Piwik\Plugin; use Piwik\Plugins\CoreAdminHome\Emails\UserCreatedEmail; use Piwik\Plugins\Login\PasswordVerifier; +use Piwik\Plugins\UsersManager\Emails\UserInfoChangedEmail; use Piwik\Site; use Piwik\Tracker\Cache; -use Piwik\View; use Piwik\Plugins\CoreAdminHome\Emails\UserDeletedEmail; /** @@ -1511,23 +1509,10 @@ class API extends \Piwik\Plugin\API { $deviceDescription = $this->getDeviceDescription(); - $view = new View('@UsersManager/_userInfoChangedEmail.twig'); - $view->type = $type; - $view->accountName = Common::sanitizeInputValue($user['login']); - $view->newEmail = Common::sanitizeInputValue($newValue); - $view->ipAddress = IP::getIpFromHeader(); - $view->deviceDescription = $deviceDescription; - - $mail = new Mail(); + $mail = new UserInfoChangedEmail($type, $newValue, $deviceDescription, $user['login']); $mail->addTo($emailTo, $user['login']); $mail->setSubject(Piwik::translate($subject)); - $mail->setDefaultFromPiwik(); - $mail->setWrappedHtmlBody($view); - - $replytoEmailName = Config::getInstance()->General['login_password_recovery_replyto_email_name']; - $replytoEmailAddress = Config::getInstance()->General['login_password_recovery_replyto_email_address']; - $mail->addReplyTo($replytoEmailAddress, $replytoEmailName); $mail->send(); } diff --git a/plugins/UsersManager/Emails/UserInfoChangedEmail.php b/plugins/UsersManager/Emails/UserInfoChangedEmail.php new file mode 100644 index 0000000000..c91847d0c5 --- /dev/null +++ b/plugins/UsersManager/Emails/UserInfoChangedEmail.php @@ -0,0 +1,71 @@ +<?php + +namespace Piwik\Plugins\UsersManager\Emails; + +use Piwik\Common; +use Piwik\Config; +use Piwik\IP; +use Piwik\Mail; +use Piwik\View; + +class UserInfoChangedEmail extends Mail +{ + + /** + * @var string + */ + private $type; + + /** + * @var string + */ + private $changedNewValue; + + /** + * @var string + */ + private $deviceDescription; + + /** + * @var string + */ + private $login; + + public function __construct($type, $changedNewValue, $deviceDescription, $login) + { + parent::__construct(); + $this->type = $type; + $this->changedNewValue = $changedNewValue; + $this->deviceDescription = $deviceDescription; + $this->login = $login; + $this->setUpEmail(); + } + + + private function setUpEmail() + { + $this->setDefaultFromPiwik(); + $this->setWrappedHtmlBody($this->getDefaultBodyView()); + + $replytoEmailName = Config::getInstance()->General['login_password_recovery_replyto_email_name']; + $replytoEmailAddress = Config::getInstance()->General['login_password_recovery_replyto_email_address']; + $this->addReplyTo($replytoEmailAddress, $replytoEmailName); + } + + + /** + * @return View + */ + protected function getDefaultBodyView() + { + $deviceDescription = $this->deviceDescription; + + $view = new View('@UsersManager/_userInfoChangedEmail.twig'); + $view->type = $this->type; + $view->accountName = Common::sanitizeInputValue($this->login); + $view->newEmail = Common::sanitizeInputValue($this->changedNewValue); + $view->ipAddress = IP::getIpFromHeader(); + $view->deviceDescription = $deviceDescription; + return $view; + } +}
\ No newline at end of file |