Copied to clipboard

Flag this post as spam?

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


  • Mike Taylor 155 posts 353 karma points
    Oct 11, 2012 @ 18:51
    Mike Taylor
    0

    AfterUnPublish event still shows the node as one of its parent's children in NodeFactory

    I'm hooking into a Document_AfterUnPublish event in order to do some manual tweaking of an Examine index.
    Oddly, if I look at the unpublished node's parent's children in NodeFactory, the unpublished node is still listed.
    void DocumentAfterUnPublish(Document sender, umbraco.cms.businesslogic.UnPublishEventArgs e)
            {
                // check
                umbraco.library.RefreshContent();
    
                var parentNode = uQuery.GetNode(sender.ParentId);
                foreach (Node childNode in parentNode.GetChildNodes())
                {
                    Console.Write(childNode.Id);
                }
    
                RemoveFromIndex(sender);
            }
    So, in the above code, the GetChildNodes collection includes the node I've just unpublished.
    Is there a workaround?
    Thanks all,
    Mike
  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 12, 2012 @ 11:55
    Dirk De Grave
    0

    I'm pretty sure the cache is only cleared afterwards,  I'd suggest to use content.AfterClearDocumentCache and do your Examine index tweaking then.

     

    Cheers,

    /Dirk

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 12, 2012 @ 11:57
    Dirk De Grave
    0

    Just looked it up on the umbraco source, cache is cleared when calling library.UnPublishSingleNode() which is done AFTER .UnPublish() and so after that specific event is fired.

     

    Cheers,

    /Dirk

  • Mike Taylor 155 posts 353 karma points
    Oct 12, 2012 @ 11:59
    Mike Taylor
    0

    Seems a bit odd, but OK....

    I only want to run my custom event handler code after a node has been unpublished (or deleted, which I believe also triggers the AfterUnPublish event). Is there a way to hook into AfterClearDocumentCache and test to see whether it was an unpublish or delete that caused it? Otherwise it will run every time the cache is cleared...

    Mike

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 12, 2012 @ 12:04
    Dirk De Grave
    0

    Hmm, not sure if you can find those details, I guess you can check the .Published property or else check path (-1,20 for recycle bin)...

  • Mike Taylor 155 posts 353 karma points
    Oct 12, 2012 @ 12:13
    Mike Taylor
    0

    I think I have it working... in the AfterUnPublish event, I'm making a forced call to library.UnPublishSingleNode(sender.Id) before I do the Examine re-index. This might mean that UnPublishSingleNode is fired twice...?

Please Sign in or register to post replies

Write your reply to:

Draft