Event system - is it possible to publish another page when publishing a page?

I have a question about the event system in Tridion 2011 ..... is it possible to publish another page when other pages are sent to the publication queue?

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

My concern that I have about auto-posting from an event system is also to publish the same page several times when you really need to post after the final item in the publish queue completes the transaction.

+6
source share
3 answers

You can publish a Sitemap for each transaction (which can contain many pages, group groups, etc.) by subscribing to the PublishTransaction publication event.

You can consider checking the publication queue and see if there are pending transactions, but theoretically this could delay the Sitemap, which will 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; } 
+7
source

Whenever you want to change the number of articles published by Tridion in response to the publishing action, my mind immediately screams a user recognizer .

Chris Summers wrote great about his experience with them some time ago: http://www.tridiondeveloper.com/the-story-of-sdl-tridion-2011-custom-resolver-and-the-allowwriteoperationsintemplates-attribute

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

It seems to me that you just have to add your navigation to the ResolvedItems collection. If you use resolvers sequentially, you also wonโ€™t get this explosion of publishing transactions that you seem to be worried about, and instead will have all the related items published (and deployed) in one transaction.

+8
source

This is something that occurs many times during the implementation, of course, using navigation or Sitemaps, which depend on the published elements (which, in my opinion, is not an ideal situation).

A possible solution for this would be to use an event system to host the page that generates your XML in the low priority publication queue. This will make (somewhat) certain that it will be published only after your usual publishing actions are completed. Now secondly, the event should check whether this page is already in the queue, so it does not add it a second time.

Keep in mind that this does not prevent him from publishing several times a day, but at least he must make sure that he is never in the queue twice. In a fast system with a dedicated multi-threaded publisher, this may well mean that it is still published every hour or so depending on your activity, etc.

Another option is to schedule the publication once a day of this page, using the event system to repeat this process, so that every day at the same time it is published only once. This will reduce the accuracy of your XML as it is updated only once a day, but it will prevent the publication queue from overflowing. Perhaps this is a problem.

+4
source

Source: https://habr.com/ru/post/921960/


All Articles