EmailActivation::TYPE_CURRENT_EMAIL_CONFIRMATION], ['email', EmailValidator::class], ]; } public function getAccount(): Account { return $this->account; } public function sendNewEmailConfirmation(): bool { if (!$this->validate()) { return false; } $transaction = Yii::$app->db->beginTransaction(); /** @var \common\models\confirmations\CurrentEmailConfirmation $previousActivation */ $previousActivation = $this->key; $previousActivation->delete(); $activation = $this->createCode(); EmailHelper::changeEmailConfirmNew($activation); $transaction->commit(); return true; } /** * @return NewEmailConfirmation * @throws ErrorException */ public function createCode() { $emailActivation = new NewEmailConfirmation(); $emailActivation->account_id = $this->getAccount()->id; $emailActivation->newEmail = $this->email; if (!$emailActivation->save()) { throw new ErrorException('Cannot save email activation model'); } return $emailActivation; } public function __construct(Account $account, array $config = []) { $this->account = $account; parent::__construct($config); } }