Sitecore provides a built-in feature for automatic content publishing, which is easy to enable. The example below is based on Sitecore 6.5.
Note: Don’t set up automatic publishing for sites which don’t have proper workflows in place — that’s basically equivalent to running the site in “Live Mode”.
Most sites contain some sort of time sensitive information which must be published and unpublished at predefined points in time: press statements, limited time offers etc.
This is possible by setting the “Publishable From” and “Publishable To” date and time properties for an item, using the “Publish”-ribbon and “Publishing Settings”-dialog.
Publishing content at regular intervals provides the following benefits:
- Authors don’t have to publish content, which means one less task in their daily rutine. Time == money == automatic publishing, due to the minutes saved every day by employees not having to publish manually.
- Authors can use Sitecores publishing restrictions to release content any time and day, regardless of office hours.
- Webpages are no longer defaced by authors who publish content piecemeal and forget (media-)items that are referenced by their newest creation.
- Excessive publishing can degrade site performance: With automatic publishing in place it’s perfectly possible to revoke the publishing role from “trigger happy” (or forgetful) authors, thus preventing the HTML cache from being cleared every few minutes. On most sites I’ve worked on the standard content author role is not granted publishing rights for this exact reason.
By default Sitecore is not set up for automatic publishing — which means that setting the publishing interval for an item has no effect unless a content author manually triggers a publish after “Publishable From” and “Publishable To” have been reached, respectively. This is easily remedied by following the steps outlined below.
Copy the XML below into a config-file (e.g. “PublishAgent.config”) and put it into your “[webroot]/App_Config/Include”-folder. Sitecore will merge these settings into the main Web.config file when your site starts up.
Practically the lower limit of the publishing interval is equal to the interval set in the node “/configuration/sitecore/scheduling/frequency” in Web.config (expressed as XPath), which is 5 minutes by default.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <scheduling> <agent type="Sitecore.Tasks.PublishAgent"> <!-- The time format is "HH:MM:SS" --> <patch:attribute name="interval">00:30:00</patch:attribute> <param desc="source database">master</param> <param desc="target database">web</param> <!-- Despite the description, "smart" publish is usable as well --> <param desc="mode (full or incremental)">smart</param> <param desc="languages">en, da</param> </agent> </scheduling> </sitecore> </configuration>
Once the include-file is deployed, the Sitecore log files should start showing entries like the following:
ManagedPoolThread #n HH:MM:SS INFO Job started: Publish to 'web' ManagedPoolThread #n HH:MM:SS INFO HtmlCacheClearer clearing HTML caches for all sites (X). ManagedPoolThread #n HH:MM:SS INFO HtmlCacheClearer done. ManagedPoolThread #n MM:MM:SS INFO Job ended: Publish to 'web' (units processed: Y)