2

There are two components, component A and component B, both are published, component A contains component B, now I want to unpublish component B, because component A contains component B, so I wish the unpublish operation fail. Question: How can I get the information that component A contains component B under the condition that I only know component B and do not know component A contains component B through Tom.NET?

Any assistance will be greatly appreciated.

1
  • 1
    Preventing unpublish can help avoid "accidents," but if the requirement is to "remove B" from the site, as an author you should remove it from where it's used and then publish all the "A's." What types of content are A and B? May 12, 2014 at 22:24

2 Answers 2

5

There's a couple of ways (as usual) to get this done. The easiest (in my opinion) is to use a custom resolver (see google results) and look inside the list of ResolvedItems - this list will contain all the items that have been resolved to be (un)published and you can manipulate the contents of the list to add or remove items from it.

Another option is to use the same ResolveEngine instruction that Tridion does when deciding to (un)publish something and see what's returned - something along these lines:

Component c = (Component)session.GetObject("tcm:5-7101");
ResolveInstruction i = new ResolveInstruction(session)
{
    Purpose = ResolvePurpose.UnPublish
};
Publication p = (Publication)c.ContextRepository;
PublicationTarget pt = (PublicationTarget)session.GetObject("tcm:0-2-65537");
PublishContext context = new PublishContext(p, pt );

Tridion.Collections.ISet<ResolvedItem> items =  ResolveEngine.ResolveItem(c, i, context);
foreach (var item in items)
{
   // do something
   // throw some exception or whatever...
}
2

You can write a event system code on when the UnPublish Transaction is initiated. In that you can check for the WhereUsed Items on the Component B and check whether the resultset contains any published component on the particular target on which you are unpublishing the Component B. If it is true, then you can abort the transaction.

Regards, Sharad Sangal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.