How to define in a custom resolver if I publish or publish publications? Tridion 2009 SP1

I try to capture when the component is not published. I try several approaches, but I don't have the result that I want. My attempts:

  • In the event system. But this does not work, because there is a known error in Windows about MSXML and COM +.

  • I am trying to create my own IResolver, but I cannot determine if this is a publication or an unpublished action.

  • I am trying to create my own ITransportPackageHandler. There I have the HandleResolvedItemForUnPublishing function, but I have no information about PublicationTarget, and I don’t know whether it is published from the stage or live.

Can someone help me? I think I can solve the problem if:

  • In IResolver, I can determine if a component is unpublished.
  • In ITransportPackageHandler, I can access PublicationTarget information
  • If I can pass information from IResolver to ITransportPackageHandler into a context variable or something like that.

Thank you very much.

Gustavo.

+4
source share
2 answers

You can look at ResolveInstruction , which you get as one of the parameters in a custom converter. Something like that:

 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 not to find a way to make this work ...

In fact, in Tridion 2009 you do not have the Purpose command in the permission command. You have an Action in the Publish transaction, but this does not appear directly in the converter. Here, as I found out whether I publish or not, your call is if you think it is too much, but the performance on my non-production virtual machine was pretty good.

  • Find the current item that we allow for
  • Download the PublishTransaction list with the status is in progress.
  • Find transaction for current item
  • Define an 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"; } } 
+6
source

Assuming you are using 2011, you can bind an event handler to the Save publication event and check the status. Then, when the component is not published, you can execute the necessary logic.

 public sealed class PublishedToEventHandler: TcmExtension { public PublishedToEventHandler() { EventSystem.SubscribeAsync<PublishTransaction, SaveEventArgs>( (subject, args, phase) => { if (!PublishStransactionStateIsSuccessfullyCompleted(subject)) return; }, EventPhases.TransactionCommitted ); } static bool PublishStransactionStateIsSuccessfullyCompleted(PublishTransaction transaction) { return transaction.State == PublishTransactionState.Success || transaction.State == PublishTransactionState.Warning; } } 

Before anything is processed in this event, you can check the Instruction.ResolveInstruction.Purpose property for the transaction to see if you publish the publication when you publish it.

The transaction has a collection of ProcessedItems , each of which contains a page or component in the ResolvedItem.Item property of the ProcessedItem object. When you need a page, you need to get the Components embedded in the page to do something with them.

Let me know if you have more questions.

+1
source

All Articles