Copied to clipboard

Flag this post as spam?

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


  • Alan Draper 57 posts 140 karma points
    Oct 29, 2019 @ 23:35
    Alan Draper
    1

    ContentService.Published not firing when using Publish with descendants

    I have an IComponent set up like this:

    public void Initialize() {
      ContentService.Published += ContentService_Published;
    }
    public void ContentService_Published(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.ContentPublishedEventArgs e) {
      Logger.Info(GetType(), "Published {N} entities.", e.PublishedEntities.Count());
    }
    

    And I don't see any logs for publishing when I use "Publish with descendants". In the case of a single page publish, it works fine.

    Here's the log after publishing the home page and also publishing with descendants

    Any ideas how I can capture multiple entities being published?

  • Alan Draper 57 posts 140 karma points
    Oct 30, 2019 @ 18:49
    Alan Draper
    0

    Actually, it seems like the "Publish with Descendants" isn't doing anything at all most of the time.

  • Sebastian Dammark 583 posts 1407 karma points
    Apr 21, 2020 @ 11:24
    Sebastian Dammark
    0

    Hi Alan,

    Did you ever figure this out ?

  • Jason D 75 posts 247 karma points
    Aug 25, 2020 @ 18:08
    Jason D
    0

    I can't find info on whether this is supposed to work, or the documentation on it. I'm hooked into the "ContentService_Published" event, which does some PDF saving functionality, but it only works if I do a regular "Publish", rather than "Publish with Descendants".

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Dec 22, 2020 @ 01:12
    Jesper Ordrup
    0

    Im running into the same problem today: save event is firing, save and publish event is firing - but save and publish with decendants is not.

    Umbraco 8.9.1

    using Umbraco.Core;
    using Umbraco.Core.Composing;
    using Umbraco.Core.Services.Implement;
    using Umbraco.Core.Logging;
    
    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class ContentSavingEventComposer : ComponentComposer<SubscribeToContentEvent>
    { }
    
    public class SubscribeToContentEvent : IComponent
    {
        private readonly ILogger _logger;
    
        public SubscribeToContentEvent(ILogger logger)
        {
            _logger = logger;
        }
    
    
        public void Initialize()
        {
            ContentService.Published += ContentService_Published;
        }
    
        private void ContentService_Published(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.ContentPublishedEventArgs e)
        {
             // this code never runs
            foreach (var node in e.PublishedEntities)
            {
                _logger.Info<SubscribeToContentEvent>(node.Name + " was published");
                node.Name = node.Name + " updated ...";
            }
        }
    
        public void Terminate()
        {
        }
    
    }
    
  • Adam Nelson 27 posts 186 karma points c-trib
    Feb 13, 2021 @ 00:49
    Adam Nelson
    101

    Quoting @Shazwazza's response from https://github.com/umbraco/Umbraco-CMS/issues/9167 for others arriving here looking for the same answer:

    If you unpublish a content item, it does not recursively go unpublish every single descendant, that overhead would be a killer. All descendants are unpublished (not visible) because it's ancestor is unpublished. If you publish with descendants that single ancestor then the publish event will only trigger for the one that is being changed - that is one content item.

    If you publish with descendants and choose to publish unpublished items - then the publishing event will also be raised for those explicitly unpublished items.

    It's not a 'problem', this is the expected behavior.

    Long story short - only descendants with changes will fire the publish event.

Please Sign in or register to post replies

Write your reply to:

Draft