I have a layout item in Sitecore and I am able to identify all the referrer items via Links button. I have tons of referrer items, I would like to remove all of them. I am hoping that I won't have to go through each item individually to delete the reference items. I am also hoping not to delete the referred items and recreating it since it will generate different GUID for the new item.
Is there a way to do this via Sitecore Desktop or SQL Server?
You can create a dynamic Asp.net page with the following code logic in the code behind.
public string RemoveReferenceLinks(string nodePath)
{
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var item = db.GetItem(nodePath);
if (item == null) return new ItemLink[0];
var links = Globals.LinkDatabase.GetItemReferrers(item, true);
if (links.Length == 0)
{
return "No referrence found";
}
foreach (var link in links)
{
var sourceItem = link.GetSourceItem();
foreach (var item1 in sourceItem.Versions.GetVersions(true))
{
var field = item1.Fields[link.SourceFieldID];
var field2 = FieldTypeManager.GetField(field);
if (field2 == null) return;
using (new SecurityDisabler())
{
item1.Editing.BeginEdit();
field2.RemoveLink(link);
item1.Editing.EndEdit();
}
}
}
return "All reference removed";
}
If you have set presentation details on your standard value, then simply change the layout on the templates standard item to the new layout.
If that's not the case, then backup your layout item by packaging it using Sitecore package designer, then try to delete the layout item. Sitecore will show a popup telling you that other items contains links to this item, and gives you the option to link to another item, which is what you need.
After that you can restore your layout item by installing the backup package.