Copied to clipboard

Flag this post as spam?

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


  • Simone Chiaretta 134 posts 541 karma points c-trib
    Dec 06, 2012 @ 11:52
    Simone Chiaretta
    0

    How to get to url of node when it's being deleted

    Hi all,

    I'm listening to Document events to do "stuff" everytime a document is published, unpublished and deleted, and those event handlers I need to have the document url.

    I have no problem in the AfterPublish and AfterUnPublish events: I get the url of the document with the following line

    umbraco.library.NiceUrlWithDomain(sender.Id)

    But I cannot find a way to get the url of document when it's being deleted:

    I've tried getting it in the AfterUnPublish, in the BeforeUnPublish and in the BeforeMoveToTrash, but I always get an error when calling the NiceUrlWithDomain.

    Couldn't find any page with the nodeId = 1059. This is most likely caused by the page isn't published!
    Parameter name: nodeId

    This is weird because in theory in the BeforeMoveToTrash nothing should have happened yet, so the document should still be published. And yes, for those wondering, the BeforeUnPublish/AfterUnPublish events happen after the MoveToTrash events.

    Any idea how I can get the url of the document being deleted?

    Thank you

    Simone

  • Simone Chiaretta 134 posts 541 karma points c-trib
    Dec 06, 2012 @ 12:01
    Simone Chiaretta
    0

    A bit more debugging: the document.Published property is still True

    Wondering if this is a bug

  • Stephen 767 posts 2273 karma points c-trib
    Dec 06, 2012 @ 12:19
    Stephen
    0

    Which version of Umbraco?

    When you mean "deleted" do you mean "moved to trash" or "actually deleted"?

  • Simone Chiaretta 134 posts 541 karma points c-trib
    Dec 06, 2012 @ 12:29
    Simone Chiaretta
    0

    Version 4.10

    Moved to trash

  • Stephen 767 posts 2273 karma points c-trib
    Dec 06, 2012 @ 12:39
    Stephen
    0

    Bug. To make it short, deleting a node ends up doing

    • calls to legacyAjaxCalls.Delete
    • which calls dialogHandler_temp.Delete
    • which calls contentTasks.Delete
    • which first calls library.UnPublishSingleNode, thus removing the node from the XML cache
    • and then calls Document.Delete, thus triggering BeforeMoveToTrash

    So when BeforeMoveToTrash runs, the node has not "officially" been trashed, but it's been removed from the XML cache and you can't get its url anymore. No idea why it works that way. Can't see any workaround either because BeforeMoveToTrash really is the first event to trigger.

  • Simone Chiaretta 134 posts 541 karma points c-trib
    Dec 06, 2012 @ 13:40
    Simone Chiaretta
    0

    OK... looks like a bug :)

    Will store the URL myself somewhere..

    thx

    Simone

Please Sign in or register to post replies

Write your reply to:

Draft