Skip to content

Commit

Permalink
Send content type notifications on copy (#12463)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolajlauridsen committed May 31, 2022
1 parent ac61f85 commit 156fe59
Showing 1 changed file with 21 additions and 3 deletions.
Expand Up @@ -730,7 +730,7 @@ public TItem Copy(TItem original, string alias, string name, TItem parent)

public Attempt<OperationResult<MoveOperationStatusType, TItem>> Copy(TItem copying, int containerId)
{
var evtMsgs = EventMessagesFactory.Get();
var eventMessages = EventMessagesFactory.Get();

TItem copy;
using (var scope = ScopeProvider.CreateScope())
Expand Down Expand Up @@ -765,16 +765,34 @@ public TItem Copy(TItem original, string alias, string name, TItem parent)
}

copy.ParentId = containerId;

SavingNotification<TItem> savingNotification = GetSavingNotification(copy, eventMessages);
if (scope.Notifications.PublishCancelable(savingNotification))
{
scope.Complete();
return OperationResult.Attempt.Fail(MoveOperationStatusType.FailedCancelledByEvent, eventMessages, copy);
}

Repository.Save(copy);

ContentTypeChange<TItem>[] changes = ComposeContentTypeChanges(copy).ToArray();

_eventAggregator.Publish(GetContentTypeRefreshedNotification(changes, eventMessages));
scope.Notifications.Publish(GetContentTypeChangedNotification(changes, eventMessages));

SavedNotification<TItem> savedNotification = GetSavedNotification(copy, eventMessages);
savedNotification.WithStateFrom(savingNotification);
scope.Notifications.Publish(savedNotification);

scope.Complete();
}
catch (DataOperationException<MoveOperationStatusType> ex)
{
return OperationResult.Attempt.Fail<MoveOperationStatusType, TItem>(ex.Operation, evtMsgs); // causes rollback
return OperationResult.Attempt.Fail<MoveOperationStatusType, TItem>(ex.Operation, eventMessages); // causes rollback
}
}

return OperationResult.Attempt.Succeed(MoveOperationStatusType.Success, evtMsgs, copy);
return OperationResult.Attempt.Succeed(MoveOperationStatusType.Success, eventMessages, copy);
}

#endregion
Expand Down

0 comments on commit 156fe59

Please sign in to comment.