Copied to clipboard

Flag this post as spam?

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


  • Francis 23 posts 123 karma points
    Jun 08, 2022 @ 17:36
    Francis
    0

    USync Node and Property Level Exclusion

    Hello Our,

    I wonder if you can help me out. I'm using uSync and included the contentHandler in the sync. This means I'm also pushing out some content node updates. Problem is there are some nodes that hold data that cannot be overwritten. I have 2 questions for this:

    1.) How can I specify which content nodes to include on the sync? 2.) How can I exclude certain node properties/ property groups in the sync?

    I'm using:

    • Umbraco CMS 9.5
    • Usync 9.2.0

    Thanks in advance

    Francis

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Jun 09, 2022 @ 07:55
    Kevin Jump
    0

    Hi Fancis,

    There is inbuilt config to ignore content on a path / doctype level but not properties or property groups :(

    To do this you will have to intercept some of the notifications that uSync fires when it imports/exports an item.

    I think the simplest way might be to have a Notification Handler that handles the uSyncImportingItemNotification event, and then remove the properties by name from the node xml this passes ?

    something like (sorry haven't had chance to actually test this code)

    public class NotificationTest : INotificationHandler<uSyncImportingItemNotification>
    {
        private static string[] dontImportItems = new[]
        {
            "twitterUsername", "sku"
        };
    
        public void Handle(uSyncImportingItemNotification notification)
        {
            var properties = notification.Item.Element("Properties");
    
            foreach(var element in properties.Elements())
            {
                if (dontImportItems.InvariantContains(element.Name.LocalName))
                    element.Remove();
            }
        }
    }
    

    for content uSync won't remove values that aren't in the xml, so by taking them out of the content xml - usync will ignore them on import (it only removes properties if they are missing from the doctype xml)

    Kevin

  • Francis 23 posts 123 karma points
    Jun 09, 2022 @ 09:26
    Francis
    0

    Hi Kevin,

    Thank you for the quick response. I will try the suggestion. Just a follow-up question. Where does this code have to sit in order for the intercept to fire. Will a Composer work or it should be someplace else?

    Regards,

    Francis

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Jun 09, 2022 @ 09:28
    Kevin Jump
    0

    Hi yes, you need to register the event in a composer.

    e.g

    builder.AddNotificationHandler<uSyncImportingItemNotification, NotificationTest>();
    
  • Francis 23 posts 123 karma points
    Jun 09, 2022 @ 09:37
    Francis
    0

    I appreciate the help Kevin. I will try these suggestions and get back to you.

    Thanks!

  • Francis 23 posts 123 karma points
    Jun 14, 2022 @ 09:08
    Francis
    0

    Hi Kevin,

    Just to give an update on my progress. I haven't tried using the INotificationHandler route yet but I got curious by your comment that if I remove the XML property, that portion will not be imported. So tested it and it turns out it works:

    <styleMap>
      <Value><![CDATA[{"bgStyle":"solid","bgOverall":"#000000"}]]></Value>
    </styleMap>
    

    So in this example, if I remove the entire "

    However, If I remove just one of the properties, e.g., {"bgStyle":"solid"}, content import detects that as removing of the value on the target site which instead of leaving it alone. Perhaps, instead of removing it, I can assign empty value?

    Anyway, as you can see I have some more testing to do. I'll also let you know once I've tried that INotificationHandler option.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft