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;
|
2019-06-17 02:29:19 +05:30
|
|
|
use common\emails\templates\ChangeEmail;
|
2017-11-26 07:14:41 +05:30
|
|
|
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;
|
|
|
|
|
2024-12-07 22:18:14 +05:30
|
|
|
final class SendCurrentEmailConfirmation implements RetryableJobInterface {
|
2017-11-26 07:14:41 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public mixed $email = null;
|
2017-11-26 07:14:41 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public mixed $username = null;
|
2017-11-26 07:14:41 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public mixed $code = null;
|
|
|
|
|
2017-11-26 07:14:41 +05:30
|
|
|
public static function createFromConfirmation(CurrentEmailConfirmation $confirmation): self {
|
2024-12-07 22:18:14 +05:30
|
|
|
$result = new self();
|
2017-11-26 07:14:41 +05:30
|
|
|
$result->email = $confirmation->account->email;
|
|
|
|
$result->username = $confirmation->account->username;
|
|
|
|
$result->code = $confirmation->key;
|
|
|
|
|
|
|
|
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
|
2019-06-17 02:29:19 +05:30
|
|
|
* @throws \common\emails\exceptions\CannotSendEmailException
|
2017-11-26 07:14:41 +05:30
|
|
|
*/
|
2024-12-02 15:40:55 +05:30
|
|
|
public function execute($queue): void {
|
2018-01-02 23:15:04 +05:30
|
|
|
Yii::$app->statsd->inc('queue.sendCurrentEmailConfirmation.attempt');
|
2024-12-07 22:18:14 +05:30
|
|
|
$template = new ChangeEmail(Yii::$app->mailer);
|
2019-06-17 02:29:19 +05:30
|
|
|
$template->setKey($this->code);
|
|
|
|
$template->send(EmailHelper::buildTo($this->username, $this->email));
|
2017-11-26 07:14:41 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|