Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get resourceName for Tridion LocalizableMessage when creating new PublisherException?

Tags:

tridion

I need to stop publishing of a page when a certain condition exists, for example if the page name contains 'one' using the Event System. Also, the other pages should continue to publish.

I am thinking to use a PublisherException instead of a generic exception.

The problem is the I do not know the resourceName of the LocalizableMessage. Any ideas?

if (item.Title.ToString().Contains("one"))
{
     Localization.LocalizableMessage errResource = new Localization.LocalizableMessage("error");
     throw new PublisherException(errResource, new Exception("Can't get there from here!"));
} 
like image 945
robrtc Avatar asked Dec 26 '22 13:12

robrtc


2 Answers

The Event System can stop Publishing, there is no middle ground there though, when you throw an exception, it stops the entire transaction.

Like Puntero mentions, if you want to remove an item from a Publish Transaction, that is where a Custom Resolver comes in. From here you cannot communicate back to the Publish Transaction, but you have access to the Tridion Logger (eventlog):

Tridion.Logging.Logger.Write("your message string", "MyResolver", LoggingCategory.General, TraceEventType.Information);

With regards to your LocalizableMessage in the Event System, you should be able to do the following:

throw new PublisherException(new LocalizableMessage(Properties.Resources.ResourceManager, "PagePublishErrorMessage"));

Where the resourceName is pointing to the name of a String resource you have in your Project.

like image 85
Bart Koopman Avatar answered Apr 24 '23 09:04

Bart Koopman


I agree with @Puntero that if you want other page in a publish action to go through, you should use a Resolver rather than an Event Handler.

I tried to raise a warning to alert users of one item not being resolved, but failed. But there may be some good tips/ideas for you here: Raising a “warning” status during SDL Tridion 2011 publishing

In the end, the only way I could get anything to work was to set "Allow X failures", and then do a check in a template, and raise the error there. That will count as a Render failure, and allow the publisher to move on to the next item in the publish transaction.

As for the message? What message would you like to display?

like image 22
Chris Summers Avatar answered Apr 24 '23 09:04

Chris Summers