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>();
}
}
}

