mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Отправка всех email вынесена в очередь
This commit is contained in:
43
common/tasks/SendNewEmailConfirmation.php
Normal file
43
common/tasks/SendNewEmailConfirmation.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace common\tasks;
|
||||
|
||||
use common\emails\EmailHelper;
|
||||
use common\emails\templates\ChangeEmailConfirmNewEmail;
|
||||
use common\models\confirmations\NewEmailConfirmation;
|
||||
use yii\queue\RetryableJobInterface;
|
||||
|
||||
class SendNewEmailConfirmation implements RetryableJobInterface {
|
||||
|
||||
public $email;
|
||||
|
||||
public $username;
|
||||
|
||||
public $code;
|
||||
|
||||
public static function createFromConfirmation(NewEmailConfirmation $confirmation): self {
|
||||
$result = new self();
|
||||
$result->email = $confirmation->getNewEmail();
|
||||
$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) {
|
||||
$to = EmailHelper::buildTo($this->username, $this->email);
|
||||
$template = new ChangeEmailConfirmNewEmail($to, $this->username, $this->code);
|
||||
$template->send();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user