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:-(
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.
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.