This post follows on from Migrating Sitecore content and looks to explain the way we migrate content between different environments.
Sinj is the framework we’ve put in place to facilitate a re-playable and scripted approach to any Sitecore changes. It enables you to create changesets via JSON/Javascript which then get run against a Sitecore authoring environment and any counterpart publishing targets. The code can be found at https://github.com/tcuk/sinj.
For any setup instructions have a look a the wiki on github. It also contains examples of the different kinds of operations you can run against your content. As the js layer talks into the Sitecore API, if you find there is an operation you need to perform but can’t it can simply be extended to add the desired functionality.
An example script for creating a template would be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
var pageFieldSection = { id: "{94d6f0d3-6453-4ffb-93fc-8fcf851dd56c}", name: "Page", parent: "/sitecore/Templates/Redesign/Field Sections", sections: [ { name: "Page", id: "{c5522e00-15d8-4295-b3d7-bb7c45089a1c}", fields: [ { name: "Page Heading", id: "{D18F5AC7-0FA0-4F37-B553-FF66A694566C}", type: scFieldTypes.Text }, { name: "Page Body", id: "{64C2AEE3-24B3-46DE-8508-DE51ADB92321}", type: scFieldTypes.HTML } ] } ] }; for (var i = 0; i < databases.length; i++) { var database = databases[i]; $sc.log("Running against database '" + database + "'"); $sc.use(database); scInsertTemplate(pageFieldSection); } |
Now this may seem overly verbose however there are easy ways to speed up the JSON generation. I’ll cover these in a subsequent post.
For me the real advantages we gain from this approach are:
- Changes are as granular as you want – they can be applied to specific fields in specific languages on specific versions if desired.
- However, if you want to update all languages in one go, its simply a case of iterating through each language in a for loop
- Bulk sets of changes can be applied in one go. By simply including all the JS files you wish to deploy in one folder then all will get applied in sequence
- You can run the scripts to any database, avoiding any need to publish scattered areas of the tree
- Changesets can be replayable and don’t have the somewhat confusing concept of: overwrite/merge (and it’s options)
- You can query the Sitecore tree to gather data to feed into other updates
In the next post I’ll show some examples of how creating Sinj scripts can become a lot simpler…