3

I have subscribed to the following event:

private void Subscribe()
{
        EventSystem.Subscribe<Component, PublishEventArgs>(ComponentPrePublish, EventPhases.TransactionCommitted);
}
private void ComponentPrePublish(Component component, PublishEventArgs e, EventPhases phase)
{
        if (e.PublishInstruction.ResolveInstruction.Purpose == ResolvePurpose.Publish)
        {
                MethodForComponentUpdate(component);
        }
}

Everything is working fine when I publish a component.

But, when I publish a component and check "Also Publish in Child Publications" my expectation is that this event will trigger for parent + each child component being published. It is not, it is only triggering for parent component.

Am I doing something wrong or is this behavior by design?

Edit - adding requirements:

Requirement that I am trying to solve is whenever component is publish, metadata fields of that component need to be updated before rendering is started.

Edit 2 - more clarifications:

I need to add/update component metadata with appropriate taxonomy before component is published (not saved, as it is too dynamic) so that content can be correctly queried on CD side. This should also match CM taxonomy so that Content Editors know what they are doing.

2 Answers 2

1

If I'm not mistaking, PublishEventArgs is the actual action in the UI, what happens with the "Also Publish in Child Publications" is a resolve action which adds items to the Publish Transaction.

So those items are not physically scheduled for publish themselves, they are just being rendered (which ends up with the same result of them being published).

update

So your requirement is to update a Component before rendering has started. I would probabaly consider a post save event in that case, unless the data you need really is that dynamic that it could be changed after the Component was saved and before it is published. In that case you might need to consider not storing it in the Component at all, and just using a TBB to add it to your output (since you should never store dynamic data).

I've written an event handler before which copied the ECL metadata over to Tridion metadata at save/checkin, since I needed that information at publish time. See the source code of that event handler here https://github.com/bkoopman/sdl-tridion-world/blob/master/ECL%20Stub%20Component%20Event%20Handler/trunk/ECL%20Stub%20Component%20Event%20Handler/EventHandler.cs

3
  • Hi Bart, requirement added. I have also tried to get component list from publish transaction, and edit those components but although editing result is visible in Tridion (in the component itself) somehow this is not "picked up" in the current publishing. Commented Apr 30, 2015 at 11:57
  • Hi Bart, tnx for the Handler example. I need to add/update component metadata with appropriate taxonomy before component is published (not saved, as it is too dynamic) so that content can be correctly queried on CD side. This should also match CM taxonomy so that Content Editors know what they are doing. Commented Apr 30, 2015 at 12:41
  • @user3760419 please edit your question and add that useful information in there. Don't expect everybody to read the little comments and also don't exppect me to be the only one answering you ;o) Commented Apr 30, 2015 at 13:10
0

You might consider a solution that has an event on a taxonomy-related item, and when that is updated, find the related Comps / Pages and update them. If the process of finding the comps to update is time-consuming or a challenge, you could possibly persist that data in your own small custom DB sitting next to the Tridion CMS DB, or even locally on the filesystem using SQLite.

Taking actions during publishing is not so good since they add TIME to publishing. If your average publish time is 2 seconds, and you add .5 seconds, maybe that is OK, or maybe not. Just something everyone should be conscious of.

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.