简体   繁体   中英

Sitecore publish:end event interaction with user

I have a publish:end event handler, and if there is any errors with it, I would like to show it to the user. Is there any way to do this? Can I hook into something to show messages on the publish end screen (or before anywhere)?

Your question intrigued me, because this one of those things that I expect to be possible with Sitecore, but no one really takes the time to find out how. So I dove into it and I'm pleased to say that it's possible, to a certain end!

In your event handler that is called on publish:end you can look up the publish jobs that are currently running. Once you get the jobs, you can modify its status messages:

var publishJobs = Sitecore.Jobs.JobManager
    .GetJobs().Where(x => x.Category.Equals("publish"))
    .ToList();

publishJobs.ForEach(x => x.Status.Messages.Add("This is a message inserted by the publish:end event"));

The result will be displayed on the last page of the publication dialog in the Results textbox.

在此处输入图片说明

The thing with the results textarea is that you only see if you click the 'Click here to see additional information' link.

To change that behaviour, you need to modify the dialog XML which is located in /sitecore/shell/Applications/Dialogs/Publish/Publish.xml . In there you can set the result textarea to be always visible.

There is one drawback though: you can't know which job is your publishing job...

Each job has a handle assigned to it which is basically a Guid and some info about the server and site, but in your event handler you don't have this information ( or at least I can't find it ).

I think in most cases it's no problem to simply add the message to all running publish jobs (after checking if it's already there), but it's something to take into account.

Hope this helps!

I don't think you can notify the user directly because publish:end is executed on another thread which doesn't know about the Sitecore interface. You can send the user an email.

You can also add the publishing status content editor warning to let editors know whether the publish completed successfully.

I have installed the publishing status on all the sitecore sites I have worked with and users find it very useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM