mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Добавлено событие о изменении email адреса пользователя, вызовы методов для генерации уведомлений внесены внутрь транзакции бд
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
namespace api\models\profile\ChangeEmail;
|
||||
|
||||
use api\models\base\KeyConfirmationForm;
|
||||
use common\helpers\Amqp;
|
||||
use common\models\Account;
|
||||
use common\models\amqp\EmailChanged;
|
||||
use Exception;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use Yii;
|
||||
use yii\base\ErrorException;
|
||||
use yii\base\Exception;
|
||||
|
||||
class ConfirmNewEmailForm extends KeyConfirmationForm {
|
||||
|
||||
@@ -38,11 +41,14 @@ class ConfirmNewEmailForm extends KeyConfirmationForm {
|
||||
$activation->delete();
|
||||
|
||||
$account = $this->getAccount();
|
||||
$oldEmail = $account->email;
|
||||
$account->email = $activation->newEmail;
|
||||
if (!$account->save()) {
|
||||
throw new ErrorException('Cannot save new account email value');
|
||||
}
|
||||
|
||||
$this->createTask($account->id, $account->email, $oldEmail);
|
||||
|
||||
$transaction->commit();
|
||||
} catch (Exception $e) {
|
||||
$transaction->rollBack();
|
||||
@@ -52,4 +58,23 @@ class ConfirmNewEmailForm extends KeyConfirmationForm {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $accountId
|
||||
* @param string $newEmail
|
||||
* @param string $oldEmail
|
||||
* @throws \PhpAmqpLib\Exception\AMQPExceptionInterface
|
||||
*/
|
||||
public function createTask($accountId, $newEmail, $oldEmail) {
|
||||
$model = new EmailChanged;
|
||||
$model->accountId = $accountId;
|
||||
$model->oldEmail = $oldEmail;
|
||||
$model->newEmail = $newEmail;
|
||||
|
||||
$message = Amqp::getInstance()->prepareMessage($model, [
|
||||
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
|
||||
]);
|
||||
|
||||
Amqp::sendToEventsExchange('accounts.email-changed', $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user