diff --git a/Dnn.CommunityForums/Controllers/ForumController.cs b/Dnn.CommunityForums/Controllers/ForumController.cs index cca1ee9e7..376398f1e 100644 --- a/Dnn.CommunityForums/Controllers/ForumController.cs +++ b/Dnn.CommunityForums/Controllers/ForumController.cs @@ -242,7 +242,7 @@ public int Forums_Save(int portalId, DotNetNuke.Modules.ActiveForums.Entities.Fo { DataContext.Instance().Execute(System.Data.CommandType.Text, "DELETE FROM {databaseOwner}{objectQualifier}activeforums_Settings WHERE ModuleId = @0 AND GroupKey = @1", fi.ModuleId, $"F:{fi.ForumID}"); } - + // for new forum not using group features, set defaults if (isNew && useGroupFeatures == false) { @@ -260,14 +260,17 @@ public int Forums_Save(int portalId, DotNetNuke.Modules.ActiveForums.Entities.Fo // Clear the caches DotNetNuke.Modules.ActiveForums.DataCache.ClearSettingsCache(fi.ModuleId); return forumId; - } + } + + [Obsolete("Deprecated in Community Forums. Removed in 10.00.00. Not Used.")] + public void Forums_Delete(int portalId, int forumId, int moduleId) => Forums_Delete(forumId: forumId, moduleId: moduleId) - public void Forums_Delete(int portalId, int forumId, int moduleId) + internal void Forums_Delete(int forumId, int moduleId) { var parentForumId = this.GetById(forumId, moduleId).ParentForumId; new DotNetNuke.Modules.ActiveForums.Controllers.ForumTopicController().DeleteForForum(forumId); new DotNetNuke.Modules.ActiveForums.Controllers.SubscriptionController().DeleteForForum(forumId); - base.DeleteById(forumId); + this.DeleteById(forumId); DataContext.Instance().Execute(System.Data.CommandType.StoredProcedure, "{databaseOwner}{objectQualifier}activeforums_Forums_RepairSort", forumId, parentForumId); DotNetNuke.Modules.ActiveForums.DataCache.ClearSettingsCache(moduleId); } diff --git a/Dnn.CommunityForums/Controllers/ForumGroupController.cs b/Dnn.CommunityForums/Controllers/ForumGroupController.cs index 82220e840..b1a598d27 100644 --- a/Dnn.CommunityForums/Controllers/ForumGroupController.cs +++ b/Dnn.CommunityForums/Controllers/ForumGroupController.cs @@ -18,6 +18,8 @@ // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System.Linq; + namespace DotNetNuke.Modules.ActiveForums.Controllers { using System.Collections; @@ -49,21 +51,27 @@ public int Groups_Save(int portalId, DotNetNuke.Modules.ActiveForums.Entities.Fo if (forumGroupInfo.PermissionsId == -1) { forumGroupInfo.PermissionsId = new DotNetNuke.Modules.ActiveForums.Controllers.PermissionController().CreateAdminPermissions(DotNetNuke.Modules.ActiveForums.Controllers.PermissionController.GetAdministratorsRoleId(portalId).ToString(), forumGroupInfo.ModuleId).PermissionsId; + DotNetNuke.Modules.ActiveForums.Controllers.PermissionController.CreateDefaultSets(portalId, forumGroupInfo.ModuleId, forumGroupInfo.PermissionsId); + } + + if (string.IsNullOrEmpty(forumGroupInfo.GroupSettingsKey)) + { + forumGroupInfo.GroupSettingsKey = $"G:{forumGroupInfo.ForumGroupId}"; } // TODO: When these methods are updated to use DAL2 for update, uncomment Cacheable attribute on forumGroupInfo - forumGroupInfo.ForumGroupId = DataProvider.Instance().Groups_Save(portalId, forumGroupInfo.ModuleId, forumGroupInfo.ForumGroupId, forumGroupInfo.GroupName, forumGroupInfo.SortOrder, forumGroupInfo.Active, forumGroupInfo.Hidden, forumGroupInfo.PermissionsId, forumGroupInfo.PrefixURL); + forumGroupInfo.ForumGroupId = DataProvider.Instance().Groups_Save(portalId, forumGroupInfo.ModuleId, forumGroupInfo.ForumGroupId, forumGroupInfo.GroupName, forumGroupInfo.SortOrder, forumGroupInfo.Active, forumGroupInfo.Hidden, forumGroupInfo.PermissionsId, forumGroupInfo.PrefixURL, forumGroupInfo.GroupSettingsKey); if (isNew) { - forumGroupInfo.GroupSettingsKey = $"G:{forumGroupInfo.ForumGroupId}"; - DotNetNuke.Modules.ActiveForums.Controllers.PermissionController.CreateDefaultSets(portalId, forumGroupInfo.ModuleId, forumGroupInfo.PermissionsId); - Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.TopicsTemplateId, "0"); - Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.TopicTemplateId, "0"); - Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.TopicFormId, "0"); - Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.ReplyFormId, "0"); - Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.QuickReplyFormId, "0"); - Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.AllowRSS, "false"); + var tc = new TemplateController(); + Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.TopicsTemplateId, tc.Template_Get(templateName: "TopicsView", portalId: portalId, moduleId: forumGroupInfo.ModuleId).TemplateId.ToString()); + Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.TopicTemplateId, tc.Template_Get(templateName: "TopicView", portalId: portalId, moduleId: forumGroupInfo.ModuleId).TemplateId.ToString()); + Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.TopicFormId, tc.Template_Get(templateName: "TopicEditor", portalId: portalId, moduleId: forumGroupInfo.ModuleId).TemplateId.ToString()); + Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.ReplyFormId, tc.Template_Get(templateName: "ReplyEditor", portalId: portalId, moduleId: forumGroupInfo.ModuleId).TemplateId.ToString()); + Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.QuickReplyFormId, tc.Template_Get(templateName: "QuickReply", portalId: portalId, moduleId: forumGroupInfo.ModuleId).TemplateId.ToString()); + Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.ProfileTemplateId, tc.Template_Get(templateName: "ProfileInfo", portalId: portalId, moduleId: forumGroupInfo.ModuleId).TemplateId.ToString()); + Settings.SaveSetting(forumGroupInfo.ModuleId, forumGroupInfo.GroupSettingsKey, ForumSettingKeys.AllowRSS, "true"); } DataCache.ClearSettingsCache(forumGroupInfo.ModuleId); @@ -72,8 +80,12 @@ public int Groups_Save(int portalId, DotNetNuke.Modules.ActiveForums.Entities.Fo public void Groups_Delete(int moduleId, int forumGroupId) { - //TODO: When these methods are updated to use DAL2 for update, uncomment Cacheable attribute on forumGroupInfo - DataProvider.Instance().Groups_Delete(moduleID: moduleId, forumGroupID: forumGroupId); + var fc = new DotNetNuke.Modules.ActiveForums.Controllers.ForumController(); + foreach (var forum in fc.GetForums(moduleId: moduleId).Where(f => f.ForumGroupId == forumGroupId)) + { + fc.Forums_Delete(forum.ForumID, moduleId); + } + this.DeleteById(forumGroupId); DataCache.ClearSettingsCache(moduleId); } } diff --git a/Dnn.CommunityForums/Providers/DataProviders/SqlDataProvider/SqlDataProvider.cs b/Dnn.CommunityForums/Providers/DataProviders/SqlDataProvider/SqlDataProvider.cs index 1502b8234..ba8430b50 100644 --- a/Dnn.CommunityForums/Providers/DataProviders/SqlDataProvider/SqlDataProvider.cs +++ b/Dnn.CommunityForums/Providers/DataProviders/SqlDataProvider/SqlDataProvider.cs @@ -217,6 +217,7 @@ public override void Forum_ConfigCleanUp(int ModuleId, string ForumSettingsKey, #endregion #region Groups + [Obsolete("Deprecated in Community Forums. Removed in 10.00.00. No longer used.")] public override void Groups_Delete(int ModuleID, int ForumGroupID) { SqlHelper.ExecuteNonQuery(this.ConnectionString, this.DatabaseOwner + this.ObjectQualifier + "activeforums_Groups_Delete", ModuleID, ForumGroupID); @@ -239,9 +240,15 @@ public override void Groups_Move(int ModuleId, int ForumGroupId, int SortDirecti SqlHelper.ExecuteNonQuery(this.ConnectionString, this.DatabaseOwner + this.ObjectQualifier + "activeforums_Groups_MoveGroup", ModuleId, ForumGroupId, SortDirection); } + [Obsolete("Deprecated in Community Forums. Removed in 10.00.00. No longer used.")] public override int Groups_Save(int PortalId, int ModuleId, int ForumGroupId, string GroupName, int SortOrder, bool Active, bool Hidden, int PermissionsId, string PrefixURL) { - return Convert.ToInt32(SqlHelper.ExecuteScalar(this.ConnectionString, this.DatabaseOwner + this.ObjectQualifier + "activeforums_Groups_Save", PortalId, ModuleId, ForumGroupId, GroupName, SortOrder, Active, Hidden, PermissionsId, PrefixURL)); + return Convert.ToInt32(SqlHelper.ExecuteScalar(this.ConnectionString, this.DatabaseOwner + this.ObjectQualifier + "activeforums_Groups_Save", PortalId, ModuleId, ForumGroupId, GroupName, SortOrder, Active, Hidden, PermissionsId, PrefixURL, $"G:{ForumGroupId}")); + } + + public override int Groups_Save(int PortalId, int ModuleId, int ForumGroupId, string GroupName, int SortOrder, bool Active, bool Hidden, int PermissionsId, string PrefixURL, string GroupSettingsKey) + { + return Convert.ToInt32(SqlHelper.ExecuteScalar(this.ConnectionString, this.DatabaseOwner + this.ObjectQualifier + "activeforums_Groups_Save", PortalId, ModuleId, ForumGroupId, GroupName, SortOrder, Active, Hidden, PermissionsId, PrefixURL, GroupSettingsKey)); } #endregion diff --git a/Dnn.CommunityForums/class/DataProvider.cs b/Dnn.CommunityForums/class/DataProvider.cs index ce1779b61..b0132aee7 100644 --- a/Dnn.CommunityForums/class/DataProvider.cs +++ b/Dnn.CommunityForums/class/DataProvider.cs @@ -91,6 +91,7 @@ private static void CreateProvider() #endregion #region Groups + [Obsolete("Deprecated in Community Forums. Removed in 10.00.00. Not Used.")] public abstract void Groups_Delete(int moduleID, int forumGroupID); [Obsolete("Deprecated in Community Forums. Removed in 10.00.00. No longer used.")] @@ -101,7 +102,10 @@ private static void CreateProvider() public abstract void Groups_Move(int moduleId, int forumGroupId, int sortDirection); + [Obsolete("Deprecated in Community Forums. Removed in 10.00.00. Not Used.")] public abstract int Groups_Save(int portalId, int moduleId, int forumGroupId, string groupName, int sortOrder, bool active, bool hidden, int permissionsId, string prefixURL); + + public abstract int Groups_Save(int portalId, int moduleId, int forumGroupId, string groupName, int sortOrder, bool active, bool hidden, int permissionsId, string prefixURL, string groupSettingsKey); #endregion #region Polls diff --git a/Dnn.CommunityForums/controls/admin_manageforums_forumeditor.ascx.cs b/Dnn.CommunityForums/controls/admin_manageforums_forumeditor.ascx.cs index 8cc551975..2577aa9c0 100644 --- a/Dnn.CommunityForums/controls/admin_manageforums_forumeditor.ascx.cs +++ b/Dnn.CommunityForums/controls/admin_manageforums_forumeditor.ascx.cs @@ -338,7 +338,7 @@ private void cbEditorAction_Callback(object sender, Controls.CallBackEventArgs e case "deleteforum": { var forumId = Utilities.SafeConvertInt(e.Parameters[1]); - new DotNetNuke.Modules.ActiveForums.Controllers.ForumController().Forums_Delete(portalId: this.PortalId, moduleId: this.ModuleId, forumId: forumId); + new DotNetNuke.Modules.ActiveForums.Controllers.ForumController().Forums_Delete(moduleId: this.ModuleId, forumId: forumId); break; } diff --git a/Dnn.CommunityForums/sql/08.02.00.SqlDataProvider b/Dnn.CommunityForums/sql/08.02.00.SqlDataProvider index 8729a262b..a5a89ce9d 100644 --- a/Dnn.CommunityForums/sql/08.02.00.SqlDataProvider +++ b/Dnn.CommunityForums/sql/08.02.00.SqlDataProvider @@ -2195,4 +2195,63 @@ EXEC {databaseOwner}[{objectQualifier}activeforums_Forums_RepairSort] @ForumGrou GO /* issue 1156 - end - deleting a forum should remove subscriptions */ +/* --------------------- */ + +/* issue 1162 - begin - pass group setting key to Groups_Save */ + +/* activeforums_Groups_Save -- pass group setting key to Groups_Save */ +IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_Groups_Save]') AND type in (N'P', N'PC')) +DROP PROCEDURE {databaseOwner}[{objectQualifier}activeforums_Groups_Save] +GO +CREATE PROCEDURE {databaseOwner}[{objectQualifier}activeforums_Groups_Save] +@PortalId int, +@ModuleId int, +@ForumGroupId int, +@GroupName nvarchar(150), +@SortOrder int, +@Active bit, +@Hidden bit, +@PermissionsId int, +@PrefixURL nvarchar(50), +@GroupSettingsKey varchar(255) = '' +AS +IF @PrefixURL <> '' AND @ForumGroupId >0 + BEGIN + DECLARE @currURL nvarchar(1000) + SET @currURL = {databaseOwner}{objectQualifier}fn_activeforums_GetURL(@ModuleId,@ForumGroupId, -1,-1,-1,-1) + DECLARE @newURL nvarchar(1000) + SET @currURL = {databaseOwner}{objectQualifier}fn_activeforums_GetURL(@ModuleId,-1, -1,-1,-1,-1) + @PrefixURL + '/' + IF LTRIM(RTRIM(LOWER(@newURL))) <> LTRIM(RTRIM(LOWER(@currURL))) + BEGIN + exec {databaseOwner}{objectQualifier}activeforums_URL_Archive @PortalId,@ForumGroupId, -1, -1, @currURL + END + END +IF EXISTS(Select ForumGroupId FROM {databaseOwner}{objectQualifier}activeforums_Groups WHERE ForumGroupId = @ForumGroupId AND ModuleId = @ModuleId) + UPDATE {databaseOwner}{objectQualifier}activeforums_Groups + SET GroupName=@GroupName, Active=@Active,Hidden=@Hidden, PermissionsId = @PermissionsId,PrefixURL = @PrefixURL + WHERE ForumGroupId = @ForumGroupId and ModuleId = @ModuleId +ELSE + BEGIN + BEGIN + SELECT @SortOrder = Max(SortOrder) + 1 From {databaseOwner}{objectQualifier}activeforums_Groups WHERE ModuleID=@ModuleID + If @SortOrder IS NULL + SET @SortOrder = 1 + END + INSERT INTO {databaseOwner}{objectQualifier}activeforums_Groups + (ModuleId, GroupName, SortOrder,GroupSettingsKey,Active,Hidden, PermissionsId,PrefixURL) + VALUES + (@ModuleId, @GroupName, @SortOrder,'',@Active,@Hidden, @PermissionsId,@PrefixURL) + SET @ForumGroupId = SCOPE_IDENTITY() + BEGIN + IF @GroupSettingsKey = '' + UPDATE {databaseOwner}{objectQualifier}activeforums_Groups SET GroupSettingsKey = 'G:' + CAST(@ForumGroupId as varchar(50)) WHERE ForumGroupId = @ForumGroupId + ELSE + UPDATE {databaseOwner}{objectQualifier}activeforums_Groups SET GroupSettingsKey = GroupSettingsKey WHERE ForumGroupId = @ForumGroupId + END + END +SELECT @ForumGroupId +GO + +/* issue 1162 - end - adds group setting key to Groups_Save */ + /* --------------------- */ \ No newline at end of file