Search code examples
tridiontridion2009

How to determine in a Custom Resolver if I am publishing or unpublishing? Tridion 2009 SP1


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:

  1. In Event System. But this not works because there are a known bug in Windows about MSXML and COM+.

  2. I try to build my own IResolver but there I cannot determine if it's a publishing or unpublishing action.

  3. 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:

  1. At the IResolver I can determine if the component is unpublishing.
  2. At the ITransportPackageHandler I can access to the PublicationTarget info
  3. If I can pass info from IResolver to the ITransportPackageHandler in a context variable or something similar.

thank you very much.

Gustavo.


Solution

  • 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.

    1. Find the current item we're resolving for
    2. Load the list of PublishTransaction with a state of "In Progress"
    3. Find the transaction for the current item
    4. Determine the action by looking at the Action attribute
    Filter 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";
        }
    }