I am trying to delete a couple of publication targets but am getting a warning saying This item is in use
. The location of my publication targets no longer exist so unpublishing using the target fails.
How can I delete the Publication Target?
I am trying to delete a couple of publication targets but am getting a warning saying This item is in use
. The location of my publication targets no longer exist so unpublishing using the target fails.
How can I delete the Publication Target?
There will be items that are published to the publication target. I would do the following:
I wouldn't recommend manually changing something in the database to 'trick' the delete.
IMPORTANT
Although this solved my problem, I'd advise anyone with a similar problem to first try the suggestions from Dominic, Trevor, Nuno and John. And as Bart has just pointed out, only after Customer Support have told you to do this. You have been warned.
I contacted SDL Support and they advised me to make a backup of the Content Manager Database and then run the following UPDATE
commands
UPDATE ITEM_STATES
SET STATE = 0
WHERE
PUBLICATION_TARGET_ID = @MyPublicationTargetID
AND STATE = 1
UPDATE PUBLISH_STATES
SET STATE = 0
WHERE
PUBLICATION_TARGET_ID = @MyPublicationTargetID
AND STATE = 1
This sets the published status to "unpublished" for all items associated with a particular publishing target. I was then able to delete the publication target through the Content Manager Explorer.
Even after all the content is unpublished, make sure all the Target Types and publication associations are removed. I remember that being a sticking point for me.
page.SetPublishedTo(target.Attributes["ID"].Value, false, tdse.User.ID);
should work.
Commented
Mar 22, 2013 at 18:11
SetPublishedTo
method available.
Commented
Mar 25, 2013 at 9:55
Sometimes the only way to get the necessary information is a bit of database digging. First, of course, clean up all the obvious things - make sure nothing's published to it, remove any publish transactions, etc. If all that doesn't work, try the following:
In the database, examine EDA_PUBLICATION_TARGETS_DELETE - observe that it begins with several selects which need to come up empty. Execute these same selects by hand, and check what items, if any, are found. If you find any items, you will probably find that you can delete them perfectly cleanly without modifying anything in the database yourself. Just instantiate each object from the API and use the .Delete() method.
OK, I'm a bit upset that:
You could have achieved the same result with the following code:
TDSE tdse = new TDSE();
Console.WriteLine(tdse.User.Name);
PublicationTarget target = tdse.GetObject("tcm:0-1-65537", EnumOpenMode.OpenModeView);
ListRowFilter listRowFilter = tdse.CreateListRowFilter();
listRowFilter.SetCondition("OnlyPublishedItems", true);
XmlNamespaceManager nm = new XmlNamespaceManager(new NameTable());
nm.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");
Dictionary<string,ComponentTemplate> componentTemplates = new Dictionary<string, ComponentTemplate>();
foreach (Publication p in target.AllowedPublications)
{
XmlDocument publishedItems = new XmlDocument();
Console.WriteLine(listRowFilter.GetXML());
publishedItems.LoadXml(p.GetListPublishItems("tcm:0-1-65537", false, false, ListColumnFilter.XMLListDefault, listRowFilter));
foreach (XmlNode node in publishedItems.SelectNodes("tcm:ListPublishItems/tcm:PublicationTarget/tcm:Page", nm))
{
Page page = tdse.GetObject(node.Attributes["ID"].Value, EnumOpenMode.OpenModeView);
Console.WriteLine("Resetting published status of " + page.Title);
page.SetPublishedTo(target, false, tdse.User);
}
foreach (XmlNode node in publishedItems.SelectNodes("tcm:ListPublishItems/tcm:PublicationTarget/tcm:Component", nm))
{
Component component = tdse.GetObject(node.Attributes["ID"].Value, EnumOpenMode.OpenModeView);
foreach (XmlNode ctNode in node.SelectNodes("tcm:RenderWith", nm))
{
string ctId = ctNode.Attributes["ID"].Value;
if (!componentTemplates.ContainsKey(ctId))
{
ComponentTemplate ct = tdse.GetObject(ctId, EnumOpenMode.OpenModeView);
componentTemplates.Add(ctId, ct);
}
Console.WriteLine("Resetting published status of " + component.Title + " (with template " + componentTemplates[ctId].Title + ")");
componentTemplates[ctId].SetPublishedTo(component, target, false, tdse.User);
}
}
}