UserManager::changeUserEmail PHP Method

changeUserEmail() public method

public changeUserEmail ( User $user, $email, boolean | true $confirm = true ) : boolean
$user User
$email
$confirm boolean | true
return boolean
    public function changeUserEmail(User $user, $email, $confirm = true)
    {
        if ($user->email == $email) {
            return true;
        }
        $transaction = Yii::app()->getDb()->beginTransaction();
        try {
            $user->email_confirm = User::EMAIL_CONFIRM_NO;
            $user->email = $email;
            if ($user->save()) {
                if ($confirm && ($token = $this->tokenStorage->createEmailVerifyToken($user)) === false) {
                    throw new CException(Yii::t('UserModule.user', 'Error change Email!'));
                }
                Yii::app()->eventManager->fire(UserEvents::SUCCESS_EMAIL_CHANGE, new UserEmailConfirmEvent($token, $user));
                $transaction->commit();
                return true;
            }
            throw new CException(Yii::t('UserModule.user', 'Error change Email!'));
        } catch (Exception $e) {
            $transaction->rollback();
            return false;
        }
    }