Source Control for my content

Leave a comment

September 5, 2008 by Alistair Deneys

Sitecore already has version control built in for content. This is great when you’re using the CMS to deliver content, but during implementation the benefit isn’t as great. What would be really good, is if I could somehow utilise my existing source control software which I use for my developer files for the content as well.

Ah, Sitecore 6.0. With it’s wealth of new features and usability improvements has answered my prayers. But not before Revolver! Sitecore 6.0 introduced a new feature on the developer tab in the content editor which gives me the ability to serialize content items and subtrees from the content tree to files on disk. The items are serialized into a very light custom text format, not XML.

Revolver has allowed me to serialize items and trees to disk in their XML representations since before version 1.0 was released, and this is available for Sitecore 5.3.x and 6.0. The item serialization from the developer toolbar above is only available in Sitecore 6.0.

To use the content editor approach we first need to ensure the developer tab is displayed. Open the content editor and right click on the ribbon, then from the resulting popup tick the developer option. This will display the developer tab on the content editor.

developer tab

Once you have selected the developer tab you will notice the new Serialize chunk. To serialize an item to disk I just use on of the serialize options to either serialize a single item or the current subtree starting at the currently selected item. Alex de Groot recently did a few posts on these new features and also a good video showing off the new features. I won’t repeat what he said, so go and check out Sitecore 6 serialization part 1 and Sitecore 6 serialization part 2

The files are going to land in the data folder under a new folder called serialization. Once here we can put them into source control quite easily.

An alterative to the above approach, or if you’re on Sitecore 5.3.x, is to use Revolver. We can combine the gi command which gets an items XML, with the echo command to write that data to any file. gi also accepts a parameter -r which will grab the XML for this item and it’s children (subtree). The nice thing (or dangerous depending on how you look at it) is that I can put the file anywhere on disk. Oh, and that’s the other thing. Revolver will output a single file and Sitecore item serialization above will output many little files.

So here’s some Revolver commands to output first a single item, then a subtree:

echo -f c:\temp\item.xml < gi
echo -f c:\temp\tree.xml < (gi -r)

To restore items into the tree I have to use the touch command combined with the echo command. Placing the -i parameter on the echo command now reverses the direction of the file operation. Instead of writing to file, I’m reading from file directly into Revolver.

touch -x < (echo -i -f c:\temp\item.xml)

I need to take a little more care when using Revolver as I can move the items around. The Sitecore item serialization takes care of all that for us.

And again, once the file is on disk we can just pull it into source control very easily. How do you choose which one to use? A lot will come down to preference. The rest will come down to how much control I want over where the items are serialized on disk and how they get deserialized.

If I were to go the Revolver path, I would highly suggest writting some scripts to take care of this and to keep a consistent location on disk.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

The views expressed on this blog are solely my own and do not necessarily reflect the views of my employer.
%d bloggers like this: