From 156fe5976cfc19f79508d7bcfd09d53c40c8eac1 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 31 May 2022 14:26:34 +0200 Subject: [PATCH] Send content type notifications on copy (#12463) --- ...peServiceBaseOfTRepositoryTItemTService.cs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Infrastructure/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs b/src/Umbraco.Infrastructure/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs index 21f95f74d6..86270cbcb3 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs @@ -730,7 +730,7 @@ namespace Umbraco.Cms.Core.Services.Implement public Attempt> Copy(TItem copying, int containerId) { - var evtMsgs = EventMessagesFactory.Get(); + var eventMessages = EventMessagesFactory.Get(); TItem copy; using (var scope = ScopeProvider.CreateScope()) @@ -765,16 +765,34 @@ namespace Umbraco.Cms.Core.Services.Implement } copy.ParentId = containerId; + + SavingNotification savingNotification = GetSavingNotification(copy, eventMessages); + if (scope.Notifications.PublishCancelable(savingNotification)) + { + scope.Complete(); + return OperationResult.Attempt.Fail(MoveOperationStatusType.FailedCancelledByEvent, eventMessages, copy); + } + Repository.Save(copy); + + ContentTypeChange[] changes = ComposeContentTypeChanges(copy).ToArray(); + + _eventAggregator.Publish(GetContentTypeRefreshedNotification(changes, eventMessages)); + scope.Notifications.Publish(GetContentTypeChangedNotification(changes, eventMessages)); + + SavedNotification savedNotification = GetSavedNotification(copy, eventMessages); + savedNotification.WithStateFrom(savingNotification); + scope.Notifications.Publish(savedNotification); + scope.Complete(); } catch (DataOperationException ex) { - return OperationResult.Attempt.Fail(ex.Operation, evtMsgs); // causes rollback + return OperationResult.Attempt.Fail(ex.Operation, eventMessages); // causes rollback } } - return OperationResult.Attempt.Succeed(MoveOperationStatusType.Success, evtMsgs, copy); + return OperationResult.Attempt.Succeed(MoveOperationStatusType.Success, eventMessages, copy); } #endregion