Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Darren Brennan 2 posts 72 karma points
    Aug 22, 2018 @ 15:09
    Darren Brennan
    0

    Sync Source config. Writes to disk on Save or Save and Publish?

    I have a question around the Config for Sync Source.

    In the config settings you have the Sync Source setting where it saves any changes to disk. Can you tell me is this change is when you Save or when you Save and Publish?

    If it is only when you Save, is there any way to modify the code so that it only writes to the disk when you Save and Publish?

    Thanks Darren

  • Kevin Jump 2309 posts 14673 karma points MVP 7x c-trib
    Aug 22, 2018 @ 18:58
    Kevin Jump
    0

    Hi Darren,

    The default is when you save (so also save and publish) - mainly because uSync deals with a lot of things that don't have the concept of publish so only save.

    but you could extend it with your own code to be only publish (for content). first you would want to turn of save events.

    so if you register for umbraco's publish event :

            Umbraco.Core.Services.ContentService.Published += ContentService_Published;
    

    you can then work through any items that are published, get the XML from uSync and save it how you wish.

        private void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
        {
            foreach (var item in e.PublishedEntities)
            {
                var attempt = uSyncCoreContext.Instance.ContentSerializer.Serialize(item);
                if (attempt.Success)
                {
                    // at this point the attempt.item value is an XElement 
                    // so you can save it somethere
                    // uSync builds a path based on parents, but if doesn't 
                    // have to be that it can be anything 
                    attempt.Item.Save("some/file/path");
                }
             }
        }
    

    uSync has a GetContentPath function which builds a path based on the node names, but it can be anything.

    and if you did save this into the uSync/Content then a importing usync at the other end would import the content (which is i suspect what you want to do ?)

    the actual folder names in the don't matter when it comes to importing all the data comes from the files.

    the only thing to note about the folder structure if you are importing is that there there something to ensure the parent nodes are higher then their child nodes so they get imported first.

  • Kevin Jump 2309 posts 14673 karma points MVP 7x c-trib
    Aug 22, 2018 @ 19:03
    Kevin Jump
    0

    Also worth noting if you don't want to turn the export of for everything then it can be done on a per handler basis - see the docs for some info.

    https://usync.readthedocs.io/handler-config/

    but without turning off the main ExportOnSave setting you could just turn off saves of content with

    <HandlerConfig Name="uSync: ContentHandler" Enabled="false"/>
    

    which will just stop the built-in content handler from doing anything on that instance of the site. while everything else would still export on save.

Please Sign in or register to post replies

Write your reply to:

Draft