I customized a MediaDeletingNotification that cannot be triggered

When I delete an Image in the Media Section, the MediaDeletedVersionHandler is not triggered. What could be the reason?
Neither of the following two notification types can be triggered.
MediaDeletingNotification
MediaDeletedNotification

public class MediaDeletedVersionHandler : INotificationHandler<MediaDeletingNotification>
{
    private readonly IScopeProvider _scopeProvider;

    public MediaDeletedVersionHandler(IScopeProvider scopeProvider)
    {
        _scopeProvider = scopeProvider;
    }

    public void Handle(MediaDeletingNotification notification)
    {
        using var scope = _scopeProvider.CreateScope();
        var content = notification.DeletedEntities;
        notification.Messages.Add(new EventMessage(
        "Notification",
        "You can return a message to the user, using the messages property on the notification.",
        EventMessageType.Info));
        //scope.Database.Delete<MediaVersions>("WHERE MediaId = @0", content.Id);
        scope.Complete();
    }
}
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Notifications;

namespace UmbracoDemo.Events
{
    public class MediaVersionComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.AddNotificationHandler<MediaSavedNotification, MediaSavedVersionHandler>();
            builder.AddNotificationHandler<MediaDeletingNotification, MediaDeletedVersionHandler>();
        }
    }
}


Although the UI says delete what’s actually happening is a move to the recycle bin. The deleting notification is for when the media item is actually been deleted e.g emptying the recycling bin

Mediamovingtorecyclebi notification is what you need

Hope this helps
Matt

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.