Skip to content

Error‐Resolving orphaned Forums

johnhenley edited this page Jun 28, 2024 · 4 revisions

/* // // Community Forums // Copyright (c) 2013-2024 // by DNN Community // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated // documentation files (the "Software"), to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and // to permit persons to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or substantial portions // of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // */

/*

// This script can be used to detect Forums with missing Forum Groups. // If you uncomment the bottom portion, it will create a new Forum Group for the orphaned Forums. // You will need to adjust this script if you use a schema other than [dbo], and/or if you use an object_qualifier.

*/

/* Run this command to see if you have orphaned forum groups */

SELECT f.ModuleId, f.ForumId, f.ForumName, f.ForumGroupId FROM [dbo].[activeforums_Forums] f LEFT OUTER JOIN [dbo].[activeforums_Groups] g ON g.ForumGroupId = f.ForumGroupId WHERE g.ForumGroupId IS NULL;

/* Only remove the comment below and the line at the end of this script when you are comfortable with what is being performed. If you are in doubt, please post an issue on https://github.com/DNNCommunity/Dnn.CommunityForums for more guidance */

/*

INSERT INTO [dbo].[activeforums_Permissions] ([CanView] ,[CanRead] ,[CanCreate] ,[CanReply] ,[CanEdit] ,[CanDelete] ,[CanLock] ,[CanPin] ,[CanAttach] ,[CanPoll] ,[CanBlock] ,[CanTrust] ,[CanSubscribe] ,[CanAnnounce] ,[CanModApprove] ,[CanModMove] ,[CanModSplit] ,[CanModDelete] ,[CanModUser] ,[CanModEdit] ,[CanModLock] ,[CanModPin] ,[CanTag] ,[CanCategorize] ,[CanPrioritize]) VALUES ('||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||', '||||');

DECLARE @PermissionId int = SCOPE_IDENTITY();

INSERT INTO [dbo].[activeforums_Groups] SELECT DISTINCT f.ModuleId, 'Orphaned Forums', 0, 0, 0, '', @PermissionId, 'Orphaned' FROM [dbo].[activeforums_Forums] f LEFT OUTER JOIN [dbo].[activeforums_Groups] g ON g.ForumGroupId = f.ForumGroupId AND g.ForumGroupId IS NULL;

UPDATE f SET ForumGroupId = g2.ForumGroupId FROM [dbo].[activeforums_Forums] f LEFT OUTER JOIN [dbo].[activeforums_Groups] g ON g.ForumGroupId = f.ForumGroupId INNER JOIN [dbo].[activeforums_Groups] g2 ON g2.ModuleId = f.ModuleId AND g2.PrefixURL = 'Orphaned' WHERE g.ForumGroupId IS NULL

UPDATE [dbo].[activeforums_Groups] SET GroupSettingsKey = 'G:'+ CAST(ForumGroupId as varchar(50)), PrefixURL = '' WHERE PrefixURL = 'Orphaned'

//this should now be empty SELECT f.ModuleId, f.ForumId, f.ForumName, f.ForumGroupId FROM [dbo].[activeforums_Forums] f LEFT OUTER JOIN [dbo].[activeforums_Groups] g ON g.ForumGroupId = f.ForumGroupId WHERE g.ForumGroupId IS NULL;

*/

Clone this wiki locally