How to Remove Orphaned or Missing Umbraco Nodes
Here is a little tip on how to remove missing or orphaned nodes within Umbraco. You may encounter this error if you try copying nodes within the back office. You'll receive an error relating to a method called 'umbraco.dialogs.moveOrCopy.CheckPermissions'. To find any orphaned nodes and remove them, run the following script against your Umbraco database. Make sure you backup your database first. It's a little long winded but the script finds any nodes and dependencies that do not have a version, are not trashed and is of type content.
| deletefrom cmsPropertyData where contentNodeId in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') | |
| deletefrom cmsDocument where nodeId in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') | |
| deletefrom cmsPreviewXml where nodeId in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') | |
| deletefrom cmsContentVersion where ContentId in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') | |
| deletefrom cmsContentXml where nodeId in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') | |
| deletefrom cmsContent where nodeId in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') | |
| deletefrom umbracoUser2NodePermission where nodeId in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') | |
| deletefrom umbracoNode where id in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') |
You may encounter a situation where some of your orphaned nodes have child nodes. You'll need to remove these as well. To identify and remove child nodes of orphaned children, use the following script before the script above. Make sure you backup your database.
| deletefrom cmsPropertyData where contentNodeId in (select id from UmbracoNode where parentID in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972')) | |
| deletefrom cmsDocument where nodeId in (select id from UmbracoNode where parentID in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972')) | |
| deletefrom cmsPreviewXml where nodeId in (select id from UmbracoNode where parentID in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972')) | |
| deletefrom cmsContentVersion where ContentId in (select id from UmbracoNode where parentID in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972')) | |
| deletefrom cmsContentXml where nodeId in (select id from UmbracoNode where parentID in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972')) | |
| deletefrom cmsContent where nodeId in (select id from UmbracoNode where parentID in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972')) | |
| deletefrom umbracoUser2NodePermission where nodeId in (select id from UmbracoNode where parentID in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972')) | |
| deletefrom umbracoNode where parentID in (select id from UmbracoNode where id not in (select nodeid from cmsContentXml) and id in (select nodeId from cmsDocument where published =1) and trashed =0and nodeObjectType ='C66BA18E-EAF3-4CFF-8A22-41B16D66A972') |