I'M very optimistic the scripts would do it. I have applied every single one without error until I got to the last: AdjustDNNContentItem. The error below, what do I do?
System.Data.SqlClient.SqlException (0x80131904): The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row matches more than one source row. A MERGE statement cannot UPDATE/DELETE the same row of the target table multiple times. Refine the ON clause to ensure a target row matches at most one source row, or use the GROUP BY clause to group the source rows.
at System.Data.SqlClient.SqlConnection. (SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at DotNetNuke.Data.SqlDataProvider.ExecuteScriptInternal(String connectionString, String script)
ClientConnectionId:59229a61-8988-41be-aec2-7d00d5b685b7
Error Number:8672,State:1,Class:16
/* Validate and Fix ContentItems for DesktopModules
================================================ */
-- Get ContentType:
DECLARE @ContentType Int = (SELECT ContentTypeID FROM dbo.[ContentTypes] WHERE ContentType = N'DesktopModule');
-- remove orphaned contentItems:
DELETE FROM dbo.[ContentItems]
WHERE ContentTypeID = @ContentType AND Content NOT IN (SELECT [FriendlyName] FROM dbo.[DesktopModules]);
-- remove invalid ContentItemIDs:
MERGE INTO dbo.[DesktopModules] M
USING dbo.[ContentItems] C ON (C.ContentItemID = M.ContentItemID)
WHEN NOT Matched BY Source AND M.ContentItemID != -1 THEN UPDATE SET ContentItemID = -1;
-- add missing content items:
MERGE INTO dbo.[ContentItems] C
USING dbo.[DesktopModules] M ON (C.ContentTypeID = @ContentType AND C.Content = M.FriendlyName)
WHEN MATCHED AND IsNull(M.FriendlyName,'') != IsNull(C.Content, '') THEN UPDATE
SET Content = M.FriendlyName, LastModifiedByUserID = M.LastModifiedByUserID, LastModifiedOnDate = M.LastModifiedOnDate
WHEN NOT MATCHED THEN INSERT
(Content, ContentTypeID, TabID, ModuleID, CreatedByUserID, CreatedOnDate, LastModifiedByUserID, LastModifiedOnDate)
VALUES (M.FriendlyName, @ContentType, -1, -1, M.CreatedByUserID, M.CreatedOnDate, M.LastModifiedByUserID, M.LastModifiedOnDate);
-- update references:
MERGE INTO dbo.[DesktopModules] M
USING dbo.[ContentItems] C ON (C.ContentTypeID = @ContentType AND C.Content = M.FriendlyName)
WHEN Matched AND IsNull(M.ContentItemID, -1) != C.ContentItemID THEN UPDATE SET ContentItemID = C.ContentItemID;
DELETE FROM dbo.[ContentItems_MetaData]
WHERE ContentItemID IN (SELECT ContentItemID FROM dbo.[ContentItems] WHERE ContentTypeID = @ContentType);