UserModel::insertInternal PHP Method

insertInternal() private method

Users are inserted in various methods depending on registration setups.
private insertInternal ( array $Fields, array $Options = [] ) : integer | false
$Fields array The user to insert.
$Options array Insert options.
return integer | false Returns the new ID of the user or **false** if there was an error.
    private function insertInternal($Fields, $Options = [])
    {
        $this->EventArguments['InsertFields'] =& $Fields;
        $this->fireEvent('BeforeInsertUser');
        if (!val('Setup', $Options)) {
            unset($Fields['Admin']);
        }
        // Massage the roles for email confirmation.
        if (self::requireConfirmEmail() && !val('NoConfirmEmail', $Options)) {
            $ConfirmRoleID = RoleModel::getDefaultRoles(RoleModel::TYPE_UNCONFIRMED);
            if (!empty($ConfirmRoleID)) {
                touchValue('Attributes', $Fields, []);
                $ConfirmationCode = randomString(8);
                $Fields['Attributes']['EmailKey'] = $ConfirmationCode;
                $Fields['Confirmed'] = 0;
            }
        }
        // Make sure to encrypt the password for saving...
        if (array_key_exists('Password', $Fields) && !val('HashMethod', $Fields)) {
            $PasswordHash = new Gdn_PasswordHash();
            $Fields['Password'] = $PasswordHash->hashPassword($Fields['Password']);
            $Fields['HashMethod'] = 'Vanilla';
        }
        // Certain configurations can allow blank email addresses.
        if (val('Email', $Fields, null) === null) {
            $Fields['Email'] = '';
        }
        $Roles = val('Roles', $Fields);
        unset($Fields['Roles']);
        if (array_key_exists('Attributes', $Fields) && !is_string($Fields['Attributes'])) {
            $Fields['Attributes'] = dbencode($Fields['Attributes']);
        }
        $UserID = $this->SQL->insert($this->Name, $Fields);
        if (is_array($Roles)) {
            $this->saveRoles($UserID, $Roles, false);
        }
        // Approval registration requires an email confirmation.
        if ($UserID && isset($ConfirmationCode) && strtolower(c('Garden.Registration.Method')) == 'approval') {
            // Send the confirmation email.
            $this->sendEmailConfirmationEmail($UserID);
        }
        // Fire an event for user inserts
        $this->EventArguments['InsertUserID'] = $UserID;
        $this->EventArguments['InsertFields'] = $Fields;
        $this->fireEvent('AfterInsertUser');
        return $UserID;
    }
UserModel