Добавлено событие о изменении email адреса пользователя, вызовы методов для генерации уведомлений внесены внутрь транзакции бд

This commit is contained in:
ErickSkrauch
2016-07-17 18:42:37 +03:00
parent 6d3db89140
commit dd0c4fcc9e
4 changed files with 55 additions and 13 deletions

View File

@@ -6,6 +6,7 @@ use common\helpers\Error;
use common\helpers\Amqp;
use common\models\amqp\UsernameChanged;
use common\models\UsernameHistory;
use Exception;
use PhpAmqpLib\Message\AMQPMessage;
use Yii;
use yii\base\ErrorException;
@@ -51,14 +52,14 @@ class ChangeUsernameForm extends PasswordProtectedForm {
throw new ErrorException('Cannot save username history record');
}
$this->createEventTask($account->id, $account->username, $oldNickname);
$transaction->commit();
} catch (ErrorException $e) {
} catch (Exception $e) {
$transaction->rollBack();
throw $e;
}
$this->createEventTask($account->id, $account->username, $oldNickname);
return true;
}
@@ -68,13 +69,13 @@ class ChangeUsernameForm extends PasswordProtectedForm {
* @param integer $accountId
* @param string $newNickname
* @param string $oldNickname
* @throws \PhpAmqpLib\Exception\AMQPExceptionInterface
*/
public function createEventTask($accountId, $newNickname, $oldNickname) {
$model = new UsernameChanged([
'accountId' => $accountId,
'oldUsername' => $oldNickname,
'newUsername' => $newNickname,
]);
$model = new UsernameChanged;
$model->accountId = $accountId;
$model-> oldUsername = $oldNickname;
$model->newUsername = $newNickname;
$message = Amqp::getInstance()->prepareMessage($model, [
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,