2017-11-26 07:14:41 +05:30
|
|
|
<?php
|
2017-11-27 04:59:15 +05:30
|
|
|
declare(strict_types=1);
|
2017-11-26 07:14:41 +05:30
|
|
|
namespace common\tasks;
|
|
|
|
|
|
|
|
use common\emails\EmailHelper;
|
|
|
|
use common\emails\templates\ChangeEmailConfirmCurrentEmail;
|
|
|
|
use common\models\confirmations\CurrentEmailConfirmation;
|
2018-01-02 23:15:04 +05:30
|
|
|
use Yii;
|
2017-11-26 07:14:41 +05:30
|
|
|
use yii\queue\RetryableJobInterface;
|
|
|
|
|
|
|
|
class SendCurrentEmailConfirmation implements RetryableJobInterface {
|
|
|
|
|
|
|
|
public $email;
|
|
|
|
|
|
|
|
public $username;
|
|
|
|
|
|
|
|
public $code;
|
|
|
|
|
|
|
|
public static function createFromConfirmation(CurrentEmailConfirmation $confirmation): self {
|
|
|
|
$result = new self();
|
|
|
|
$result->email = $confirmation->account->email;
|
|
|
|
$result->username = $confirmation->account->username;
|
|
|
|
$result->code = $confirmation->key;
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTtr() {
|
|
|
|
return 30;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function canRetry($attempt, $error) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \yii\queue\Queue $queue
|
|
|
|
*/
|
|
|
|
public function execute($queue) {
|
2018-01-02 23:15:04 +05:30
|
|
|
Yii::$app->statsd->inc('queue.sendCurrentEmailConfirmation.attempt');
|
2017-11-26 07:14:41 +05:30
|
|
|
$to = EmailHelper::buildTo($this->username, $this->email);
|
|
|
|
$template = new ChangeEmailConfirmCurrentEmail($to, $this->code);
|
|
|
|
$template->send();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|