Copied to clipboard

Flag this post as spam?

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


  • JGKN 26 posts 172 karma points
    Sep 14, 2021 @ 15:24
    JGKN
    0

    ContentService unpublished event not updating IPublishedContent parent's children

    TLDR Version

    Getting the children of an article node during a comment nodes unpublished event still shows the unpublished comment node as a valid child. Why?

    Longer version

    I have hooked a few custom methods into the ContentService events to update a custom sql table, but I'm having a bit of a problem with the unpublished event.

    What I'm trying to do

    After unpublishing a "comment" from an "article", I need the custom sql db to remove the comment, and then update the article's custom update date since the comment may have been the most recent update.

    How I'm doing it

    In the ContentService.Unpublished I'm first deleting the comment, then deleting its parent, the article, from the db and all its other child comments.

    After the db is cleared, I'm then rebuilding the article using its umbraco IPublishedContent data, and then all its surviving comments.

    The problem

    The issue is the IPublishedContent for the article still has the old comment I've just unpublished as one of its children!

    This means it initially gets deleted from my db, but then when the article is rebuilt it also gets recreated as well.

    I have no idea why article.Children still contains the unpublished comment - I'd understand if I was hooking into the ContentService.Unpublishing event, but I'm using the .Unpublished event - supposedly after the comment has been deleted from the umbraco db/nucache... So to me it doesn't make any sense that it's showing up...

    Is this expected behaviour? Am I missing something?

    I've event tried article.Children.where(x => x.isPublished()), but still have the same result.

    Any help/thoughts would be appreciated.

  • JGKN 26 posts 172 karma points
    Sep 14, 2021 @ 15:30
    JGKN
    0

    I should also note I have no issue with the ContentService.Trashed event I also hook into - it actually uses the exact same method for deleting/rebuilding the db entries....

    So I can almost rule out the code as the source of the issue - it does seem specific to the .Unpublished event only.

  • JGKN 26 posts 172 karma points
    Sep 19, 2021 @ 10:54
    JGKN
    0

    I still haven't been able to find a solution to this- I really don't understand how ContentService.Unpublished hasn't updated all the IPublishedContents, since the unpublishing process should be complete by the time the event is fired...

  • JGKN 26 posts 172 karma points
    Sep 22, 2021 @ 13:09
    JGKN
    100

    I've now created a bug report for this issue: https://github.com/umbraco/Umbraco-CMS/issues/11164

    Edit: a workaround was provided in the bug report, so I'll mark this thread as solved (but the ticket is still open as there could still be a bug to fix within Umbraco)

Please Sign in or register to post replies

Write your reply to:

Draft