Richard Read
Richard Read

Reputation: 923

Events System - Possible to publish another page when page is being published?

I have a question about the events system in Tridion 2011.....would it be possible to publish another page when other pages are sent to the publishing queue?

We currently have an XML file that defines our site navigation and sitemap, but unfortunately currently needs manually publishing each time a new page is added to the website.

My concern I have about auto-publishing from the events system as well is having to publish the same page several times, when really it would only need publishing after the final item in the publishing queue has ended its transaction.

Upvotes: 6

Views: 760

Answers (3)

Frank van Puffelen
Frank van Puffelen

Reputation: 600090

Whenever you want to change how many items are being published by Tridion in response to a publish action, my mind immediately screams custom resolver.

Chris Summers did a great write up of his experience with them a while ago: http://www.tridiondeveloper.com/the-story-of-sdl-tridion-2011-custom-resolver-and-the-allowwriteoperationsintemplates-attribute

Nuno wrote his experience up a bit more concisely: http://nunolinhares.blogspot.com/2011/10/tridion-publisher-and-custom-resolvers.html

It sounds to me like you should simply add your navigation to the ResolvedItems collection there. If you use resolvers consistently, you also won't get this explosion of publish transactions that you seem worried about and instead will have all related items published (and deployed) in a single transaction.

Upvotes: 8

Arjen Stobbe
Arjen Stobbe

Reputation: 1684

You could publish the Sitemap per transaction (that can contain many pages, structure groups, etc.) by subscribing to the PublishTransaction Save event.

You could consider verifying the publish queue and see if there are waiting transactions, but in theory this could postpone the Sitemap to be published for a very, very long time.

EventSystem.SubscribeAsync<PublishTransaction, SaveEventArgs>(
    (subject, args, phase) =>
    {
        if (!PublishStransactionStateIsSuccessfullyCompleted(subject))
            return;

        // Code to publish sitemap
    },
    EventPhases.TransactionCommitted
);
static bool PublishStransactionStateIsSuccessfullyCompleted(PublishTransaction transaction)
{
    return transaction.State == PublishTransactionState.Success ||
            transaction.State == PublishTransactionState.Warning;
}

Upvotes: 7

Bart Koopman
Bart Koopman

Reputation: 4835

This is something that comes up a lot of times during an implementation, certainly with navigation or sitemaps that are depending on published items (which is not an ideal situation in my opinion).

A possible solution for this would be that you use the Event System to place the Page which generates your XML in the Publishing Queue with low priority. This will make (somewhat) sure that it is only published after your regular publish actions are executed. Now secondly the event should check whether this Page is already in the queue, so it doesn't add it a second time.

Keep in mind, this does not prevent it from being published multiple times a day, but it should at least make sure it is never in the queue twice. On a fast system with a dedicated multi threaded publisher, it could very well mean that it still gets published every hour or so depending on your activity etc.

Another option would be to schedule publishing once a day of that Page, using the Event System to repeat that process, so that every day at the same time it is published only once. This will reduce your accuracy of your XML since it only gets updated once a day, but it will prevent your Publishing Queue from being filled too much might that be an issue.

Upvotes: 4

Related Questions