I'm trying to capture when a component is unpublished. I try some approaches but I don't have the result that I want. My attempts are:
In Event System. But this not works because there are a known bug in Windows about MSXML and COM+.
I try to build my own IResolver but there I cannot determine if it's a publishing or unpublishing action.
I try to build my own ITransportPackageHandler. There, I have a function called HandleResolvedItemForUnPublishing but I don't have any information about PublicationTarget and I don't know if it's unpublished from staging or live.
Can someone help me? I think that I can solve the problem if:
thank you very much.
Gustavo.
You should be able to look at the ResolvePurpose
of the ResolveInstruction
that you get as one of the parameters in the custom resolver. Something along these lines:
public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, ISet<ResolvedItem> resolvedItems)
{
if (instruction.Purpose == ResolvePurpose.Publish || instruction.Purpose == ResolvePurpose.RePublish)
{
// We are publishing
}
else if(instruction.Purpose == ResolvePurpose.UnPublish)
{
// We are unpublishing
}
// Don't know if this one exists in 2009, it exists in 2011 SP1
else if(instruction.Purpose == ResolvePurpose.UnknownByClient)
{
// The server is doing something that I don't understand (yet?)
}
}
EDIT
I refused to not find a way to make this work...
Indeed, in Tridion 2009 you don't have a Purpose
on the resolve instruction. You do have an Action
in the Publish Transaction, but this one is not exposed directly in the resolver. Here's how I found out if I'm publishing or unpublishing - your call if think it's overkill, but performance on my non-production VM was pretty good.
Action
attributeFilter filter = new Filter();
filter.Conditions["InfoType"] = 2; // Get transactions in Progress
foreach (XmlNode node in item.Session.GetList(typeof(PublishTransaction), filter))
{
if(node.Attributes["ItemID"].Value.Equals(item.Id.ToString()))
{
// we have a winner
string action;
if (node.Attributes["Action"].Value.Equals("0"))
action = "Publish";
if (node.Attributes["Action"].Value.Equals("1"))
action = "Unpublish";
}
}