2

We are using Sitecore SXA for development.

Right now we are able to sync into Sitecore everything(based on serialization configuration) using unicorn through yml files. if deleted yml file, it is deleting from content tree also.

Now I want to change this sync process for a specific section of content tree like Data, Presentation, Settings etc. I want to sync only newly added yml file and want to ignore updated or deletd yml files and also want to keep as is if any new item created in content tree by an author even no yml file exists for that.

What changes do I need to make in the configuration to achieve above requirement?

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <unicorn>
      <configurations>
        <configuration name="Project.Corporate.Website" description="media items." dependencies="Foundation.*" patch:after="configuration[@name='Foundation.Serialization']">
          <targetDataStore physicalRootPath="$(sourceFolder)\project\Corporate\serialization" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" />
            <predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true">
                <include name="Media" database="master" path="/sitecore/media library/Project/Corporate" />
            </predicate>
        </configuration>
      </configurations>
    </unicorn>
  </sitecore>
</configuration>

Thanks a lot in advance.

1 Answer 1

3

You can do this by using the NewItemsOnly evaluator in your configuration. You would need to setup multiple configurations for this tho as you can only use one evaluator per configuration.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <unicorn>
            <configurations>
                <configuration name="SXANewItemsOnly" description="Only sync new items for the SXA Data, Presentaion and Settings folders">
                    <!-- swap the evaluator to the different implementation (see <defaults> in Unicorn.config for a full list of things you can replace like this) -->
                    <evaluator type="Unicorn.Evaluators.NewItemOnlyEvaluator, Unicorn" singleInstance="true"/>

                    <!--
                        Note: when using custom evaluators keep Transparent Sync OFF for those configurations (the line below).
                        Transparent Sync operates by reading from the serialization store directly.
                        In other words transparent sync always acts like SerializedAsMasterEvaluator because disk is LITERALLY the master.
                        See https://github.com/kamsar/Unicorn/wiki/The-Transparent-Sync-Guide
                    -->
                    <dataProviderConfiguration enableTransparentSync="false" />

                    <predicate>
                        <include database="master" path="/sitecore/content/my-tenant/my-site/data" />
                        <include database="master" path="/sitecore/content/my-tenant/my-site/presentation" />
                        <include database="master" path="/sitecore/content/my-tenant/my-site/settings" />
                    </predicate>
                </configuration>
            </configurations>
        </unicorn>
    </sitecore>
</configuration>

You would need to make sure there was another configuration that runs before this that syncs the root items of the site, otherwise it would fail. You can make sure of the configuration order using dependencies in Unicorn. There is an example in the Unicorn source code on github: https://github.com/SitecoreUnicorn/Unicorn/blob/master/src/Unicorn/Standard%20Config%20Files/Unicorn.Configs.Dependency.config.example

The NewItemsOnlyEvaluator - syncs exactly as you have described. It will only add the item if the item does not already exist. If items are added by content editors, they will not be removed, and if items are edited, they will not be overwritten.

There are some caveats to this tho. If an item is deleted in the target database, on the next sync it will be re-added. Because Unicorn will see that the item is not there and therefore must be new.

Also - I would be selective about which areas of the site you use for this. Normally I would only use this with content areas. The Presentation and Settings do contain areas that should be source controlled. E.g. rendering variants. If you have the rendering variants set as NewItemsOnly then that means updates to the rendering variants would not get sync'd as the items would already exist. So think about the items in the tree and decide which ones should be new items only and which should not.

1
  • thanks a lot for quick response. it worked for me.
    – Erwin Paul
    Nov 30, 2018 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.