Copied to clipboard

Flag this post as spam?

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


  • Huw Reddick 533 posts 1723 karma points
    Feb 15, 2021 @ 07:37
    Huw Reddick
    0

    excluding specific content when synchronising

    Is it possible to exclude particular content from the sync?

    We have a shop section where the products are synchronised from another system, so synching them through converge is not required, would be handy to have some kind of exclusion list.

  • Stuart Mullinger 63 posts 289 karma points
    Feb 15, 2021 @ 10:39
    Stuart Mullinger
    0

    Hi Huw, there is a way to set the default action for certain content, in this case you can automatically set it to Ignore. Take a look at the "Default Action Setter" section in the documentation.

    I can immediately see that this is quite limiting as you only have the name to go on. I will take a look at including the path in the GetDefaultAction() function.

    Another approach could be to set up specific users on both the remote and local sites and use Umbraco permissions to stop access to the shop section. Then use those users when using Converge.

  • Huw Reddick 533 posts 1723 karma points
    Feb 15, 2021 @ 11:02
    Huw Reddick
    0

    Thanks for the pointer, I will take a look at creating an action setter for my products.

  • Huw Reddick 533 posts 1723 karma points
    Feb 15, 2021 @ 15:43
    Huw Reddick
    0

    Hi Stuart,

    I gave it a try, but don't see how I can get it to ignore all the products

    Basically I have a Shop page that has children who are 'product' (doc type alias) created as below

    _contentService.Create(productname, shopId, "product");
    

    I want to ignore all these 'product' when synching, can't see how I do that using the defaultactionsetter interface,

  • Stuart Mullinger 63 posts 289 karma points
    Feb 15, 2021 @ 16:49
    Stuart Mullinger
    100

    I realised earlier that just having the name would be limiting. Currently working on adding the path to that function, that will allow you to identify the position in the content tree.

    The only other solution I can think of is to use the ContentService within the DefaultActionSetter to check if it is a "product". Something like (untested):

            var productContentType = Umbraco.Core.Composing.Current.Services.ContentTypeService.Get("product");
            if (productContentType != null)
            {
                long numRecords;
                var productContent = Umbraco.Core.Composing.Current.Services.ContentService.GetPagedOfType(productContentType.Id, 0, int.MaxValue, out numRecords, null).FirstOrDefault(c => c.Name == itemName);
                if (productContent != null)
                {
                    action = MergeAction.Ignore;
                }
            }
    

    Not sure how you set up the "filter" parameter, but that may help. You could pre-load products into a List<string> if speed is an issue.

  • Stuart Mullinger 63 posts 289 karma points
    Feb 15, 2021 @ 16:57
    Stuart Mullinger
    0

    That would only work if the product exists locally.

  • Huw Reddick 533 posts 1723 karma points
    Feb 15, 2021 @ 17:20
    Huw Reddick
    0

    Thanks for info, I will try that, theproducts do exist in both local and remote, I just don't want to synch incase the prod version has had any properties updated (description/image etc, but they should at least exist in both systems.

  • Huw Reddick 533 posts 1723 karma points
    Feb 16, 2021 @ 09:03
    Huw Reddick
    0

    worked a treat, thanks for the help.

  • Huw Reddick 533 posts 1723 karma points
    Mar 26, 2021 @ 16:15
    Huw Reddick
    0

    Hi Stuart,

    I notice that in your latest version you added a path parameter to the GetDefaultaction on Action setters, could you perhaps provide a quick example of that works?

    Your code is a godsend by the way :)

  • Stuart Mullinger 63 posts 289 karma points
    Mar 27, 2021 @ 11:29
    Stuart Mullinger
    1

    Glad it's proving useful Huw.

    I added the path parameter to provide a bit extra information. You can ignore it if you don't need it. It is a "\"-separated list of this item's ancestors. Each name in the list is URL-encoded and can be decoded using HttpUtility.UrlDecode().

    For example, this will ignore all the local-only nodes under "\Home\Ignore Local Folder":

    if (contentType == ConvergeContentType.Content)
    {
        if (!String.IsNullOrWhiteSpace(path))
        {
            var parents = path.Split('\\');
            if (parents.Length > 2 && status == CompareStatus.LocalNotRemote)
            {
                // path starts with "\", so ignore parents[0] - it is blank
                if (HttpUtility.UrlDecode(parents[1]) == "Home" && HttpUtility.UrlDecode(parents[2]) == "Ignore Local Folder")
                {
                    mergeAction = MergeAction.Ignore;
                }
            }
        }
    }
    

    The actual path string provided will look like this (as the components are Url-encoded): "\Home\Ignore+Local+Folder"

  • Huw Reddick 533 posts 1723 karma points
    Mar 27, 2021 @ 12:53
    Huw Reddick
    0

    Many thanks for the explanation.

Please Sign in or register to post replies

Write your reply to:

Draft