Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Apr 17, 2018 @ 15:46
    Ismail Mayat
    0

    Publish issue after upgrade

    I recently upgraded from 7.2.6 to 7.10.2. I had working content saving event and that was creating node child nodes on a page being saved and it was then publishing the child nodes. Since the upgrade the child nodes are created however they do not seem to be published. Looking at info tab it says:

    This document is published but is not in the cache

    There are no errors in the log.

    The code looks like:

            private void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> saveEventArgs)
        {
            foreach (var savedEntity in saveEventArgs.SavedEntities)
            {
                if (savedEntity.ContentType.Alias == "GalleryLandingPage")
                {
                    int mediaFolderId = savedEntity.HasProperty("mediaFolder") ? savedEntity.GetValue<int>("mediaFolder") : 0;
                    bool moveToTop = savedEntity.HasProperty("moveToTop") && savedEntity.GetValue<bool>("moveToTop");
    
                    if (mediaFolderId != 0)
                    {
                        var mediaFolder = _mediaService.GetById(mediaFolderId);
    
                        savedEntity.SetValue("mediaFolder", null);
                        savedEntity.SetValue("moveToTop", false);
    
                        _contentService.SaveAndPublishWithStatus(savedEntity, 0, false);
    
                        foreach (var media in mediaFolder.Children())
                        {
                            var nodeName = media.Name.Replace("_", " ").Replace(".jpg", "").Replace(".png", "").Replace(".gif", "").Replace(".JPG", "").Replace(".PNG", "").Replace(".GIF", "");
    
                            var galleryImage = _contentService.CreateContent(nodeName, savedEntity.Id, "GalleryImage");
    
                            galleryImage.SetValue("galleryImage", media.Id);
                            galleryImage.SetValue("moveToTop", true);
    
                            _contentService.SaveAndPublishWithStatus(galleryImage, 0, false);
                        }
    
                        if (moveToTop)
                        {
                            var imagesToBeMoved = savedEntity.Children().Where(x => x.GetValue<bool>("moveToTop") == true).ToList();
                            var galleryImages = savedEntity.Children().ToList();
    
                            galleryImages.RemoveAll(x => x.GetValue<bool>("moveToTop"));
                            galleryImages.InsertRange(0, imagesToBeMoved);
    
                            _contentService.Sort(galleryImages, 0, false);
                        }
                    }
                }
    

    Has something changed in api for 7.10.2 for when u publish from contentservice?

    Regards

    Ismail

  • bob baty-barr 1180 posts 1294 karma points MVP
    Apr 17, 2018 @ 15:52
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Apr 17, 2018 @ 16:22
    Søren Gregersen
    0

    I guess the mediaFolder is a content picker. If that is the case, i think the value of it, will be an UDI. I can't remember if there is a setting for it, but you should be able to set it up in each data-type.

    https://our.umbraco.org/documentation/getting-started/setup/upgrading/760-breaking-changes#property-editors-storing-udi-instead-of-id-u4-9310

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Apr 17, 2018 @ 16:37
    Ismail Mayat
    0

    Thing is stuff gets created and it attempts to publish?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 17, 2018 @ 17:52
    Dave Woestenborghs
    0

    Is there a spefici reason why you are using the Saving event ? Otherwise try if it works with the Saved Event.

    Dave

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Apr 18, 2018 @ 08:44
    Ismail Mayat
    0

    Dave,

    Cheers your suggestion worked nicely. I am not sure why the original dev did it this way and why on earth it even worked in 7.2.6.

    Anyhow i owe u another coffee, i am going be skint at this rate lol

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 18, 2018 @ 08:57
    Dave Woestenborghs
    1

    I had an other forum post with the same issue and solution. So something must have changed in Umbraco Core.

    Dave

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Apr 18, 2018 @ 07:55
    Ismail Mayat
    0

    Dave,

    It's an inherited project. So what this has is a gallery parent page and on it you pick a media folder.

    When you save content saving event fires it gets the folder and all images in that folder then creates content nodes under the gallery page with the linked image. However before doing that the actual gallery page is published first. I suspect that gallery page has not fully published yet when the other publish happens on the children and therefore the items are not in the cache.

    I am going to try one more thing then will try content_saved event. Although I am still unsure as to why this worked with 7.2.6.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft