Copied to clipboard

Flag this post as spam?

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


  • Paul Bennett 30 posts 53 karma points
    Jul 29, 2011 @ 11:39
    Paul Bennett
    1

    DataType Delete Event handlers

    I'm trying to hook into the delete event for a datatype to perform a check before a user can delete a document containing that datatype.
    Below is the code I am playing with:
    public EventDataType()
            {
    
                DataTypeDefinition.BeforeDelete += new EventHandler<umbraco.cms.businesslogic.DeleteEventArgs>(DataTypeDefinition_BeforeDelete);
                DataTypeDefinition.AfterDelete += new EventHandler<DeleteEventArgs>(DataTypeDefinition_AfterDelete);
                DataTypeDefinition.BeforeSave += new EventHandler<SaveEventArgs>(DataTypeDefinition_BeforeSave);
            }
    
            void DataTypeDefinition_BeforeDelete(object sender, DeleteEventArgs e)
            {
                throw new NotImplementedException();
            }
    
            void DataTypeDefinition_AfterDelete(object sender, DeleteEventArgs e)
            {
                throw new NotImplementedException();
            }
    
            void DataTypeDefinition_BeforeSave(object sender, SaveEventArgs e)
            {
                throw new NotImplementedException();
            }
    On saving the NotImplementedException is thrown as expected but when I delete nothing happens suggesting that the event is never fired?
  • David Conlisk 432 posts 1008 karma points
    Apr 18, 2012 @ 11:19
    David Conlisk
    0

    I'm having a similar problem with events not firing on delete.

    I'm using the latest version: umbraco v 4.7.1.1 (Assembly version: 1.0.4393.24044)

    None of these events are firing for me:

    Document.BeforeDelete
    Document.AfterDelete
    CMSNode.BeforeDelete
    CMSNode.AfterDelete

    The following events are firing fine:

    Document.New
    Document.AfterPublish
    Document.AfterUnPublish

    When I delete a node, the AfterUnPublish event does fire, but the isTrashed property of the document is always false regardless of whether it is being deleted or not. So the question is, how do I run code when a node in the site is deleted?

    Thanks,

    David

  • David Conlisk 432 posts 1008 karma points
    Apr 18, 2012 @ 11:31
    David Conlisk
    0

    Hi all,

    Turns out that when you delete a node in the CMS, the Document.AfterUnPublish event fires, followed by the Document.BeforeMoveToTrash and Document.AfterMoveToTrash. That solved my problem (at last!). 

    Cheers,

    David

Please Sign in or register to post replies

Write your reply to:

Draft