Skip to content

Commit

Permalink
Merge pull request #1165 from johnhenley/dev82/dal2-groups-1162
Browse files Browse the repository at this point in the history
TASK: replace forum group delete stored procedure with DAL2
  • Loading branch information
johnhenley authored Nov 14, 2024
2 parents f46bfd1 + 7022649 commit ea7e56a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 17 deletions.
11 changes: 7 additions & 4 deletions Dnn.CommunityForums/Controllers/ForumController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand Down
34 changes: 23 additions & 11 deletions Dnn.CommunityForums/Controllers/ForumGroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Dnn.CommunityForums/class/DataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
59 changes: 59 additions & 0 deletions Dnn.CommunityForums/sql/08.02.00.SqlDataProvider
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

/* --------------------- */

0 comments on commit ea7e56a

Please sign in to comment.