2017-11-26 07:14:41 +05:30
|
|
|
<?php
|
2017-11-27 04:59:15 +05:30
|
|
|
declare(strict_types=1);
|
2019-06-17 02:29:19 +05:30
|
|
|
|
2017-11-26 07:14:41 +05:30
|
|
|
namespace common\tasks;
|
|
|
|
|
|
|
|
use common\emails\EmailHelper;
|
|
|
|
use common\emails\templates\RegistrationEmail;
|
|
|
|
use common\emails\templates\RegistrationEmailParams;
|
|
|
|
use common\models\confirmations\RegistrationConfirmation;
|
|
|
|
use Yii;
|
|
|
|
use yii\queue\RetryableJobInterface;
|
|
|
|
|
|
|
|
class SendRegistrationEmail implements RetryableJobInterface {
|
|
|
|
|
|
|
|
public $username;
|
|
|
|
|
|
|
|
public $email;
|
|
|
|
|
|
|
|
public $code;
|
|
|
|
|
|
|
|
public $link;
|
|
|
|
|
|
|
|
public $locale;
|
|
|
|
|
|
|
|
public static function createFromConfirmation(RegistrationConfirmation $confirmation): self {
|
|
|
|
$account = $confirmation->account;
|
|
|
|
|
|
|
|
$result = new self();
|
|
|
|
$result->username = $account->username;
|
|
|
|
$result->email = $account->email;
|
|
|
|
$result->code = $confirmation->key;
|
|
|
|
$result->link = Yii::$app->request->getHostInfo() . '/activation/' . $confirmation->key;
|
|
|
|
$result->locale = $account->lang;
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2019-06-17 02:29:19 +05:30
|
|
|
public function getTtr(): int {
|
2017-11-26 07:14:41 +05:30
|
|
|
return 30;
|
|
|
|
}
|
|
|
|
|
2019-06-17 02:29:19 +05:30
|
|
|
public function canRetry($attempt, $error): bool {
|
2017-11-26 07:14:41 +05:30
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \yii\queue\Queue $queue
|
|
|
|
* @throws \common\emails\exceptions\CannotSendEmailException
|
|
|
|
*/
|
|
|
|
public function execute($queue) {
|
2018-01-02 23:15:04 +05:30
|
|
|
Yii::$app->statsd->inc('queue.sendRegistrationEmail.attempt');
|
2019-06-17 02:29:19 +05:30
|
|
|
$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));
|
2017-11-26 07:14:41 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|