Bug reports Found a bug? Post it here please.
Version 6.x > Bug reports > Duplicate documents in Tree View modes: 
User avatar
Member
Member
lancetek - 3/21/2013 11:07:41 AM
   
Duplicate documents in Tree
I have a few duplicate documents in our tree: User image

When I look at the properties, they have the same Document alias', Same live URL, Same Node ID and Document ID... every property looks to be identical.

I tried deleting ONE of them, and both instances disappear from the tree. If I then go into the Bin and try to restore the document:

Restoring document failed. Original exception: [DataConnection.HandleError]: Query: INSERT INTO CMS_Tree ([NodeAliasPath], [NodeName], [NodeAlias], [NodeClassID], [NodeParentID], [NodeLevel], [NodeACLID], [NodeSiteID], [NodeGUID], [NodeOrder], [IsSecuredNode], [NodeCacheMinutes], [NodeSKUID], [NodeDocType], [NodeHeadTags], [NodeBodyElementAttributes], [NodeInheritPageLevels], [NodeChildNodesCount], [RequiresSSL], [NodeLinkedNodeID], [NodeOwner], [NodeCustomData], [NodeGroupID], [NodeLinkedNodeSiteID] ) VALUES ( @NodeAliasPath, @NodeName, @NodeAlias, @NodeClassID, @NodeParentID, @NodeLevel, @NodeACLID, @NodeSiteID, @NodeGUID, @NodeOrder, @IsSecuredNode, @NodeCacheMinutes, @NodeSKUID, @NodeDocType, @NodeHeadTags, @NodeBodyElementAttributes, @NodeInheritPageLevels, @NodeChildNodesCount, @RequiresSSL, @NodeLinkedNodeID, @NodeOwner, @NodeCustomData, @NodeGroupID, @NodeLinkedNodeSiteID); SELECT SCOPE_IDENTITY() AS [NodeID]: caused exception: Cannot insert duplicate key row in object 'dbo.CMS_Tree' with unique index 'IX_CMS_Tree_NodeSiteID_NodeGUID'. The duplicate key value is (1, 8c3f48f5-f835-4bf6-b51b-86aae4d71708). The statement has been terminated.


If I then try to create another document with the same name(because the restore won't work), the document alias gets the '-(1)' appended to it - as if there is already a document in the tree. (But there isn't...)

In looking inside the CMS_Tree and CMS_Documents tables, there are two entries for each node and document! As seen here:
User image
you can see that each Node has an identical NodeAliasPath. But when you view the nodes via the CMS Desk, they only show the values from ONE of the database rows! here's a view of selecting two different documents in the CMS Tree... but the values are all the same:
User image


Is there some sort of fix or db update I can do to rid myself of these extra documents?


We are using Kentico 6.0.58(SP1)


User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/23/2013 12:21:39 PM
   
RE:Duplicate documents in Tree
Hi,

How did you managed to get the duplicates? I have never seen this before and I am unable to reproduce the on my 6.0.58 installation.
Is there any custom code used or any of the system files was modified?

Are you able to reproduce it on another CMS instance or on a clean v6 installation?

Best regards,
Juraj Ondrus

User avatar
Member
Member
lancetek - 3/24/2013 6:45:09 AM
   
RE:Duplicate documents in Tree
I *think* they were inserted by using the Content Staging.

I've noticed this has happened a few times on other projects. It's not a problem that I can replicate easily. Usually Content Staging just overwrites/updates the destination document... but sometimes it creates a new one. Which causes problems as Kentico expects each AliasPath to be unique.

I suppose to stop this from occurring, having a unique restriction on the AliasPath database column would be good. And maybe also stop using integers as the primary key for most tables - as divergence between installations causes havoc with the Content Staging:

We tend to use one-way Content Staging, but sometimes documents may be created at the different levels - so that the integer keys don't match up any more.

Example: We have 4 environments:
5x development machines (Dev)
1x Merge
1x Staging
1x Live

New documents are sometimes created at all these levels -
Dev, Merge, Staging and Live. So when I create node 32145 on Dev, when it gets pushed to Merge it may end up being 32156, and pushed to Staging it may be 32168, with it finally ending up as 32199 on Live.

Recently we've been adding another Culture to our project... and adding quite a few new pages in this other Culture.


Side Note: When we do a big deployment, we will end up taking a database dump from Live and restoring to Dev, Merge and Staging, in an effort to occasionally get all the databases for all the environments matching up.


I'm sure that this won't help you to fix it, since it's something that I can't reliably replicate. But it is annoying when it happens!

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/24/2013 1:08:46 PM
   
RE:Duplicate documents in Tree
Hi,

I understand. However, without exact steps - it is hard to look for the cause in the thousands of staging module code :-(

In staging or between different DBs, the IDs can be different - but that is OK since there is a translation in place to match the object records by the GUID, which should be always unique. It seems, that under some special circumstances and sequence of steps, some inconsistence in the DB happens - but without more details it is hard to discover the isse.

Best regards,
Juraj Ondrus

User avatar
Member
Member
lancetek - 3/24/2013 1:27:11 PM
   
RE:Duplicate documents in Tree
I understand your understanding Juraj! If I can figure out some way to reliably replicate it, I'll let you know.

What's the recommended way to remove these duplicate nodes from the database? I can't remove them via the CMS desk, due to the aforementioned error.

Here's what I've used in the past:




DECLARE @_menuItemId int
DECLARE @_nodeId int
DECLARE @_documentId int


SELECT @_menuItemId = menuItemId, @_nodeId = nodeId, @_documentId = documentId
FROM [View_CONTENT_MenuItem_Joined]
WHERE nodeId = 29592

print @_menuItemId
print @_nodeId
print @_documentId



DELETE FROM CONTENT_menuItem WHERE menuitemid = @_menuItemId
DELETE FROM CMS_Document WHERE documentId = @_documentId
DELETE FROM cms_DocumentAlias WHERE aliasnodeId = @_nodeId

DELETE FROM CMS_WorkflowHistory WHERE VersionHistoryId in (SELECT VersionHistoryId FROM cms_versionhistory where documentid = @_documentId)
DELETE FROM cms_versionhistory where documentid = @_documentId

DELETE FROM CMS_EventLog WHERE nodeId = @_nodeId
DELETE FROM CMS_Tree WHERE nodeId = @_nodeId


User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/26/2013 12:13:58 PM
   
RE:Duplicate documents in Tree
Hi,

I understand that you understand... (just kidding :-))

That query looks good - deleting them directly in the DB is the only way right now. Just, please be sure you have backup of the DB before deleting them in case anything will go wrong.

Best regards,
Juraj Ondrus