The ASPSmith Articles, ASPAlliance.com |
IBuySpy: Copy Portal |
| http://www.aspalliance.com/stevesmith/articles/ibscopyportal.asp |
|
This article was written to support the 7/1/2001 release of the IBS Portal and may not work with the latest version. If you feel inclined to update it in any way, please let me know and I will credit you. Thanks! The IBuySpy.com Portal Application supports multiple portals running off of the same database, through the use of the PortalID key in the Portals table. However, in order to make a separate installation of the Portal website use a non-default PortalID, you must hand edit and then recompile the Configuration.cs file. The change must be made in the PortalSettings constructor, as shown in the following code snippet:
public PortalSettings(int tabIndex, int tabId) {
// Create Instance of Connection and Command Object
SqlConnection myConnection =
new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("GetPortalSettings", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterPortalAlias =
new SqlParameter("@PortalAlias", SqlDbType.NVarChar, 50);
parameterPortalAlias.Value = "p_default";
// CHANGE THIS TO POINT TO NEW PORTAL
myCommand.Parameters.Add(parameterPortalAlias);
Now, before you go hand editing these tables to set up your new portal, copy the following stored procedure to your Portal database and simply execute it, providing it with the new Portal name, alias, and whether you want the edit buttons to always show by default. If you've already created your new portal and just want to copy the modules and tabs from an existing portal to the one you've created, specify your new portal's ID for the @new_portal_id parameter. In either case, specify the source portal's id for @source_portal_id. sp_CopyPortalData
/*
This procedure copies the layout and modules for one portal to another portal.
If @new_portal_id is set, then the source_portal_id's
data is copied to the specified new_portal_id. Otherwise, the alias,
name, and AlwaysShowEditButton for the new portal to be
created must be specified.
*/
Create Procedure sp_CopyPortalData
(
@portal_alias nvarchar(50) = null,
@portal_name nvarchar(128) = null,
@AlwaysShowEditButton bit = 0,
@source_portal_id int = 0,
@new_portal_id int = -1 OUTPUT
)
AS
BEGIN
IF (@new_portal_id = -1)
BEGIN
insert portals (portalalias, portalname, alwaysshoweditbutton)
values (@portal_alias,@portal_name,@AlwaysShowEditButton)
select @new_portal_id = @@IDENTITY
END
-- Copy Tabs
INSERT INTO tabs (TabOrder, PortalID, TabName, MobileTabName, AuthorizedRoles, ShowMobile)
SELECT taborder, @new_portal_id, tabname, mobiletabname, authorizedroles,
showmobile
FROM tabs
WHERE PortalID = @source_portal_id
ORDER BY taborder
-- Copy Module Definitions
INSERT INTO ModuleDefinitions
SELECT @new_portal_id, FriendlyName, DesktopSrc, MobileSrc
FROM ModuleDefinitions
WHERE PortalID = @source_portal_id
ORDER BY FriendlyName
INSERT INTO Modules (TabID, ModuleDefID, ModuleOrder, PaneName, ModuleTitle,
AuthorizedEditRoles, CacheTime, ShowMobile)
SELECT (select T.TabID from Tabs T where T.PortalID = @new_portal_id
and T.TabName = (select T2.TabName from Tabs T2 where T2.TabID = M.TabID)) as TabID,
(Select Top 1 MD.ModuleDefID
FROM ModuleDefinitions MD
WHERE MD.PortalID = @new_portal_id
AND MD.FriendlyName =
(select MD2.FriendlyName
from ModuleDefinitions MD2
where MD2.ModuleDefID = M.ModuleDefID
)
) as ModuleDefID,
M.ModuleOrder, M.PaneName, M.ModuleTitle, M.AuthorizedEditRoles, M.CacheTime, M.ShowMobile
FROM Modules M
WHERE EXISTS (SELECT * FROM Modules M2 INNER JOIN Tabs T ON M2.TabID = T.TabID
WHERE T.PortalID = @source_portal_id)
AND (select T.TabID from Tabs T where T.PortalID = @new_portal_id and
T.TabName = (select T2.TabName from Tabs T2 where T2.TabID = M.TabID)) is not null
AND M.TabID In (SELECT TabID From Tabs where PortalID = @source_portal_id)
ORDER BY M.ModuleID
END
If you've just installed the portal and would simply like to create a separate instance of the portal to play with while keeping the original intact, you can do so by copying (or re-running the installer) the web application to another web folder (make sure you set it up in IIS as an application), creating the procedure above (just copy it and run it in Enterprise Manager), and then executing the following sql: declare @new_portal_id int select @new_portal_id = -1 exec sp_CopyPortalData "p_MyPortal", "My New Portal", 0, 0, @new_portal_id OUTPUT select @new_portal_id Really only the exec statement is needed to do the work, the rest of it just lets you see the new portalID that is assigned to your new portal. Go ahead and rename the alias to whatever you like. This is what you will put in the Configuration.cs file (above) for the new portal site. Hope you find this useful and if you find any bugs, let me know! (thanks to Shaun Eagan for helping me correct this to work with the 0711 SDK of the portal.) Add Portal SP (by Paul Marza)Recently Paul Marza sent me this code to add a new portal, rather than copying an existing one:
/* this procedure creates a new minimal portal.
it will use as input the alias you want to assign to it, and the alias
will be used for the name as well
it returns the ID of the newly created portal
It will add a new user, set the role, and add two tabs.
The minimal portal will contain as much information as needed to start
building your new portal, but not much,
so you'll have do 'build' your portal from inside, add users and so on.
Or you can extend this stored procedure
*/
CREATE PROCEDURE tsa_AddAPortal
(
@PortalAlias nvarchar(50),
@new_portalID int OUTPUT
)
AS
BEGIN
DECLARE @role_ID int
DECLARE @user_ID int
DECLARE @homeTab int -- the 'Home' tab
DECLARE @adminTab int -- the 'Admin' tab
DECLARE @modDefID int
-- insert the new portal
IF (@PortalAlias != "")
BEGIN
insert into Portals (PortalAlias, PortalName,
AlwaysShowEditButton)
values (@PortalAlias, @PortalAlias, 0)
select @new_portalID = @@IDENTITY
END
-- add a role for this portal
-- save the added ID for later use
insert into Roles (PortalID, RoleName)
values (@new_PortalID, 'Admins')
select @role_ID = @@IDENTITY
-- add a new user, by default: @PortalAlias, PortalAlias@admins.org
-- the name of user will be the portal alias to avoid duplicate
values (if you use this procedure several times)
-- still, if you create a new portal with an existing alias you'll
have a conflict. Any ideas?
-- save the added ID for later use
insert into users (Name, Password, Email)
values (@PortalAlias, @PortalAlias, @PortalAlias + '@admins.org')
select @user_ID = @@IDENTITY
-- assign a role to this user
insert into UserRoles(UserID, RoleID)
values (@user_ID, @role_ID)
-- add two tabs to the portal, the 'Home' and 'Admin'
insert into Tabs(TabOrder, PortalID, TabName, MobileTabName,
AuthorizedRoles, ShowMobile)
values (1, @new_portalID, 'Home', 'Home', 'All Users;', 0)
select @homeTab = @@IDENTITY
insert into Tabs(TabOrder, PortalID, TabName, MobileTabName,
AuthorizedRoles, ShowMobile)
values (3, @new_portalID, 'Admin', 'Admin', 'Admins;', 0)
select @adminTab = @@IDENTITY
/*
now I need to add entries into ModuleDefinitions and Modules tables.
this will be done by adding the one by one. Ad additional stores
procedure may be used to have a cleaner code
you can add more modules to have them by default or you can just add
more from portal administration
the order of insertion will give the order in which modules are shown
*/
-- //////////////////////////////////////////////////
-- add modules for Admin
-- //////////////////////////////////////////////////
-- SiteSettings, center, idx 1
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Site Settings (Admin)',
'Admin/SiteSettings.ascx', ' ')
select @modDefID = @@IDENTITY
-- now place the module into a tab
insert into Modules(TabID, ModuleDefID, ModuleOrder, PaneName,
ModuleTitle, AuthorizedEditRoles, CacheTime, ShowMobile)
values(@adminTab, @modDefID, 1, 'ContentPane', 'Site Settings',
'Admins;', 0, 0)
--Tabs, center, idx 2
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Tabs (Admin)', 'Admin/Tabs.ascx', ' ')
select @modDefID = @@IDENTITY
--
insert into Modules(TabID, ModuleDefID, ModuleOrder, PaneName,
ModuleTitle, AuthorizedEditRoles, CacheTime, ShowMobile)
values(@adminTab, @modDefID, 2, 'ContentPane', 'Tabs', 'Admins;', 0,
0)
--Roles, center, idx 3
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Roles (Admin)', 'Admin/Roles.ascx', ' ')
select @modDefID = @@IDENTITY
--
insert into Modules(TabID, ModuleDefID, ModuleOrder, PaneName,
ModuleTitle, AuthorizedEditRoles, CacheTime, ShowMobile)
values(@adminTab, @modDefID, 3, 'ContentPane', 'Security Roles',
'Admins;', 0, 0)
--ManageUsers, center, idx 4
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Manage Users (Admin)', 'Admin/Users.ascx', '
')
select @modDefID = @@IDENTITY
-- now place the module into a tab
insert into Modules(TabID, ModuleDefID, ModuleOrder, PaneName,
ModuleTitle, AuthorizedEditRoles, CacheTime, ShowMobile)
values(@adminTab, @modDefID, 4, 'ContentPane', 'Manage Users',
'Admins;', 0, 0)
--Module Types, center, idx 4
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Module Types (Admin)',
'Admin/ModuleDefs.ascx', ' ')
select @modDefID = @@IDENTITY
-- now place the module into a tab
insert into Modules(TabID, ModuleDefID, ModuleOrder, PaneName,
ModuleTitle, AuthorizedEditRoles, CacheTime, ShowMobile)
values(@adminTab, @modDefID, 1, 'RightPane', 'Module Types',
'Admins;', 0, 0)
-- //////////////////////////////////////////////////
-- add other modules
-- //////////////////////////////////////////////////
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Announcements',
'DesktopModules/Announcements.ascx', 'MobileModules/Announcements.ascx')
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Discussion', 'DesktopModules/Discussion.ascx',
' ')
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Events', 'DesktopModules/HtmlModule.ascx',
'MobileModules/Events.ascx')
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Html Document',
'DesktopModules/HtmlModule.ascx', 'MobileModules/Text.ascx')
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Image', 'DesktopModules/ImageModule.ascx', '')
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Links', 'DesktopModules/Links.ascx',
'MobileModules/Links.ascx')
insert into ModuleDefinitions(PortalID, FriendlyName, DesktopSrc,
MobileSrc)
values (@new_portalID, 'Quick Links',
'DesktopModules/QuickLinks.ascx', 'MobileModules/Links.ascx')
END
GO
|