DotNetNuke (DNN) Move User to Portal
November 3, 2011
Leave a comment
I have a client where we use DNN as the framework around a multi-portal site. The portals are basically the same (serving the same ‘industry’), but they’re all private branded for large customers.
Occasionally, we need to move a user from one of those portals to another. Again, same industry, same resource pool. Now, you can buy plugin modules to do this, OR you can write a SQL script and do it yourself.
Here’s the script I wrote, feel free to use, comment, modify for your specific needs.
Assumptions:
- Each Portal has the exact same role names
- Each Portal has the exact same Profile Attributes
-- =============================================
-- Author: Michael Larter
-- Create date: 11/3/2011
-- Description: Move User and their roles to
-- a different portal
-- =============================================
CREATE PROCEDURE [dbo].[spLiqqid_DNN_UsersMoveToPortal]
@userid int, -- UserID of the user to move
@portalID int -- Target Portal
AS
BEGIN
SET NOCOUNT ON;
-- Easy part, move the user to a different portal
UPDATE UserPortals
SET portalid=@portalID where userid=@userid
-- Change their role id's to be those from the target portal
-- Assumes that the role names between the two portals are the same
update UR1
set ur1.RoleID = (select RoleID from roles R2 where R2.portalid = @portalID and R2.rolename = R1.RoleName )
from UserRoles UR1
join Roles R1 ON R1.RoleID = UR1.RoleID
where UserID = @userid
-- Change their profile attributes to be that from the target portal
-- Assumes that the PropertyDefinition names between the two portals are the same
update UP1
set UP1.PropertyDefinitionID = (select PropertyDefinitionID FROM ProfilePropertyDefinition PPD2 where PPD2.PropertyName = PPD1.PropertyName and PortalID=@portalid)
from UserProfile UP1
join dbo.ProfilePropertyDefinition PPD1 on PPD1.PropertyDefinitionID = UP1.PropertyDefinitionID
where UserID=@userid
END
Categories: DotNetNuke
DNN, DotNetNuke, Portal, SQL, User