6

I am working on the following event system:

EventSystem.Subscribe<PublishTransaction, SaveEventArgs>(MyEventHandler, EventPhases.Initiated);

void MyEventHandler(PublishTransaction publishTransaction, SaveEventArgs saveEventArgs, EventPhases eventPhases)
{
    IdentifiableObject identifiableObject = publishTransaction.Items[0];
    if (identifiableObject.Id == "tcm:40-81620") //the test component
    {
        PublishContext publishContext = publishTransaction.PublishContexts[0];

        log.DebugFormat(
            "{0} - publishContext[0].ResolvedItems.Count = {1}; publishContext[0].ProcessedItems.Count = {2}",
            publishTransaction.State.ToString(),
            publishContext.ResolvedItems.Count,
            publishContext.ProcessedItems.Count);
    }
}

I need to do something with the resolved items, but I wasn't getting the behaviour I was expecting, so I decided to log the PublishTransactionState, ResolvedItems and ProcessedItems. In the handler I have set the code to run just for a single test component in order not to get logs for other transactions. The test component is being rendered with two templates.

Here is the log I get(using log4net):

WaitingForPublish - publishContext[0].ResolvedItems.Count = 0; publishContext[0].ProcessedItems.Count = 0
InProgress -  publishContext[0].ResolvedItems.Count = 0; publishContext[0].ProcessedItems.Count = 0
Resolving - publishContext[0].ResolvedItems.Count = 0; publishContext[0].ProcessedItems.Count = 0
Rendering - publishContext[0].ResolvedItems.Count = 0; publishContext[0].ProcessedItems.Count = 0
Rendering - publishContext[0].ResolvedItems.Count = 0; publishContext[0].ProcessedItems.Count = 2
ReadyForTransport - publishContext[0].ResolvedItems.Count = 2; publishContext[0].ProcessedItems.Count = 2
ReadyForTransport - publishContext[0].ResolvedItems.Count = 2; publishContext[0].ProcessedItems.Count = 2
WaitingForDeployment - publishContext[0].ResolvedItems.Count = 2; publishContext[0].ProcessedItems.Count = 2
Success - publishContext[0].ResolvedItems.Count = 2; publishContext[0].ProcessedItems.Count = 2

Can someone please explain the following:

  • Why is the 'PublishContext[0].ProcessedItems' populated prior to 'PublishContext[0].ResolvedItems?
  • Why are there two 'Rendering' states? In question PublishTransaction save event triggered multiple times Rick Pannekoek states that "In general, the Save event is called for any save (change) of the PublishTransaction, not only for state changes" which is clear, however I can't seem to find out which property change is causing this. Is there an easy way to find out what is causing this save?

Thank you in advance

5
  • 1
    Why are there two 'Rendering' states? isn't this because you're rendering two component presentations? Jul 4, 2016 at 13:04
  • Can you share your event handler code please so that we can see how/where you're calling the log statements? Jul 4, 2016 at 13:15
  • @Dylan..MarkSaunders Hm, possibly. I was expecting a single Rendering since they're all part of the same transaction. I will add a third CT and verify. I will post a comment once I've tried it.
    – Atila Sos
    Jul 4, 2016 at 13:58
  • @NickoliRoussakov, Sure, I've updated the original description.
    – Atila Sos
    Jul 4, 2016 at 13:59
  • 1
    @Dylan..MarkSaunders, adding a third CT resulted in a second ReadyForTransport appearing, while two Rendering-s remained. So that confirms that it's unrelated to the number of templates involved. The event gets triggered by some property change. At this point I've pretty much given up on finding out which one, it was just a side-question :). However the main dilemma remains, why does the processed items get populated before the resolved items.
    – Atila Sos
    Jul 4, 2016 at 14:25

1 Answer 1

6

Regarding the "Why are there two 'Rendering' states?", or more accurately "Why are there two Save events with State 'Rendering'?": you already more or less answered the question yourself -- the first one is for the State change to 'Rendering', the second one for changing the ProcessedItems.

IIRC, the ResolvedItems property is derived from ProcessedItems. I think this derivation happens when loading the item. That would explain why you don't see them yet in the Save event that happens when ProcessedItems are set. It also matters to which Event Phase ypu subscribed.

Your Answer

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

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