DECLARE @DisableAnalytics BIT = 0 -- 1 to disable Site Anaytics, 0 to leave enabled
DECLARE @DisableLiquidContent BIT = 1 -- 1 to disable Liquid Content, 0 to leave enabled
DECLARE @DisableFormBuilder BIT = 1 -- 1 to disable Form Builder, 0 to leave enabled
DECLARE @PortalId INT = NULL -- Specify a Portal ID, leave null to disable all portals




IF @DisableAnalytics = 1
BEGIN
	IF @PortalId IS NULL
	BEGIN
		UPDATE HostSettings SET SettingValue = 'False' WHERE SettingName = 'AnalyticsEnabled'
		UPDATE PortalSettings SET SettingValue = 'False' WHERE SettingName = 'AnalyticsEnabled'
		DELETE FROM PortalSettings WHERE SettingName IN ('AnalyticsAccountCode', 'AnalyticsClientCredentials')
	END
	ELSE
	BEGIN
		UPDATE PortalSettings SET SettingValue = 'False' WHERE SettingName = 'AnalyticsEnabled' AND PortalID = @PortalId
		DELETE FROM PortalSettings WHERE SettingName IN ('AnalyticsAccountCode', 'AnalyticsClientCredentials') AND PortalID = @PortalId
	END
END
IF @DisableLiquidContent = 1
BEGIN
	IF @PortalId IS NULL
	BEGIN
		UPDATE HostSettings SET SettingValue = 'False' WHERE SettingName = 'StructuredContentEnabled'
		UPDATE PortalSettings SET SettingValue = 'False' WHERE SettingName = 'StructuredContentEnabled'
		DELETE FROM PortalSettings WHERE SettingName = 'StructuredContentClientCredentials'
	END
	ELSE
	BEGIN
		UPDATE PortalSettings SET SettingValue = 'False' WHERE SettingName = 'StructuredContentEnabled' AND PortalID = @PortalId
		DELETE FROM PortalSettings WHERE SettingName = 'StructuredContentClientCredentials' AND PortalID = @PortalId
	END
END
IF @DisableFormBuilder = 1
BEGIN
	IF @PortalId IS NULL
	BEGIN
		UPDATE HostSettings SET SettingValue = 'False' WHERE SettingName = 'FormBuilderEnabled'
		UPDATE PortalSettings SET SettingValue = 'False' WHERE SettingName = 'FormBuilderEnabled'
		DELETE FROM PortalSettings WHERE SettingName = 'FormBuilderClientCredentials'
	END
	ELSE
	BEGIN
		UPDATE PortalSettings SET SettingValue = 'False' WHERE SettingName = 'FormBuilderEnabled' AND PortalID = @PortalId
		DELETE FROM PortalSettings WHERE SettingName = 'FormBuilderClientCredentials' AND PortalID = @PortalId
	END
END

