From 7eddc22bbaa6beb8a18e9f2037d76b8ff5609b40 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Tue, 23 Apr 2019 14:24:45 +0200 Subject: [PATCH] V8: Send notifications for move, restore, copy and delete actions (#5255) --- .../Compose/NotificationsComponent.cs | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web/Compose/NotificationsComponent.cs b/src/Umbraco.Web/Compose/NotificationsComponent.cs index adc0008f48..c099fde8ef 100644 --- a/src/Umbraco.Web/Compose/NotificationsComponent.cs +++ b/src/Umbraco.Web/Compose/NotificationsComponent.cs @@ -41,14 +41,20 @@ namespace Umbraco.Web.Compose //Send notifications for the update and created actions ContentService.Saved += (sender, args) => ContentServiceSaved(_notifier, sender, args, _actions); - //Send notifications for the delete action - ContentService.Deleted += (sender, args) => _notifier.Notify(_actions.GetAction(), args.DeletedEntities.ToArray()); - //Send notifications for the unpublish action ContentService.Unpublished += (sender, args) => _notifier.Notify(_actions.GetAction(), args.PublishedEntities.ToArray()); + //Send notifications for the move/move to recycle bin and restore actions + ContentService.Moved += (sender, args) => ContentServiceMoved(_notifier, sender, args, _actions); + + //Send notifications for the delete action when content is moved to the recycle bin + ContentService.Trashed += (sender, args) => _notifier.Notify(_actions.GetAction(), args.MoveInfoCollection.Select(m => m.Entity).ToArray()); + + //Send notifications for the copy action + ContentService.Copied += (sender, args) => _notifier.Notify(_actions.GetAction(), args.Original); + //Send notifications for the rollback action - ContentService.RolledBack += (sender, args) => _notifier.Notify(_actions.GetAction(), args.Entity); + ContentService.RolledBack += (sender, args) => _notifier.Notify(_actions.GetAction(), args.Entity); } public void Terminate() @@ -92,6 +98,22 @@ namespace Umbraco.Web.Compose notifier.Notify(actions.GetAction(), newEntities.ToArray()); notifier.Notify(actions.GetAction(), updatedEntities.ToArray()); } + + private void ContentServiceMoved(Notifier notifier, IContentService sender, Core.Events.MoveEventArgs args, ActionCollection actions) + { + // notify about the move for all moved items + _notifier.Notify(_actions.GetAction(), args.MoveInfoCollection.Select(m => m.Entity).ToArray()); + + // for any items being moved from the recycle bin (restored), explicitly notify about that too + var restoredEntities = args.MoveInfoCollection + .Where(m => m.OriginalPath.Contains(Constants.System.RecycleBinContentString)) + .Select(m => m.Entity) + .ToArray(); + if(restoredEntities.Any()) + { + _notifier.Notify(_actions.GetAction(), restoredEntities); + } + } /// /// This class is used to send the notifications