public int CreatePortal(int solutionId, string portalAlias, string portalName, string portalPath) { var tabs = new PagesDB(); var modules = new ModulesDB(); // Create a new portal var portalId = this.AddPortal(portalAlias, portalName, portalPath); // get module definitions foreach (var solutionModuleDefinition in modules.GetSolutionModuleDefinitions(solutionId)) { modules.UpdateModuleDefinitions(solutionModuleDefinition.GeneralModuleDefinitionId, portalId, true); } if (!Config.UseSingleUserBase) { const string AdminEmail = "*****@*****.**"; // Create the stradmin User for the new portal var user = new UsersDB(); // Create the "Admins" role for the new portal var roleId = user.AddRole(portalAlias, "Admins"); var userId = user.AddUser(StringsAdmin, AdminEmail, StringsAdmin, portalAlias); // Create the "Admins" profile for the new portal var profile = ProfileBase.Create(AdminEmail); profile.SetPropertyValue("Email", AdminEmail); profile.SetPropertyValue("Name", "admin"); try { profile.Save(); } catch { } // Create a new row in a many to many table (userroles) // giving the "admins" role to the stradmin user user.AddUserRole(roleId, userId, portalAlias); } // Create a new Page "home" var homePageId = tabs.AddPage(portalId, "Home", 1); // Create a new Page "admin" var localizedString = General.GetString("ADMIN_TAB_NAME"); var adminPageId = tabs.AddPage(portalId, localizedString, StrAdmins, 9999); // Add Modules for portal use // Html Document modules.UpdateModuleDefinitions(new Guid(StrGuidhtmlDocument), portalId, true); // Add Modules for portal administration // Site Settings (Admin) localizedString = General.GetString("MODULE_SITE_SETTINGS"); modules.UpdateModuleDefinitions(new Guid(StrGuidSiteSettings), portalId, true); modules.AddModule( adminPageId, 1, StrContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSiteSettings)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Pages (Admin) localizedString = General.GetString("MODULE_TABS"); modules.UpdateModuleDefinitions(new Guid(StrGuidPages), portalId, true); modules.AddModule( adminPageId, 2, StrContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidPages)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Roles (Admin) localizedString = General.GetString("MODULE_SECURITY_ROLES"); modules.UpdateModuleDefinitions(new Guid(StrGuidSecurityRoles), portalId, true); modules.AddModule( adminPageId, 3, StrContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSecurityRoles)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Manage Users (Admin) localizedString = General.GetString("MODULE_MANAGE_USERS"); modules.UpdateModuleDefinitions(new Guid(StrGuidManageUsers), portalId, true); modules.AddModule( adminPageId, 4, StrContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidManageUsers)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Module Definitions (Admin) localizedString = General.GetString("MODULE_MODULES"); modules.UpdateModuleDefinitions(new Guid(StrGuidModules), portalId, true); modules.AddModule( adminPageId, 1, StringsRightPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidModules)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // End Change [email protected] // Change by [email protected] // Add Signin Module and put it on the hometab // Signin localizedString = General.GetString("MODULE_LOGIN", "Login"); modules.UpdateModuleDefinitions(new Guid(StrGuidLogin), portalId, true); modules.AddModule( homePageId, -1, StrLeftPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidLogin)), 0, StrAdmins, "Unauthenticated Users;Admins;", StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Add language switcher to available modules // Language Switcher modules.UpdateModuleDefinitions(new Guid(StrGuidLanguageSwitcher), portalId, true); // End of change by [email protected] // Create paths this.CreatePortalPath(portalPath); return(portalId); }
private int CreatePortal(int templateID, string templateAlias, string portalAlias, string portalName, string portalPath) { int newPortalID; PortalsDB portals = new PortalsDB(); TabsDB tabs = new TabsDB(); ModulesDB modules = new ModulesDB(); UsersDB users = new UsersDB(); // create an Array to stores modules ID and GUID for finding them later ArrayList templateModules = new ArrayList(); moduleTemplate module; // create an Array to stores tabs ID for finding them later ArrayList templateTabs = new ArrayList(); tabTemplate tab; // Create a new portal newPortalID = portals.AddPortal(portalAlias, portalName, portalPath); // Open the connection to the PortalTemplates Database SqlConnection myConnection = GetConnection(); SqlConnection my2ndConnection = GetConnection(); SqlConnection my3rdConnection = GetConnection(); myConnection.Open(); my2ndConnection.Open(); my3rdConnection.Open(); // get module definitions and save them in the new portal SqlDataReader myReader = GetTemplateModuleDefinitions(templateID, myConnection); // Always call Read before accessing data. while (myReader.Read()) { module.id = (int)myReader["ModuleDefID"]; module.GuidID = GetGeneralModuleDefinitionByName(myReader["FriendlyName"].ToString(), my2ndConnection); try { // save module definitions in the new portal modules.UpdateModuleDefinitions(module.GuidID, newPortalID, true); // Save the modules into a list for finding them later templateModules.Add(module); } catch { // tried to add a Module thas doesn´t exists in this implementation of the portal } } myReader.Close(); if (!PortalSettings.UseSingleUserBase) { int roleID; int userID; int adminRoleID = 0; // get roles and save them in the new portal myReader = GetPortalRoles(templateID, myConnection); // Always call Read before accessing data. while (myReader.Read()) { roleID = users.AddRole(newPortalID, myReader["RoleName"].ToString()); if (myReader["RoleName"].ToString() == "Admins") { adminRoleID = roleID; } } myReader.Close(); // Create the "admin" User for the new portal string AdminEmail = "*****@*****.**"; userID = users.AddUser("admin", AdminEmail, "admin", newPortalID); // Create a new row in a many to many table (userroles) // giving the "admins" role to the "admin" user users.AddUserRole(adminRoleID, userID); } // Get all the Tabs in the Template Portal, store IDs in a list for finding them later // and create the Tabs in the new Portal myReader = GetTabsByPortal(templateID, myConnection); // Always call Read before accessing data. while (myReader.Read()) { // Save the tabs into a list for finding them later tab.oldID = (int)myReader["TabID"]; tab.newID = tabs.AddTab(newPortalID, myReader["TabName"].ToString(), Int32.Parse(myReader["TabOrder"].ToString())); templateTabs.Add(tab); } myReader.Close(); // now I have to get them again to set up the ParentID for each Tab myReader = GetTabsByPortal(templateID, myConnection); // Always call Read before accessing data. while (myReader.Read()) { // Find the news TabID and ParentTabID System.Collections.IEnumerator myEnumerator = templateTabs.GetEnumerator(); int newTabID = -1; int newParentTabID = -1; while (myEnumerator.MoveNext() && (newTabID == -1 || newParentTabID == -1)) { tab = (tabTemplate)myEnumerator.Current; if (tab.oldID == (int)myReader["TabID"]) { newTabID = tab.newID; } if (tab.oldID == Int32.Parse("0" + myReader["ParentTabID"])) { newParentTabID = tab.newID; } } if (newParentTabID == -1) { newParentTabID = 0; } // Update the Tab in the new portal tabs.UpdateTab(newPortalID, newTabID, newParentTabID, myReader["TabName"].ToString(), Int32.Parse(myReader["TabOrder"].ToString()), myReader["AuthorizedRoles"].ToString(), myReader["MobileTabName"].ToString(), (bool)myReader["ShowMobile"]); // Finally use GetPortalSettings to access each Tab and its Modules in the Template Portal // and create them in the new Portal SqlDataReader result; try { result = GetTabModules(Int32.Parse(myReader["TabID"].ToString()), my2ndConnection); object myValue; while (result.Read()) { ModuleSettings m = new ModuleSettings(); m.ModuleID = (int)result["ModuleID"]; m.ModuleDefID = (int)result["ModuleDefID"]; m.TabID = newTabID; m.PaneName = (string)result["PaneName"]; m.ModuleTitle = (string)result["ModuleTitle"]; myValue = result["AuthorizedEditRoles"]; m.AuthorizedEditRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["AuthorizedViewRoles"]; m.AuthorizedViewRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["AuthorizedAddRoles"]; m.AuthorizedAddRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["AuthorizedDeleteRoles"]; m.AuthorizedDeleteRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["AuthorizedPropertiesRoles"]; m.AuthorizedPropertiesRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["AuthorizedMoveModuleRoles"]; m.AuthorizedMoveModuleRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["AuthorizedDeleteModuleRoles"]; m.AuthorizedDeleteModuleRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["AuthorizedPublishingRoles"]; m.AuthorizedPublishingRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["SupportWorkflow"]; m.SupportWorkflow = !Convert.IsDBNull(myValue) ? (bool)myValue : false; myValue = result["AuthorizedApproveRoles"]; m.AuthorizedApproveRoles = !Convert.IsDBNull(myValue) ? (string)myValue : string.Empty; myValue = result["WorkflowState"]; m.WorkflowStatus = !Convert.IsDBNull(myValue) ? (WorkflowState)(0 + (byte)myValue) : WorkflowState.Original; try { myValue = result["SupportCollapsable"]; } catch { myValue = DBNull.Value; } m.SupportCollapsable = DBNull.Value != myValue ? (bool)myValue : false; try { myValue = result["ShowEveryWhere"]; } catch { myValue = DBNull.Value; } m.ShowEveryWhere = DBNull.Value != myValue ? (bool)myValue : false; m.CacheTime = int.Parse(result["CacheTime"].ToString()); m.ModuleOrder = int.Parse(result["ModuleOrder"].ToString()); myValue = result["ShowMobile"]; m.ShowMobile = !Convert.IsDBNull(myValue) ? (bool)myValue : false; // Find the new ModuleDefID assigned to the module in the new portal myEnumerator = templateModules.GetEnumerator(); int newModuleDefID = 0; while (myEnumerator.MoveNext() && newModuleDefID == 0) { module = (moduleTemplate)myEnumerator.Current; if (module.id == m.ModuleDefID) { newModuleDefID = modules.GetModuleDefinitionByGuid(newPortalID, module.GuidID); } } if (newModuleDefID > 0) { // add the module to the new tab int newModuleID = modules.AddModule(newTabID, m.ModuleOrder, m.PaneName, m.ModuleTitle, newModuleDefID, m.CacheTime, m.AuthorizedEditRoles, m.AuthorizedViewRoles, m.AuthorizedAddRoles, m.AuthorizedDeleteRoles, m.AuthorizedPropertiesRoles, m.AuthorizedMoveModuleRoles, m.AuthorizedDeleteModuleRoles, m.ShowMobile, m.AuthorizedPublishingRoles, m.SupportWorkflow, m.ShowEveryWhere, m.SupportCollapsable); // At the end, get all ModuleSettings and save them in the new module SqlDataReader dr = GetModuleSettings(m.ModuleID, my3rdConnection); while (dr.Read()) { ModuleSettings.UpdateModuleSetting(newModuleID, dr["SettingName"].ToString(), dr["SettingValue"].ToString()); } dr.Close(); } } result.Close(); } catch { // Error? ignore Tab ... } } myReader.Close(); // Set the CustomSettings of the New Portal based in the Template Portal myReader = GetPortalCustomSettings(templateID, myConnection); // Always call Read before accessing data. while (myReader.Read()) { PortalSettings.UpdatePortalSetting(newPortalID, myReader["SettingName"].ToString(), myReader["SettingValue"].ToString()); } myReader.Close(); // close the conections myConnection.Close(); myConnection.Dispose(); my2ndConnection.Close(); my2ndConnection.Dispose(); my3rdConnection.Close(); my3rdConnection.Dispose(); // Create paths portals.CreatePortalPath(portalPath); return(newPortalID); }
public int CreatePortal(int solutionID, string portalAlias, string portalName, string portalPath) { int portalID; PagesDB tabs = new PagesDB(); ModulesDB modules = new ModulesDB(); // Create a new portal portalID = AddPortal(portalAlias, portalName, portalPath); // get module definitions SqlDataReader myReader; myReader = modules.GetSolutionModuleDefinitions(solutionID); // Always call Read before accessing data. try { while (myReader.Read()) { modules.UpdateModuleDefinitions(new Guid(myReader["GeneralModDefID"].ToString()), portalID, true); } } finally { myReader.Close(); //by Manu, fixed bug 807858 } if (!Config.UseSingleUserBase) { string AdminEmail = "*****@*****.**"; // Create the stradmin User for the new portal UsersDB User = new UsersDB(); // Create the "Admins" role for the new portal Guid roleID = User.AddRole("Admins"); Guid userID = User.AddUser(stradmin, AdminEmail, stradmin); // Create a new row in a many to many table (userroles) // giving the "admins" role to the stradmin user User.AddUserRole(roleID, userID); } // Create a new Page "home" int homePageID = tabs.AddPage(portalID, "Home", 1); // Create a new Page "admin" string localizedString = General.GetString("ADMIN_TAB_NAME"); int adminPageID = tabs.AddPage(portalID, localizedString, strAdmins, 9999); // Add Modules for portal use // Html Document modules.UpdateModuleDefinitions(new Guid(strGUIDHTMLDocument), portalID, true); // Add Modules for portal administration // Site Settings (Admin) localizedString = General.GetString("MODULE_SITE_SETTINGS"); modules.UpdateModuleDefinitions(new Guid(strGUIDSiteSettings), portalID, true); modules.AddModule(adminPageID, 1, strContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalID, new Guid(strGUIDSiteSettings)), 0, strAdmins, strAllUsers, strAdmins, strAdmins, strAdmins, strAdmins, strAdmins, false, string.Empty, false, false, false); // Pages (Admin) localizedString = General.GetString("MODULE_TABS"); modules.UpdateModuleDefinitions(new Guid(strGUIDPages), portalID, true); modules.AddModule(adminPageID, 2, strContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalID, new Guid(strGUIDPages)), 0, strAdmins, strAllUsers, strAdmins, strAdmins, strAdmins, strAdmins, strAdmins, false, string.Empty, false, false, false); // Roles (Admin) localizedString = General.GetString("MODULE_SECURITY_ROLES"); modules.UpdateModuleDefinitions(new Guid(strGUIDSecurityRoles), portalID, true); modules.AddModule(adminPageID, 3, strContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalID, new Guid(strGUIDSecurityRoles)), 0, strAdmins, strAllUsers, strAdmins, strAdmins, strAdmins, strAdmins, strAdmins, false, string.Empty, false, false, false); // Manage Users (Admin) localizedString = General.GetString("MODULE_MANAGE_USERS"); modules.UpdateModuleDefinitions(new Guid(strGUIDManageUsers), portalID, true); modules.AddModule(adminPageID, 4, strContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalID, new Guid(strGUIDManageUsers)), 0, strAdmins, strAllUsers, strAdmins, strAdmins, strAdmins, strAdmins, strAdmins, false, string.Empty, false, false, false); // Module Definitions (Admin) localizedString = General.GetString("MODULE_MODULES"); modules.UpdateModuleDefinitions(new Guid(strGUIDModules), portalID, true); modules.AddModule(adminPageID, 1, strRightPane, localizedString, modules.GetModuleDefinitionByGuid(portalID, new Guid(strGUIDModules)), 0, strAdmins, strAllUsers, strAdmins, strAdmins, strAdmins, strAdmins, strAdmins, false, string.Empty, false, false, false); // End Change [email protected] // Change by [email protected] // Add Signin Module and put it on the hometab // Signin localizedString = General.GetString("MODULE_LOGIN", "Login"); modules.UpdateModuleDefinitions(new Guid(strGUIDLogin), portalID, true); modules.AddModule(homePageID, -1, strLeftPane, localizedString, modules.GetModuleDefinitionByGuid(portalID, new Guid(strGUIDLogin)), 0, strAdmins, "Unauthenticated Users;Admins;", strAdmins, strAdmins, strAdmins, strAdmins, strAdmins, false, string.Empty, false, false, false); // Add language switcher to available modules // Language Switcher modules.UpdateModuleDefinitions(new Guid(strGUIDLanguageSwitcher), portalID, true); // End of change by [email protected] // Create paths CreatePortalPath(portalPath); return(portalID); }