ImportModel::assignUserIDs PHP Method

assignUserIDs() public method

public assignUserIDs ( ) : boolean
return boolean
    public function assignUserIDs()
    {
        // Assign user IDs of email matches.
        $Sql = "update :_zUser i\n         join :_User u\n           on i.Email = u.Email\n         set i._NewID = u.UserID, i._Action = 'Update'";
        $this->query($Sql);
        // Assign user IDs of name matches.
        $Sql = "update :_zUser i\n         join :_User u\n            on i.Name = u.Name\n         left join :_zUser i2\n            on i2._NewID = u.UserID /* make sure no duplicates */\n         set i._NewID = u.UserID, i._Action = 'Update'\n         where i._NewID is null and i2.UserID is null";
        $this->query($Sql);
        // Get the max UserID so we can increment new users.
        $MaxID = $this->query('select max(UserID) as MaxID from :_User')->value('MaxID', 0);
        $MinID = $this->query('select min(UserID) as MinID from :_zUser where _NewID is null')->value('MinID', null);
        if (is_null($MinID)) {
            //$this->Timer->Split('No more IDs to update');
            // No more IDs to update.
            return true;
        }
        $IDInc = $MaxID - $MinID + self::ID_PADDING;
        // Update the users to insert.
        $Sql = "update :_zUser i\n         left join :_User u\n            on u.Name = i.Name /* make sure no duplicates */\n         set i._NewID = i.UserID + {$IDInc}, i._Action = 'Insert'\n         where i._NewID is null\n            and u.UserID is null";
        $this->query($Sql);
        // There still might be users that have overlapping usernames which must be changed.
        // Append a random suffix to the new username.
        $Sql = "update :_zUser i\n         set i.Name = concat(i.Name, convert(floor(1000 + rand() * 8999), char)), i._NewID = i.UserID + {$IDInc}, i._Action = 'Insert'\n         where i._NewID is null";
        $this->query($Sql);
        return true;
    }