From cc6277c8d74d66ba4e855f6b4cc128a5ca217a29 Mon Sep 17 00:00:00 2001 From: robvde Date: Thu, 18 Oct 2012 09:37:39 +0400 Subject: [PATCH] Fixed: DomainItemId field added to the Domains table to register the relationship between a domain pointer and domain. Updated depended procedures and methods --- WebsitePanel/Database/update_db.sql | 237 ++++++++++++------ .../Servers/DomainInfo.cs | 8 + .../Code/Data/DataProvider.cs | 14 +- .../Code/Servers/ServerController.cs | 32 ++- .../Code/WebServers/WebServerController.cs | 2 + 5 files changed, 212 insertions(+), 81 deletions(-) diff --git a/WebsitePanel/Database/update_db.sql b/WebsitePanel/Database/update_db.sql index 919aa5d9..f5a5317d 100644 --- a/WebsitePanel/Database/update_db.sql +++ b/WebsitePanel/Database/update_db.sql @@ -5856,7 +5856,101 @@ END GO -IF NOT EXISTS (SELECT * FROM sys.objects WHERE type_desc = N'SQL_STORED_PROCEDURE' AND name = N'GetExchangeOrganization') + + + + + + + + + + + + + + + + + +IF NOT EXISTS(select 1 from sys.columns COLS INNER JOIN sys.objects OBJS ON OBJS.object_id=COLS.object_id and OBJS.type='U' AND OBJS.name='Domains' AND COLS.name='DomainItemId') +BEGIN +ALTER TABLE [dbo].[Domains] ADD + [DomainItemId] [int] NULL +END +GO + + + + + +BEGIN TRAN +CREATE TABLE #TempDomains +( + [PackageID] [int] NOT NULL, + [ZoneItemID] [int] NULL, + [DomainName] [nvarchar](100) COLLATE Latin1_General_CI_AS NOT NULL, + [HostingAllowed] [bit] NOT NULL, + [WebSiteID] [int] NULL, + [IsSubDomain] [bit] NOT NULL, + [IsInstantAlias] [bit] NOT NULL, + [IsDomainPointer] [bit] NOT NULL, + [DomainItemID] [int] NULL, +) + +UPDATE Domains SET DomainItemID = DomainID + +INSERT INTO #TempDomains SELECT PackageID, +ZoneItemID, +DomainName, +HostingAllowed, +WebSiteID, +IsSubDomain, +IsInstantAlias, +IsDomainPointer, +DomainItemID FROM Domains WHERE IsDomainPointer = 1 + + +UPDATE Domains SET IsDomainPointer=0,WebSiteID=NULL, DomainItemID=NULL WHERE IsDomainPointer = 1 AND DomainName IN (SELECT DomainName FROM Domains AS D WHERE +D.DomainName = (SELECT DISTINCT ItemName FROM ServiceItems WHERE ItemID = D.ZoneItemId ) +Group BY DOmainName +HAVING (COUNT(DomainName) = 1)) + + +INSERT INTO Domains SELECT PackageID, +ZoneItemID, +DomainName, +HostingAllowed, +WebSiteID, +NULL, +IsSubDomain, +IsInstantAlias, +IsDomainPointer, +DomainItemID + FROM #TempDomains As T WHERE DomainName IN (SELECT DomainName FROM Domains AS D WHERE +D.DomainName = (SELECT DISTINCT ItemName FROM ServiceItems WHERE ItemID = D.ZoneItemId ) +Group BY DOmainName +HAVING (COUNT(DomainName) = 1)) + + +UPDATE Domains SET DomainItemID = null WHERE IsDomainPointer=0 + +DROP TABLE #TempDomains +COMMIT TRAN +GO + + + +IF NOT EXISTS (SELECT * FROM [dbo].[Quotas] WHERE [QuotaName] = 'Web.EnableHostNameSupport') +BEGIN + INSERT [dbo].[Quotas] ([QuotaID], [GroupID], [QuotaOrder], [QuotaName], [QuotaDescription], [QuotaTypeID], [ServiceQuota], [ItemTypeID]) VALUES (334, 2, 23, N'Web.EnableHostNameSupport', N'Enable Hostname Support', 1, 0, NULL) +END +GO + + + + +IF NOT EXISTS (SELECT * FROM sys.objects WHERE type_desc = N'SQL_STORED_PROCEDURE' AND name = N'GetDomainByNameByPointer') BEGIN EXEC sp_executesql N'CREATE PROCEDURE [dbo].[GetDomainByNameByPointer] ( @@ -5897,76 +5991,79 @@ GO - - - - - - - - - - - - - - - - - -BEGIN TRAN -CREATE TABLE #TempDomains -( - [PackageID] [int] NOT NULL, - [ZoneItemID] [int] NULL, - [DomainName] [nvarchar](100) COLLATE Latin1_General_CI_AS NOT NULL, - [HostingAllowed] [bit] NOT NULL, - [WebSiteID] [int] NULL, - [IsSubDomain] [bit] NOT NULL, - [IsInstantAlias] [bit] NOT NULL, - [IsDomainPointer] [bit] NOT NULL, -) - - -INSERT INTO #TempDomains SELECT PackageID, -ZoneItemID, -DomainName, -HostingAllowed, -WebSiteID, -IsSubDomain, -IsInstantAlias, -IsDomainPointer FROM Domains WHERE IsDomainPointer = 1 - - -UPDATE Domains SET IsDomainPointer=0,WebSiteID=NULL WHERE IsDomainPointer = 1 AND DomainName IN (SELECT DomainName FROM Domains AS D WHERE -D.DomainName = (SELECT DISTINCT ItemName FROM ServiceItems WHERE ItemID = D.ZoneItemId ) -Group BY DOmainName -HAVING (COUNT(DomainName) = 1)) - - -INSERT INTO Domains SELECT PackageID, -ZoneItemID, -DomainName, -HostingAllowed, -WebSiteID, -NULL, -IsSubDomain, -IsInstantAlias, -IsDomainPointer - FROM #TempDomains As T WHERE DomainName IN (SELECT DomainName FROM Domains AS D WHERE -D.DomainName = (SELECT DISTINCT ItemName FROM ServiceItems WHERE ItemID = D.ZoneItemId ) -Group BY DOmainName -HAVING (COUNT(DomainName) = 1)) - -DROP TABLE #TempDomains -COMMIT TRAN -GO - - - -IF NOT EXISTS (SELECT * FROM [dbo].[Quotas] WHERE [QuotaName] = 'Web.EnableHostNameSupport') +IF NOT EXISTS (SELECT * FROM sys.objects WHERE type_desc = N'SQL_STORED_PROCEDURE' AND name = N'GetDomainsByDomainItemID') BEGIN - INSERT [dbo].[Quotas] ([QuotaID], [GroupID], [QuotaOrder], [QuotaName], [QuotaDescription], [QuotaTypeID], [ServiceQuota], [ItemTypeID]) VALUES (334, 2, 23, N'Web.EnableHostNameSupport', N'Enable Hostname Support', 1, 0, NULL) +EXEC sp_executesql N'CREATE PROCEDURE [dbo].[GetDomainsByDomainItemID] +( + @ActorID int, + @DomainID int +) +AS + +SELECT + D.DomainID, + D.PackageID, + D.ZoneItemID, + D.DomainItemID, + D.DomainName, + D.HostingAllowed, + ISNULL(D.WebSiteID, 0) AS WebSiteID, + WS.ItemName AS WebSiteName, + ISNULL(D.MailDomainID, 0) AS MailDomainID, + MD.ItemName AS MailDomainName, + Z.ItemName AS ZoneName, + D.IsSubDomain, + D.IsInstantAlias, + D.IsDomainPointer +FROM Domains AS D +INNER JOIN Packages AS P ON D.PackageID = P.PackageID +LEFT OUTER JOIN ServiceItems AS WS ON D.WebSiteID = WS.ItemID +LEFT OUTER JOIN ServiceItems AS MD ON D.MailDomainID = MD.ItemID +LEFT OUTER JOIN ServiceItems AS Z ON D.ZoneItemID = Z.ItemID +WHERE + D.DomainItemID = @DomainID + AND dbo.CheckActorPackageRights(@ActorID, P.PackageID) = 1 +RETURN' END GO + + + + +ALTER PROCEDURE [dbo].[UpdateDomain] +( + @DomainID int, + @ActorID int, + @ZoneItemID int, + @HostingAllowed bit, + @WebSiteID int, + @MailDomainID int, + @DomainItemID int +) +AS + +-- check rights +DECLARE @PackageID int +SELECT @PackageID = PackageID FROM Domains +WHERE DomainID = @DomainID + +IF dbo.CheckActorPackageRights(@ActorID, @PackageID) = 0 +RAISERROR('You are not allowed to access this package', 16, 1) + +IF @ZoneItemID = 0 SET @ZoneItemID = NULL +IF @WebSiteID = 0 SET @WebSiteID = NULL +IF @MailDomainID = 0 SET @MailDomainID = NULL + +-- update record +UPDATE Domains +SET + ZoneItemID = @ZoneItemID, + HostingAllowed = @HostingAllowed, + WebSiteID = @WebSiteID, + MailDomainID = @MailDomainID, + DomainItemID = @DomainItemID +WHERE + DomainID = @DomainID + RETURN +GO \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Servers/DomainInfo.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Servers/DomainInfo.cs index cd716b2c..eef37219 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Servers/DomainInfo.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Servers/DomainInfo.cs @@ -36,6 +36,7 @@ namespace WebsitePanel.EnterpriseServer private int domainId; private int packageId; private int zoneItemId; + private int domainItemId; private string domainName; private bool hostingAllowed; private int webSiteId; @@ -68,6 +69,13 @@ namespace WebsitePanel.EnterpriseServer set { zoneItemId = value; } } + public int DomainItemId + { + get { return domainItemId; } + set { domainItemId = value; } + } + + public string DomainName { get { return domainName; } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Data/DataProvider.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Data/DataProvider.cs index 648e387f..2673bc80 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Data/DataProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Data/DataProvider.cs @@ -811,6 +811,15 @@ namespace WebsitePanel.EnterpriseServer new SqlParameter("@ZoneID", zoneId)); } + public static DataSet GetDomainsByDomainItemId(int actorId, int domainId) + { + return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure, + ObjectQualifier + "GetDomainsByDomainItemId", + new SqlParameter("@ActorId", actorId), + new SqlParameter("@DomainID", domainId)); + } + + public static int CheckDomain(int packageId, string domainName, bool isDomainPointer) { @@ -851,7 +860,7 @@ namespace WebsitePanel.EnterpriseServer } public static void UpdateDomain(int actorId, int domainId, int zoneItemId, - bool hostingAllowed, int webSiteId, int mailDomainId) + bool hostingAllowed, int webSiteId, int mailDomainId, int domainItemId) { SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, ObjectQualifier + "UpdateDomain", @@ -860,7 +869,8 @@ namespace WebsitePanel.EnterpriseServer new SqlParameter("@ZoneItemId", zoneItemId), new SqlParameter("@HostingAllowed", hostingAllowed), new SqlParameter("@WebSiteId", webSiteId), - new SqlParameter("@MailDomainId", mailDomainId)); + new SqlParameter("@MailDomainId", mailDomainId), + new SqlParameter("@DomainItemId", domainItemId)); } public static void DeleteDomain(int actorId, int domainId) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Servers/ServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Servers/ServerController.cs index 9d4afd59..b7c1e49c 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Servers/ServerController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/Servers/ServerController.cs @@ -1609,7 +1609,14 @@ namespace WebsitePanel.EnterpriseServer return ObjectUtils.CreateListFromDataSet( DataProvider.GetDomainsByZoneId(SecurityContext.User.UserId, zoneId)); } - + + public static List GetDomainsByDomainItemId(int zoneId) + { + return ObjectUtils.CreateListFromDataSet( + DataProvider.GetDomainsByDomainItemId(SecurityContext.User.UserId, zoneId)); + } + + public static List GetMyDomains(int packageId) { return ObjectUtils.CreateListFromDataSet( @@ -1908,7 +1915,7 @@ namespace WebsitePanel.EnterpriseServer { DataProvider.UpdateDomain(SecurityContext.User.UserId, domain.DomainId, domain.ZoneItemId, domain.HostingAllowed, domain.WebSiteId, - domain.MailDomainId); + domain.MailDomainId, domain.DomainItemId); return 0; } @@ -1959,7 +1966,7 @@ namespace WebsitePanel.EnterpriseServer } - List domains = GetDomainsByZoneId(domain.ZoneItemId); + List domains = GetDomainsByDomainItemId(domain.DomainId); foreach (DomainInfo d in domains) { if (d.WebSiteId > 0) @@ -2030,7 +2037,7 @@ namespace WebsitePanel.EnterpriseServer if (!domain.IsDomainPointer) { - List domains = GetDomainsByZoneId(domain.ZoneItemId); + List domains = GetDomainsByDomainItemId(domain.DomainId); foreach (DomainInfo d in domains) { if (d.WebSiteId > 0) @@ -2218,16 +2225,22 @@ namespace WebsitePanel.EnterpriseServer instantAlias = GetDomainItem(instantAliasId); } + if (domain.WebSiteId > 0) + { + WebServerController.AddWebSitePointer(domain.WebSiteId, + (domain.DomainName.Replace("." + domain.ZoneName, "") == domain.ZoneName) ? "" : domain.DomainName.Replace("." + domain.ZoneName, ""), + instantAlias.DomainId); + } + + // add web site pointer if required - List domains = GetDomainsByZoneId(domain.ZoneItemId); + List domains = GetDomainsByDomainItemId(domain.DomainId); foreach (DomainInfo d in domains) { if (d.WebSiteId > 0) { - WebSite w = WebServerController.GetWebSite(d.WebSiteId); - WebServerController.AddWebSitePointer(d.WebSiteId, - (w.Name.Replace("." + domain.ZoneName, "") == domain.ZoneName) ? "" : w.Name.Replace("." + domain.ZoneName, ""), + (d.DomainName.Replace("." + domain.ZoneName, "") == domain.ZoneName) ? "" : d.DomainName.Replace("." + domain.ZoneName, ""), instantAlias.DomainId); } @@ -2283,7 +2296,8 @@ namespace WebsitePanel.EnterpriseServer return webRes; } - List domains = GetDomainsByZoneId(instantAlias.ZoneItemId); + List domains = GetDomainsByDomainItemId(instantAlias.DomainId); + foreach (DomainInfo d in domains) { if (d.WebSiteId > 0) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/WebServers/WebServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/WebServers/WebServerController.cs index 8f5e439e..26066feb 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/WebServers/WebServerController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/WebServers/WebServerController.cs @@ -1170,6 +1170,8 @@ namespace WebsitePanel.EnterpriseServer { domainTmp.WebSiteId = siteItemId; domainTmp.ZoneItemId = domain.ZoneItemId; + domainTmp.DomainItemId = domainId; + ServerController.UpdateDomain(domainTmp); } }