Refactor emails models objects, rework related tests

This commit is contained in:
ErickSkrauch
2019-06-16 23:59:19 +03:00
parent 1bf249030f
commit 70d1999d55
24 changed files with 522 additions and 196 deletions

View File

@@ -1,9 +1,10 @@
<?php
declare(strict_types=1);
namespace common\tasks;
use common\emails\EmailHelper;
use common\emails\templates\ChangeEmailConfirmCurrentEmail;
use common\emails\templates\ChangeEmail;
use common\models\confirmations\CurrentEmailConfirmation;
use Yii;
use yii\queue\RetryableJobInterface;
@@ -25,22 +26,23 @@ class SendCurrentEmailConfirmation implements RetryableJobInterface {
return $result;
}
public function getTtr() {
public function getTtr(): int {
return 30;
}
public function canRetry($attempt, $error) {
public function canRetry($attempt, $error): bool {
return true;
}
/**
* @param \yii\queue\Queue $queue
* @throws \common\emails\exceptions\CannotSendEmailException
*/
public function execute($queue) {
Yii::$app->statsd->inc('queue.sendCurrentEmailConfirmation.attempt');
$to = EmailHelper::buildTo($this->username, $this->email);
$template = new ChangeEmailConfirmCurrentEmail($to, $this->code);
$template->send();
$template = new ChangeEmail(Yii::$app->mailer);
$template->setKey($this->code);
$template->send(EmailHelper::buildTo($this->username, $this->email));
}
}

View File

@@ -1,9 +1,10 @@
<?php
declare(strict_types=1);
namespace common\tasks;
use common\emails\EmailHelper;
use common\emails\templates\ChangeEmailConfirmNewEmail;
use common\emails\templates\ConfirmNewEmail;
use common\models\confirmations\NewEmailConfirmation;
use Yii;
use yii\queue\RetryableJobInterface;
@@ -25,22 +26,24 @@ class SendNewEmailConfirmation implements RetryableJobInterface {
return $result;
}
public function getTtr() {
public function getTtr(): int {
return 30;
}
public function canRetry($attempt, $error) {
public function canRetry($attempt, $error): bool {
return true;
}
/**
* @param \yii\queue\Queue $queue
* @throws \common\emails\exceptions\CannotSendEmailException
*/
public function execute($queue) {
Yii::$app->statsd->inc('queue.sendNewEmailConfirmation.attempt');
$to = EmailHelper::buildTo($this->username, $this->email);
$template = new ChangeEmailConfirmNewEmail($to, $this->username, $this->code);
$template->send();
$template = new ConfirmNewEmail(Yii::$app->mailer);
$template->setKey($this->code);
$template->setUsername($this->username);
$template->send(EmailHelper::buildTo($this->username, $this->email));
}
}

View File

@@ -1,5 +1,6 @@
<?php
declare(strict_types=1);
namespace common\tasks;
use common\emails\EmailHelper;
@@ -34,11 +35,11 @@ class SendPasswordRecoveryEmail implements RetryableJobInterface {
return $result;
}
public function getTtr() {
public function getTtr(): int {
return 30;
}
public function canRetry($attempt, $error) {
public function canRetry($attempt, $error): bool {
return true;
}
@@ -48,10 +49,10 @@ class SendPasswordRecoveryEmail implements RetryableJobInterface {
*/
public function execute($queue) {
Yii::$app->statsd->inc('queue.sendPasswordRecovery.attempt');
$params = new ForgotPasswordParams($this->username, $this->code, $this->link);
$to = EmailHelper::buildTo($this->username, $this->email);
$template = new ForgotPasswordEmail($to, $this->locale, $params, Yii::$app->emailsRenderer);
$template->send();
$template = new ForgotPasswordEmail(Yii::$app->mailer, Yii::$app->emailsRenderer);
$template->setLocale($this->locale);
$template->setParams(new ForgotPasswordParams($this->username, $this->code, $this->link));
$template->send(EmailHelper::buildTo($this->username, $this->email));
}
}

View File

@@ -1,5 +1,6 @@
<?php
declare(strict_types=1);
namespace common\tasks;
use common\emails\EmailHelper;
@@ -34,11 +35,11 @@ class SendRegistrationEmail implements RetryableJobInterface {
return $result;
}
public function getTtr() {
public function getTtr(): int {
return 30;
}
public function canRetry($attempt, $error) {
public function canRetry($attempt, $error): bool {
return true;
}
@@ -48,10 +49,10 @@ class SendRegistrationEmail implements RetryableJobInterface {
*/
public function execute($queue) {
Yii::$app->statsd->inc('queue.sendRegistrationEmail.attempt');
$params = new RegistrationEmailParams($this->username, $this->code, $this->link);
$to = EmailHelper::buildTo($this->username, $this->email);
$template = new RegistrationEmail($to, $this->locale, $params, Yii::$app->emailsRenderer);
$template->send();
$template = new RegistrationEmail(Yii::$app->mailer, Yii::$app->emailsRenderer);
$template->setLocale($this->locale);
$template->setParams(new RegistrationEmailParams($this->username, $this->code, $this->link));
$template->send(EmailHelper::buildTo($this->username, $this->email));
}
}