317 lines
8 KiB
Transact-SQL
317 lines
8 KiB
Transact-SQL
USE [${install.database}]
|
|
GO
|
|
|
|
-- update database version
|
|
DECLARE @build_version nvarchar(10), @build_date datetime
|
|
SET @build_version = N'${release.version}'
|
|
SET @build_date = '${release.date}T00:00:00' -- ISO 8601 Format (YYYY-MM-DDTHH:MM:SS)
|
|
|
|
IF NOT EXISTS (SELECT * FROM [dbo].[Versions] WHERE [DatabaseVersion] = @build_version)
|
|
BEGIN
|
|
INSERT [dbo].[Versions] ([DatabaseVersion], [BuildDate]) VALUES (@build_version, @build_date)
|
|
END
|
|
GO
|
|
|
|
-- Version 2.1 section
|
|
IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [DisplayName] = 'Hosted Microsoft Exchange Server 2013')
|
|
BEGIN
|
|
INSERT [dbo].[Providers] ([ProviderId], [GroupId], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES(91, 12, N'Exchange2013', N'Hosted Microsoft Exchange Server 2013', N'WebsitePanel.Providers.HostedSolution.Exchange2013, WebsitePanel.Providers.HostedSolution.Exchange2013', N'Exchange', 1)
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
UPDATE [dbo].[Providers] SET [DisableAutoDiscovery] = NULL WHERE [DisplayName] = 'Hosted Microsoft Exchange Server 2013'
|
|
END
|
|
GO
|
|
|
|
|
|
IF NOT EXISTS (SELECT * FROM [dbo].[Quotas] WHERE [QuotaName] = 'Exchange2007.AllowLitigationHold')
|
|
DELETE FROM HostingPlanQuotas WHERE QuotaID = 340
|
|
GO
|
|
DELETE FROM HostingPlanQuotas WHERE QuotaID = 341
|
|
GO
|
|
DELETE FROM HostingPlanQuotas WHERE QuotaID = 342
|
|
GO
|
|
DELETE FROM HostingPlanQuotas WHERE QuotaID = 343
|
|
GO
|
|
DELETE FROM HostingPlanResources WHERE GroupID = 33
|
|
GO
|
|
BEGIN
|
|
INSERT [dbo].[Quotas] ([QuotaID], [GroupID],[QuotaOrder], [QuotaName], [QuotaDescription], [QuotaTypeID], [ServiceQuota], [ItemTypeID]) VALUES (420, 12, 24,N'Exchange2007.AllowLitigationHold',N'Allow Litigation Hold',1, 0 , NULL)
|
|
END
|
|
GO
|
|
|
|
|
|
IF NOT EXISTS (SELECT * FROM [dbo].[Quotas] WHERE [QuotaName] = 'Exchange2007.RecoverableItemsSpace')
|
|
BEGIN
|
|
INSERT [dbo].[Quotas] ([QuotaID], [GroupID],[QuotaOrder], [QuotaName], [QuotaDescription], [QuotaTypeID], [ServiceQuota], [ItemTypeID]) VALUES (421, 12, 25,N'Exchange2007.RecoverableItemsSpace',N'Recoverable Items Space',2, 0 , NULL)
|
|
END
|
|
GO
|
|
|
|
|
|
|
|
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='ExchangeMailboxPlans' AND COLS.name='AllowLitigationHold')
|
|
BEGIN
|
|
ALTER TABLE [dbo].[ExchangeMailboxPlans] ADD
|
|
[AllowLitigationHold] [bit] NULL,
|
|
[RecoverableItemsWarningPct] [int] NULL,
|
|
[RecoverableItemsSpace] [int] NULL
|
|
END
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
ALTER PROCEDURE [dbo].[AddExchangeMailboxPlan]
|
|
(
|
|
@MailboxPlanId int OUTPUT,
|
|
@ItemID int,
|
|
@MailboxPlan nvarchar(300),
|
|
@EnableActiveSync bit,
|
|
@EnableIMAP bit,
|
|
@EnableMAPI bit,
|
|
@EnableOWA bit,
|
|
@EnablePOP bit,
|
|
@IsDefault bit,
|
|
@IssueWarningPct int,
|
|
@KeepDeletedItemsDays int,
|
|
@MailboxSizeMB int,
|
|
@MaxReceiveMessageSizeKB int,
|
|
@MaxRecipients int,
|
|
@MaxSendMessageSizeKB int,
|
|
@ProhibitSendPct int,
|
|
@ProhibitSendReceivePct int ,
|
|
@HideFromAddressBook bit,
|
|
@MailboxPlanType int,
|
|
@AllowLitigationHold bit,
|
|
@RecoverableItemsWarningPct int,
|
|
@RecoverableItemsSpace int
|
|
)
|
|
AS
|
|
|
|
IF (((SELECT Count(*) FROM ExchangeMailboxPlans WHERE ItemId = @ItemID) = 0) AND (@MailboxPlanType=0))
|
|
BEGIN
|
|
SET @IsDefault = 1
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
IF ((@IsDefault = 1) AND (@MailboxPlanType=0))
|
|
BEGIN
|
|
UPDATE ExchangeMailboxPlans SET IsDefault = 0 WHERE ItemID = @ItemID
|
|
END
|
|
END
|
|
|
|
INSERT INTO ExchangeMailboxPlans
|
|
(
|
|
ItemID,
|
|
MailboxPlan,
|
|
EnableActiveSync,
|
|
EnableIMAP,
|
|
EnableMAPI,
|
|
EnableOWA,
|
|
EnablePOP,
|
|
IsDefault,
|
|
IssueWarningPct,
|
|
KeepDeletedItemsDays,
|
|
MailboxSizeMB,
|
|
MaxReceiveMessageSizeKB,
|
|
MaxRecipients,
|
|
MaxSendMessageSizeKB,
|
|
ProhibitSendPct,
|
|
ProhibitSendReceivePct,
|
|
HideFromAddressBook,
|
|
MailboxPlanType,
|
|
AllowLitigationHold,
|
|
RecoverableItemsWarningPct,
|
|
RecoverableItemsSpace
|
|
)
|
|
VALUES
|
|
(
|
|
@ItemID,
|
|
@MailboxPlan,
|
|
@EnableActiveSync,
|
|
@EnableIMAP,
|
|
@EnableMAPI,
|
|
@EnableOWA,
|
|
@EnablePOP,
|
|
@IsDefault,
|
|
@IssueWarningPct,
|
|
@KeepDeletedItemsDays,
|
|
@MailboxSizeMB,
|
|
@MaxReceiveMessageSizeKB,
|
|
@MaxRecipients,
|
|
@MaxSendMessageSizeKB,
|
|
@ProhibitSendPct,
|
|
@ProhibitSendReceivePct,
|
|
@HideFromAddressBook,
|
|
@MailboxPlanType,
|
|
@AllowLitigationHold,
|
|
@RecoverableItemsWarningPct,
|
|
@RecoverableItemsSpace
|
|
)
|
|
|
|
SET @MailboxPlanId = SCOPE_IDENTITY()
|
|
|
|
RETURN
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ALTER PROCEDURE [dbo].[UpdateExchangeMailboxPlan]
|
|
(
|
|
@MailboxPlanId int,
|
|
@MailboxPlan nvarchar(300),
|
|
@EnableActiveSync bit,
|
|
@EnableIMAP bit,
|
|
@EnableMAPI bit,
|
|
@EnableOWA bit,
|
|
@EnablePOP bit,
|
|
@IsDefault bit,
|
|
@IssueWarningPct int,
|
|
@KeepDeletedItemsDays int,
|
|
@MailboxSizeMB int,
|
|
@MaxReceiveMessageSizeKB int,
|
|
@MaxRecipients int,
|
|
@MaxSendMessageSizeKB int,
|
|
@ProhibitSendPct int,
|
|
@ProhibitSendReceivePct int ,
|
|
@HideFromAddressBook bit,
|
|
@MailboxPlanType int,
|
|
@AllowLitigationHold bit,
|
|
@RecoverableItemsWarningPct int,
|
|
@RecoverableItemsSpace int
|
|
)
|
|
AS
|
|
|
|
UPDATE ExchangeMailboxPlans SET
|
|
MailboxPlan = @MailboxPlan,
|
|
EnableActiveSync = @EnableActiveSync,
|
|
EnableIMAP = @EnableIMAP,
|
|
EnableMAPI = @EnableMAPI,
|
|
EnableOWA = @EnableOWA,
|
|
EnablePOP = @EnablePOP,
|
|
IsDefault = @IsDefault,
|
|
IssueWarningPct= @IssueWarningPct,
|
|
KeepDeletedItemsDays = @KeepDeletedItemsDays,
|
|
MailboxSizeMB= @MailboxSizeMB,
|
|
MaxReceiveMessageSizeKB= @MaxReceiveMessageSizeKB,
|
|
MaxRecipients= @MaxRecipients,
|
|
MaxSendMessageSizeKB= @MaxSendMessageSizeKB,
|
|
ProhibitSendPct= @ProhibitSendPct,
|
|
ProhibitSendReceivePct = @ProhibitSendReceivePct,
|
|
HideFromAddressBook = @HideFromAddressBook,
|
|
MailboxPlanType = @MailboxPlanType,
|
|
AllowLitigationHold = @AllowLitigationHold,
|
|
RecoverableItemsWarningPct = @RecoverableItemsWarningPct,
|
|
RecoverableItemsSpace = @RecoverableItemsSpace
|
|
WHERE MailboxPlanId = @MailboxPlanId
|
|
|
|
RETURN
|
|
UPDATE Domains SET IsDomainPointer=0, DomainItemID=NULL WHERE MailDomainID IS NOT NULL AND isDomainPointer=1
|
|
|
|
GO
|
|
|
|
|
|
ALTER PROCEDURE [dbo].[GetPackageQuotas]
|
|
(
|
|
@ActorID int,
|
|
@PackageID int
|
|
)
|
|
AS
|
|
|
|
-- check rights
|
|
IF dbo.CheckActorPackageRights(@ActorID, @PackageID) = 0
|
|
RAISERROR('You are not allowed to access this package', 16, 1)
|
|
|
|
DECLARE @PlanID int, @ParentPackageID int
|
|
SELECT @PlanID = PlanID, @ParentPackageID = ParentPackageID FROM Packages
|
|
WHERE PackageID = @PackageID
|
|
|
|
-- get resource groups
|
|
SELECT
|
|
RG.GroupID,
|
|
RG.GroupName,
|
|
ISNULL(HPR.CalculateDiskSpace, 0) AS CalculateDiskSpace,
|
|
ISNULL(HPR.CalculateBandwidth, 0) AS CalculateBandwidth,
|
|
dbo.GetPackageAllocatedResource(@ParentPackageID, RG.GroupID, 0) AS ParentEnabled
|
|
FROM ResourceGroups AS RG
|
|
LEFT OUTER JOIN HostingPlanResources AS HPR ON RG.GroupID = HPR.GroupID AND HPR.PlanID = @PlanID
|
|
WHERE dbo.GetPackageAllocatedResource(@PackageID, RG.GroupID, 0) = 1
|
|
ORDER BY RG.GroupOrder
|
|
|
|
|
|
-- return quotas
|
|
SELECT
|
|
Q.QuotaID,
|
|
Q.GroupID,
|
|
Q.QuotaName,
|
|
Q.QuotaDescription,
|
|
Q.QuotaTypeID,
|
|
dbo.GetPackageAllocatedQuota(@PackageID, Q.QuotaID) AS QuotaValue,
|
|
dbo.GetPackageAllocatedQuota(@ParentPackageID, Q.QuotaID) AS ParentQuotaValue,
|
|
ISNULL(dbo.CalculateQuotaUsage(@PackageID, Q.QuotaID), 0) AS QuotaUsedValue
|
|
FROM Quotas AS Q
|
|
WHERE Q.HideQuota IS NULL OR Q.HideQuota = 0
|
|
ORDER BY Q.QuotaOrder
|
|
RETURN
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ALTER PROCEDURE [dbo].[UpdateServiceProperties]
|
|
(
|
|
@ServiceID int,
|
|
@Xml ntext
|
|
)
|
|
AS
|
|
|
|
-- delete old properties
|
|
BEGIN TRAN
|
|
DECLARE @idoc int
|
|
--Create an internal representation of the XML document.
|
|
EXEC sp_xml_preparedocument @idoc OUTPUT, @xml
|
|
|
|
-- Execute a SELECT statement that uses the OPENXML rowset provider.
|
|
DELETE FROM ServiceProperties
|
|
WHERE ServiceID = @ServiceID
|
|
AND PropertyName COLLATE Latin1_General_CI_AS IN
|
|
(
|
|
SELECT PropertyName
|
|
FROM OPENXML(@idoc, '/properties/property', 1)
|
|
WITH (PropertyName nvarchar(50) '@name')
|
|
)
|
|
|
|
INSERT INTO ServiceProperties
|
|
(
|
|
ServiceID,
|
|
PropertyName,
|
|
PropertyValue
|
|
)
|
|
SELECT
|
|
@ServiceID,
|
|
PropertyName,
|
|
PropertyValue
|
|
FROM OPENXML(@idoc, '/properties/property',1) WITH
|
|
(
|
|
PropertyName nvarchar(50) '@name',
|
|
PropertyValue nvarchar(1000) '@value'
|
|
) as PV
|
|
|
|
-- remove document
|
|
exec sp_xml_removedocument @idoc
|
|
|
|
COMMIT TRAN
|
|
RETURN
|
|
GO
|
|
|