Thursday, July 05, 2012

Sitecore Pre-Production Preview


It’s time to revisit my old blog series from a couple of years ago. I’ve blogged about ways to setup a pre-production preview environment back in 2009 and 2010. I suggest reviewing those before reading this post further, as I am not going to provide a lot of context. Since the last post, I was getting even more questions about how to set this up, so here is another take on the same problem that involves less customization, and in my book, it’s much easier to setup.

The idea is simple and rotates around the notion of running kind of a “Live mode” on separate Pre-Production Preview server.
This server will source out content from the master database instead of “pre-prod web” database. This will let you get away from using publishing, thus reducing complexity.

User Story:
As a content user I should have ability to access pre production version of my website without the need to log into Sitecore authoring environment. I also need to send a link to my management before a page goes live. I want the pre production environment to show items only from specific workflow state (i.e. only items in ‘Pre-Approved’ state, but not in ‘Draft’ state).

Pre-requisites:
- Workflow present and configured

Optional:
-  Dedicated Pre Production Preview Sitecore instance (not required but this solution, but may be a good idea if you have integration dependencies that are not present in the Authoring environment)
- ScalabilitySettings enabled (EventQueue) – needed if dedicated instance is setup.

Solution:

1. Enable “LiveMode” with ‘enableWorkflow’ flag disabled and custom ‘filterByWorkflow’ flag enabled:

<site name="website">
  <patch:attribute name="database">master</patch:attribute>
  <patch:attribute name="filterItems">true</patch:attribute>
  <patch:attribute name="enableWorkflow">false</patch:attribute>
  <patch:attribute name="filterByWorkflow">true</patch:attribute>
</site>

2. Extend the “FilterItem” pipeline by adding a custom processor performing filtering by workflow state:

<pipelines>
  <filterItem>
    <processor patch:before="*[@type='Sitecore.Pipelines.FilterItem.EnsureFilteredItem, Sitecore.Kernel']"
               type="scLabs.PreProdPreview.Pipelines.FilterItems.FilterByWorkflowState,scLabs.PreProdPreview" />
  </filterItem>
</pipelines>

3. Deploy this to the Sitecore instance acting as a pre-production server (there is no need to deploy this to the Content Delivery servers).

I should mention that enabling the “FilterItem” pipeline puts extra pressure on item resolving, so if you consider implementing this on the Authoring server and it is already running out of juice, setting up a dedicated Sitecore instance would be a good idea.

Complete Solution can be found here on GitHub. Another disclaimer: though I’ve seen similar solutions working in production environments, this particular code is still experimental, so no guarantees. Carefully test this before going live with it.

Hope this is going to work beautifully for your needs. Any feedback is appreciated!

4 comments:

Mark Ursino said...

Nice post Alex. We've done this for clients before with a "preview" host. Some challenges though:

- Any front-end Lucene.NET indexes won't work if this uses the master DB. An option is to maintain two sets of indexes, one for web (normal) and one for master (preview) then write code to handle that, e.g. a smart property to get the right index:
public string PublicationsIndex {
get {
if(siteIsPreview)
return "PublicationsPreview";
return "Publications";
}
}
- HTML output caching basically needs to be off

Alex Shyba said...

Thanks for the comment, Mark!
Both points are absolutely valid for dedicated preview host. As for the Lucene, in reality, the proper config will be no different from the mutli-authoring setups.
Since there is publishing in place, HTML cache is a problem in any LiveMode derived configurations, since there is no publishing required for the updates to show up. One way to go about it is configure time based html cache clearings. In such preview environment it should not be a biggie to disable HTML cache completely. As long as you don't have anybody or anything hammering the box ;-)

Thanks for the feedback!

Pravin Giradkar said...

Hi Alex,

Can I publish to prod server from preview host ?
Will my workflow fired up ?

Pravin Giradkar said...

Can I publish to prod server instance from this preview host ? Will my workflow trigger ?