The customer wanted the ability to suspend scheduled publishing, but could still make manual publishes (i.e. started from the Sitecore client).
Each time a publish is started it runs the publish pipeline. Therefore it is possible to insert a custom pipeline step at the beginning (see below) to do the following:
- Identify if it was a scheduled publish
- Check if a check-box in Sitecore is ticked
- If both conditions are met – abort the publish pipeline to stop the publish
Unfortunately aborting the publish pipeline is not enough 😦
In the initial code I would abort the pipeline using AbortPipeline() (see below) as I assumed this was enough to stop the publish. The pipeline was aborted and no items were published, but the code that starts the pipeline still updated the properties table indicating that the publish had succeeded:-(
Side affect
This had the side effect that when the schedule publishing was enabled again, any items that were modified or created whist the publishing was disabled would not be published as when scheduled publishing was resumed Sitecore believed that they had already been published.
Solution
After checking the code using reflector I determined if I threw an exception, it would ensure that the properties table was not updated. So the publish was completely cancelled, and when scheduled incremental publishing was resumed it will publish all the items that have been modified since the last successful publish, and not since the last aborted publish.
How to identify a scheduled publish
Not the nicest solution but it works! I check the publish context user which can have the following values:
- The user logged into sitecore – If publish is started from the Sitecore client
- sitecore\Anonymous – if the publish is started by the scheduler
If the value is sitecore\Anonymous I know that it is a scheduled publish.
Hi Alan.
We are checking “the publish type” (manual or scheduled) exactly in the same way 🙂
Great post.
But I was confused with the sentence cast an exception.. untill I found out you were talking about throwing an exception. I was looking for an exception cast eg. (MyException)ex 😉
Good point 🙂 not sure why I always say casting instead of throwing?? But I’ll fix that, cheers for the feedback
Cast a spell, cast an exception. Using the Magician icon for your Sitecore account? 🙂
Have you reported this to Sitecore support?
If not, then I encourage you to do so.
Throwing an exception is never a good solution 😃
Support know about it 🙂