Tuesday, May 26, 2015

Using the package designer to sync Sitecore content between environments


The Sitecore 8 package designer allows you to create a package (zip file) with selected Sitecore items which can then be imported into another Sitecore installation. An example of where this might be useful is moving content, templates and layouts from a development environment to a test or production environment.

Creating the XML project

An XML project is the settings/variables for a given package. This project can then be run to create the actual package (which contains the Sitecore content) and even exported/imported itself so that you can generate the same packages on multiple environments.

To create an XML project, load up the Sitecore administration desktop. Click the start menu, then Development Tools and then Package Designer. You will be greeted with a form for creating your XML project, the fields (apart from Package Name) are all optional, but generally it's a good idea to specify the author, a version and perhaps some documentation notes.
You now have the option to specify which items/files to include both statically or dynamically. As all of my layouts physical files are inside a visual studio solution (which itself can be deployed), I won't need to include files in this package. Because this package needs to be re-usable I will be taking items dynamically (if you have a set of files which will not have additions/deletions you could create a dynamic package just for them). Click on the Items Dynamically menu item and the following screen will appear:
Select the root template item, or if you have created a folder under templates with all of your custom templates select that. Click Next and you will be prompted to add a filter to which items to include, in this example I want to take everything so enter no filters and click Next again. Now give your source a name, in this case I used "MyPackage_Templates_Source". A package can have multiple sources, so you will want to create one to cover all of the Sitecore items you have configured, in this case I have taken Content, Templates and Layouts:
It is also important which order these sources run in, templates should be first because the content items will have content assigned to fields on the templates. If you don't import templates first all of the custom fields (from the templates) will be blank.

Once you have chosen all of the sources, click the Save As button to save the XML project. Your projects can now be opened, downloaded and then imported into other Sitecore instances.
In this example (for demonstration purposes) I have selected entire content trees from Sitecore which can make for some very large packages. Generally you would want to become very granular to ensure you only package up the content which is custom from the base Sitecore. Using filters under Items Dynamically or by selecting the precise Items Statically, Sitecore allows you to create minimal packages which allow the right Sitecore content items to be synced between environments.

Creating the package

Once you have defined an XML project you can then run that project to generate a zip file. Click Open off the main menu of the Sitecore Package Designer and select the XML project you wish to run. Once open, click Generate Zip on the main menu.
Give the zip file a meaningful name (perhaps indicating the project being run and a timestamp), then click next. The zip file will begin to generate (which may take several minutes) and once complete a confirmation box will popup with a link to download the Sitecore package (in zip file format).

Importing the package

Once you have downloaded a package you can then import it into another Sitecore instance. Load up the Sitecore administration desktop and click the start menu, then Development Tools and then Installation Wizard. Click the Choose package button, here you are able to upload your package (and select it) or select a package you have uploaded previously. Once you have selected a package, click the Open button, and then Next where some of the package details (entered during the XML project creation stage) will show. 
Click the install button and the package installation will begin. You may be promoted with messages when an item in the package is already installed on the Sitecore instance. Generally I will select Overwrite and click Apply to all because this ensure the environments are the same when it comes to GUIDs of Sitecore items.
The installation may take several minutes to complete, but once finished you will see a message with the option to restart the client or server, I generally restart the client. 
Now you should deploy any code to the server as required and perform a full publish in Sitecore. Now both of your Sitecore environments should be synced and running the exact same content and code.

No comments:

Post a Comment