Copied to clipboard

Flag this post as spam?

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


  • Thanh Pham 7 posts 77 karma points
    Oct 21, 2016 @ 05:30
    Thanh Pham
    0

    uSync stuffs up tree node hierarchy

    Hope you can help me out of this.

    Basically I'm running a website using uSync for deployment. Now every time I deploy changes to production it seems uSync is moving my content pages all around which I then have to manually re-order them on production. Sometimes it does not send content through as well.

    enter image description here

    For example, I have a tree as shown on the image above. Now if I update or add new Special Offer and deploy to production uSync will move all or a few Offers out of their parent node Special Offers and place them randomly in the hierarchy. This is really painful.

    I'm running other websites as well but this issue does not happen to those so I'm not sure why. Could someone please shed a light on this matter? Many thanks.

    I'm using Umbraco version 7.5.3, uSync version 3.2.2.740

  • Kevin Jump 1036 posts 6084 karma points mvp c-trib
    Oct 21, 2016 @ 08:19
    Kevin Jump
    0

    Hi,

    I think it sounds like the content files on the disk are out of sync somehow ?

    the sort order is a int value on each content item and is set when usync imports the values, so they don't necessarily follow a 1,2,3,4. if there is a usync file with a higher value it will just go in the order in the wrong place.

    thinking a bit about it i am not 100% sure if the save events are getting fired by umbraco when you do a sort (so when you sort in the interface, there should be a save of each content type to save the sort order - this is what usync will hook into). I will have a play around .

    the 'quick' fix for you might just to be save each content item in that part of the tree on the source umbraco site, the will ensure the sort orders are right in the usync files, and this should solve it.

  • Thanh Pham 7 posts 77 karma points
    Oct 23, 2016 @ 23:27
    Thanh Pham
    0

    Hi Kevin,

    Thanks for your info. That reminds me of the existing code I wrote before. Basically I wrote an event handler called OfferContentPublishEventHandler where whenever I create new Offer the handler will copy the content and put it in the websites depending on my selection, for example Subaru Melbourne and Subaru Docklands. See image below. By doing this way I only create Offer once and can deploy to multi sites easily (we have 17 sites). Do you think this is causing the issue? I copied the code snippet below the image so that you can have a look? Thanks

    enter image description here

    class OfferContentPublishEventHandler : IContentPublishEventHandler { private readonly ILogger _logger; private readonly UmbracoHelper _umbracoHelper;

        public OfferContentPublishEventHandler(ILogger logger, UmbracoHelper umbracoHelper)
        {
            _logger = logger;
            _umbracoHelper = umbracoHelper;
        }
    
        public bool Support(string contentType)
        {
            return contentType == Constants.UmbracoDocumentType.Offer;
        }
    
        public void Publish(PublishEventArgs<IContent> eventArgs)
        {
            var content = eventArgs.PublishedEntities.First();
    
            var publishTos = content.GetValue<string>("publishTo")?
                .Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
    
            var contentService = ApplicationContext.Current.Services.ContentService;
    
            if (publishTos != null)
            {
                foreach (var nodeId in publishTos)
                {
                    var rootNode =
                        _umbracoHelper.TypedContent(nodeId).AncestorOrSelf(Constants.UmbracoDocumentType.Website);
    
                    _logger.Trace("Publishing this content to site {0}: {1}", rootNode?.Name,
                        JsonConvert.SerializeObject(content));
    
                    var parentNode = _umbracoHelper.TypedContent(nodeId);
    
                    if (parentNode.Children.Any(x => x.Name == content.Name))
                    {
                        contentService.Delete(
                        contentService.GetById(parentNode.Children.First(x => x.Name == content.Name).Id));
                    }
    
                    var newContent = contentService.Copy(content, parentNode.Id, false);
    
                    newContent.SortOrder = parentNode.Children.OrderBy(x => x.SortOrder).First().SortOrder - 1;
    
                    var publishResult = contentService.SaveAndPublishWithStatus(newContent);
    
                    _logger.Trace("Publish result {0}", JsonConvert.SerializeObject(publishResult));
                }
            }
        }
    }
    
  • Thanh Pham 7 posts 77 karma points
    Oct 26, 2016 @ 01:07
    Thanh Pham
    0

    Hi Kevin,

    Did you have a chance to play around with what you mentioned above? Are you able to confirm my previous post? Many thanks.

    Regards,

    TP

Please Sign in or register to post replies

Write your reply to:

Draft