U4-3775 - Media.BeforeMoveToTrash is not working in V7

Created by Richard Soeteman 02 Dec 2013, 13:07:17 Updated by Shannon Deminick 21 Jun 2017, 07:58:45

The event handler Media.BeforeMoveToTrash is not fired in Umbraco v7, below an example that works in V4/V6 but not in V7

///

/// Handles the delete of media from relation database when user removed it /// public class DeleteMediarelationRecord : ApplicationBase { /// /// Initializes a new instance of the class. /// public DeleteMediarelationRecord() { Media.BeforeMoveToTrash += Media_BeforeMoveToTrash; }

    /// <summary>
    /// Clears the mediarelation table  after a user moved  the item to trash.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="umbraco.cms.businesslogic.MoveToTrashEventArgs"/> instance containing the event data.</param>
   public  void Media_BeforeMoveToTrash(Media sender, umbraco.cms.businesslogic.MoveToTrashEventArgs e)
    {
        var nodes = DataHelper.GetNodeAndChildren(sender.Id);
        foreach (var nodeInfo in nodes)
        {
            MediaRelation.Delete(nodeInfo.NodeId);
        }
    }

Comments

Shannon Deminick 02 Dec 2013, 21:54:56

This is correct, it will no longer fire just like the rest of the media/content/members events because the API controllers are using the new Services API layer which will only fire the Services API layer events.

The v7 upgrade document discusses this: http://our.umbraco.org/documentation/Installation/Upgrading/v7-upgrade#Events

If you continue to use the legacy business logic APIs in your code, then the legacy events will continue to fire (which will in turn fire the new Services Layer API events) but if you are using the new Services API layer, then only the new events will fire. This is the same with v6, the only difference is that in v7 we are using the new Services API in our codebase - eventually all of the core codebase will be using the new Services APIs.


Richard Soeteman 03 Dec 2013, 06:06:58

Ah ok, I am using the legacy API but the tree is not of course.


Shannon Deminick 21 Jun 2017, 07:58:46

Closing issue due to inactivity - see blog post for details https://umbraco.com/blog/issue-tracker-cleanup/


Priority: Normal

Type: Bug

State: Closed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.0.0

Due in version:

Sprint:

Story Points:

Cycle: