1
votes

Issue: Unable to catch if publish item to TargetDatabase fails.

In sitecore UI, When I publish an item from master database to web database(Target Database), I wanted to check if publish was successful before it shows in UI.

looking at the following post from John West about the pipeline order: http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2011/08/intercept-item-publishing-with-the-sitecore-aspnet-cms.aspx

I've added the following publish item processor:

 <processor patch:after="*[@type='Sitecore.Publishing.Pipelines.PublishItem.PerformAction, Sitecore.Kernel']" type="BOTWLibrary.Pipelines.EvaluateResult, BOTWLibrary"/>

In EvaluateResult.cs

public class EvaluateResult : PublishItemProcessor
{
    public override void Process(PublishItemContext context)
    {
       // check if publish was successful.
    }
}

Thanks in advance.

1

1 Answers

0
votes

If the publish fails it will set the results operation to none, as well as give a reason for the unknown publish action. This isn't a guarantee that the publish failed but I think it's the closest you'll get.

public class EvaluateResult : PublishItemProcessor
{
    public override void Process(PublishItemContext context)
    {
        // check if publish was successful.
        if(context.Result.Operation == PublishOperation.None)
        {
            throw new Exception(context.Result.Explanation);
        }
    }
}