Fixes ACCOUNTS-BQ. Don't use mailer in constructor

This commit is contained in:
ErickSkrauch 2024-12-07 17:48:14 +01:00
parent 5ed6f0ce86
commit c7d192d14e
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
2 changed files with 4 additions and 9 deletions

View File

@ -7,10 +7,9 @@ use common\emails\EmailHelper;
use common\emails\templates\ChangeEmail;
use common\models\confirmations\CurrentEmailConfirmation;
use Yii;
use yii\mail\MailerInterface;
use yii\queue\RetryableJobInterface;
class SendCurrentEmailConfirmation implements RetryableJobInterface {
final class SendCurrentEmailConfirmation implements RetryableJobInterface {
public mixed $email = null;
@ -18,11 +17,8 @@ class SendCurrentEmailConfirmation implements RetryableJobInterface {
public mixed $code = null;
public function __construct(public MailerInterface $mailer) {
}
public static function createFromConfirmation(CurrentEmailConfirmation $confirmation): self {
$result = new self(Yii::$app->mailer);
$result = new self();
$result->email = $confirmation->account->email;
$result->username = $confirmation->account->username;
$result->code = $confirmation->key;
@ -44,7 +40,7 @@ class SendCurrentEmailConfirmation implements RetryableJobInterface {
*/
public function execute($queue): void {
Yii::$app->statsd->inc('queue.sendCurrentEmailConfirmation.attempt');
$template = new ChangeEmail($this->mailer);
$template = new ChangeEmail(Yii::$app->mailer);
$template->setKey($this->code);
$template->send(EmailHelper::buildTo($this->username, $this->email));
}

View File

@ -8,7 +8,6 @@ use common\models\AccountQuery;
use common\models\confirmations\CurrentEmailConfirmation;
use common\tasks\SendCurrentEmailConfirmation;
use common\tests\unit\TestCase;
use Yii;
use yii\queue\Queue;
use yii\symfonymailer\Message;
@ -34,7 +33,7 @@ class SendCurrentEmailConfirmationTest extends TestCase {
}
public function testExecute(): void {
$task = new SendCurrentEmailConfirmation(Yii::$app->mailer);
$task = new SendCurrentEmailConfirmation();
$task->username = 'mock-username';
$task->email = 'mock@ely.by';
$task->code = 'GFEDCBA';