Merge pull request #10655 from umbraco/v9/task/supress-notifications
Remove raiseEvent method parameters and allow suppressing events at the scope level
This commit is contained in:
@@ -1044,7 +1044,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
|
||||
|
||||
if (dataTypes.Count > 0)
|
||||
{
|
||||
_dataTypeService.Save(dataTypes, userId, true);
|
||||
_dataTypeService.Save(dataTypes, userId);
|
||||
}
|
||||
|
||||
return dataTypes;
|
||||
|
||||
@@ -379,10 +379,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// </summary>
|
||||
/// <param name="contents"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="raiseEvents"></param>
|
||||
/// <returns></returns>
|
||||
Attempt<OperationResult> IContentServiceBase<IContent>.Save(IEnumerable<IContent> contents, int userId,
|
||||
bool raiseEvents) => Attempt.Succeed(Save(contents, userId, raiseEvents));
|
||||
Attempt<OperationResult> IContentServiceBase<IContent>.Save(IEnumerable<IContent> contents, int userId) => Attempt.Succeed(Save(contents, userId));
|
||||
|
||||
/// <summary>
|
||||
/// Gets <see cref="IContent"/> objects by Ids
|
||||
@@ -756,7 +754,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
#region Save, Publish, Unpublish
|
||||
|
||||
/// <inheritdoc />
|
||||
public OperationResult Save(IContent content, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
public OperationResult Save(IContent content, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
PublishedState publishedState = content.PublishedState;
|
||||
if (publishedState != PublishedState.Published && publishedState != PublishedState.Unpublished)
|
||||
@@ -774,7 +772,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (IScope scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new ContentSavingNotification(content, eventMessages);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
@@ -800,10 +798,12 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
_documentRepository.Save(content);
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new ContentSavedNotification(content, eventMessages).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new ContentSavedNotification(content, eventMessages).WithStateFrom(savingNotification));
|
||||
|
||||
// TODO: we had code here to FORCE that this event can never be suppressed. But that just doesn't make a ton of sense?!
|
||||
// I understand that if its suppressed that the caches aren't updated, but that would be expected. If someone
|
||||
// is supressing events then I think it's expected that nothing will happen. They are probably doing it for perf
|
||||
// reasons like bulk import and in those cases we don't want this occuring.
|
||||
scope.Notifications.Publish(new ContentTreeChangeNotification(content, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
if (culturesChanging != null)
|
||||
@@ -823,7 +823,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public OperationResult Save(IEnumerable<IContent> contents, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
public OperationResult Save(IEnumerable<IContent> contents, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
IContent[] contentsA = contents.ToArray();
|
||||
@@ -831,7 +831,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (IScope scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new ContentSavingNotification(contentsA, eventMessages);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
@@ -850,11 +850,10 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
_documentRepository.Save(content);
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new ContentSavedNotification(contentsA, eventMessages).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new ContentSavedNotification(contentsA, eventMessages).WithStateFrom(savingNotification));
|
||||
// TODO: See note above about supressing events
|
||||
scope.Notifications.Publish(new ContentTreeChangeNotification(contentsA, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
Audit(AuditType.Save, userId == -1 ? 0 : userId, Cms.Core.Constants.System.Root, "Saved multiple content");
|
||||
|
||||
scope.Complete();
|
||||
@@ -864,7 +863,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public PublishResult SaveAndPublish(IContent content, string culture = "*", int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
public PublishResult SaveAndPublish(IContent content, string culture = "*", int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
@@ -912,14 +911,14 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
// we don't care about the response here, this response will be rechecked below but we need to set the culture info values now.
|
||||
content.PublishCulture(impact);
|
||||
|
||||
var result = CommitDocumentChangesInternal(scope, content, evtMsgs, allLangs, savingNotification.State, userId, raiseEvents);
|
||||
var result = CommitDocumentChangesInternal(scope, content, evtMsgs, allLangs, savingNotification.State, userId);
|
||||
scope.Complete();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public PublishResult SaveAndPublish(IContent content, string[] cultures, int userId = 0, bool raiseEvents = true)
|
||||
public PublishResult SaveAndPublish(IContent content, string[] cultures, int userId = 0)
|
||||
{
|
||||
if (content == null) throw new ArgumentNullException(nameof(content));
|
||||
if (cultures == null) throw new ArgumentNullException(nameof(cultures));
|
||||
@@ -938,7 +937,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
var savingNotification = new ContentSavingNotification(content, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
return new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, content);
|
||||
}
|
||||
@@ -948,7 +947,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
if (cultures.Length == 0 && !varies)
|
||||
{
|
||||
//no cultures specified and doesn't vary, so publish it, else nothing to publish
|
||||
return SaveAndPublish(content, userId: userId, raiseEvents: raiseEvents);
|
||||
return SaveAndPublish(content, userId: userId);
|
||||
}
|
||||
|
||||
if (cultures.Any(x => x == null || x == "*"))
|
||||
@@ -959,9 +958,11 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
// publish the culture(s)
|
||||
// we don't care about the response here, this response will be rechecked below but we need to set the culture info values now.
|
||||
foreach (var impact in impacts)
|
||||
{
|
||||
content.PublishCulture(impact);
|
||||
}
|
||||
|
||||
var result = CommitDocumentChangesInternal(scope, content, evtMsgs, allLangs, savingNotification.State, userId, raiseEvents);
|
||||
var result = CommitDocumentChangesInternal(scope, content, evtMsgs, allLangs, savingNotification.State, userId);
|
||||
scope.Complete();
|
||||
return result;
|
||||
}
|
||||
@@ -1067,7 +1068,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// <para>The document is *always* saved, even when publishing fails.</para>
|
||||
/// </remarks>
|
||||
internal PublishResult CommitDocumentChanges(IContent content,
|
||||
int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
@@ -1083,7 +1084,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
var allLangs = _languageRepository.GetMany().ToList();
|
||||
|
||||
var result = CommitDocumentChangesInternal(scope, content, evtMsgs, allLangs, savingNotification.State, userId, raiseEvents);
|
||||
var result = CommitDocumentChangesInternal(scope, content, evtMsgs, allLangs, savingNotification.State, userId);
|
||||
scope.Complete();
|
||||
return result;
|
||||
}
|
||||
@@ -1097,7 +1098,6 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// <param name="allLangs"></param>
|
||||
/// <param name="notificationState"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="raiseEvents"></param>
|
||||
/// <param name="branchOne"></param>
|
||||
/// <param name="branchRoot"></param>
|
||||
/// <param name="eventMessages"></param>
|
||||
@@ -1111,8 +1111,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
private PublishResult CommitDocumentChangesInternal(IScope scope, IContent content,
|
||||
EventMessages eventMessages, IReadOnlyCollection<ILanguage> allLangs,
|
||||
IDictionary<string, object> notificationState,
|
||||
int userId = Cms.Core.Constants.Security.SuperUserId,
|
||||
bool raiseEvents = true, bool branchOne = false, bool branchRoot = false)
|
||||
int userId = Constants.Security.SuperUserId,
|
||||
bool branchOne = false, bool branchRoot = false)
|
||||
{
|
||||
if (scope == null)
|
||||
{
|
||||
@@ -1269,10 +1269,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
SaveDocument(content);
|
||||
|
||||
// raise the Saved event, always
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new ContentSavedNotification(content, eventMessages).WithState(notificationState));
|
||||
}
|
||||
scope.Notifications.Publish(new ContentSavedNotification(content, eventMessages).WithState(notificationState));
|
||||
|
||||
if (unpublishing) // we have tried to unpublish - won't happen in a branch
|
||||
{
|
||||
@@ -2381,9 +2378,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// </remarks>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="raiseEvents"></param>
|
||||
/// <returns>Result indicating what action was taken when handling the command.</returns>
|
||||
public OperationResult Sort(IEnumerable<IContent> items, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
public OperationResult Sort(IEnumerable<IContent> items, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
@@ -2394,7 +2390,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
{
|
||||
scope.WriteLock(Cms.Core.Constants.Locks.ContentTree);
|
||||
|
||||
var ret = Sort(scope, itemsA, userId, evtMsgs, raiseEvents);
|
||||
var ret = Sort(scope, itemsA, userId, evtMsgs);
|
||||
scope.Complete();
|
||||
return ret;
|
||||
}
|
||||
@@ -2410,9 +2406,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// </remarks>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="raiseEvents"></param>
|
||||
/// <returns>Result indicating what action was taken when handling the command.</returns>
|
||||
public OperationResult Sort(IEnumerable<int> ids, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
public OperationResult Sort(IEnumerable<int> ids, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
@@ -2424,29 +2419,27 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
scope.WriteLock(Cms.Core.Constants.Locks.ContentTree);
|
||||
var itemsA = GetByIds(idsA).ToArray();
|
||||
|
||||
var ret = Sort(scope, itemsA, userId, evtMsgs, raiseEvents);
|
||||
var ret = Sort(scope, itemsA, userId, evtMsgs);
|
||||
scope.Complete();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
private OperationResult Sort(IScope scope, IContent[] itemsA, int userId, EventMessages eventMessages, bool raiseEvents)
|
||||
private OperationResult Sort(IScope scope, IContent[] itemsA, int userId, EventMessages eventMessages)
|
||||
{
|
||||
var sortingNotification = new ContentSortingNotification(itemsA, eventMessages);
|
||||
var savingNotification = new ContentSavingNotification(itemsA, eventMessages);
|
||||
if (raiseEvents)
|
||||
{
|
||||
// raise cancelable sorting event
|
||||
if (scope.Notifications.PublishCancelable(sortingNotification))
|
||||
{
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
// raise cancelable saving event
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
// raise cancelable sorting event
|
||||
if (scope.Notifications.PublishCancelable(sortingNotification))
|
||||
{
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
// raise cancelable saving event
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
var published = new List<IContent>();
|
||||
@@ -2479,16 +2472,13 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
_documentRepository.Save(content);
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
//first saved, then sorted
|
||||
scope.Notifications.Publish(new ContentSavedNotification(itemsA, eventMessages).WithStateFrom(savingNotification));
|
||||
scope.Notifications.Publish(new ContentSortedNotification(itemsA, eventMessages).WithStateFrom(sortingNotification));
|
||||
}
|
||||
//first saved, then sorted
|
||||
scope.Notifications.Publish(new ContentSavedNotification(itemsA, eventMessages).WithStateFrom(savingNotification));
|
||||
scope.Notifications.Publish(new ContentSortedNotification(itemsA, eventMessages).WithStateFrom(sortingNotification));
|
||||
|
||||
scope.Notifications.Publish(new ContentTreeChangeNotification(saved, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
if (raiseEvents && published.Any())
|
||||
if (published.Any())
|
||||
{
|
||||
scope.Notifications.Publish(new ContentPublishedNotification(published, eventMessages));
|
||||
}
|
||||
|
||||
@@ -434,18 +434,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// </summary>
|
||||
/// <param name="dataTypeDefinitions"><see cref="IDataType"/> to save</param>
|
||||
/// <param name="userId">Id of the user issuing the save</param>
|
||||
public void Save(IEnumerable<IDataType> dataTypeDefinitions, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
Save(dataTypeDefinitions, userId, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a collection of <see cref="IDataType"/>
|
||||
/// </summary>
|
||||
/// <param name="dataTypeDefinitions"><see cref="IDataType"/> to save</param>
|
||||
/// <param name="userId">Id of the user issuing the save</param>
|
||||
/// <param name="raiseEvents">Boolean indicating whether or not to raise events</param>
|
||||
public void Save(IEnumerable<IDataType> dataTypeDefinitions, int userId, bool raiseEvents)
|
||||
public void Save(IEnumerable<IDataType> dataTypeDefinitions, int userId)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var dataTypeDefinitionsA = dataTypeDefinitions.ToArray();
|
||||
@@ -453,7 +442,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingDataTypeNotification = new DataTypeSavingNotification(dataTypeDefinitions, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingDataTypeNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingDataTypeNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
@@ -465,10 +454,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
_dataTypeRepository.Save(dataTypeDefinition);
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new DataTypeSavedNotification(dataTypeDefinitions, evtMsgs).WithStateFrom(savingDataTypeNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new DataTypeSavedNotification(dataTypeDefinitions, evtMsgs).WithStateFrom(savingDataTypeNotification));
|
||||
|
||||
Audit(AuditType.Save, userId, -1);
|
||||
|
||||
scope.Complete();
|
||||
|
||||
@@ -653,15 +653,14 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// </summary>
|
||||
/// <param name="media">The <see cref="IMedia"/> to save</param>
|
||||
/// <param name="userId">Id of the User saving the Media</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param>
|
||||
public Attempt<OperationResult> Save(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
public Attempt<OperationResult> Save(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (IScope scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new MediaSavingNotification(media, eventMessages);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Attempt.Cancel(eventMessages);
|
||||
@@ -685,10 +684,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
|
||||
_mediaRepository.Save(media);
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new MediaSavedNotification(media, eventMessages).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new MediaSavedNotification(media, eventMessages).WithStateFrom(savingNotification));
|
||||
// TODO: See note about suppressing events in content service
|
||||
scope.Notifications.Publish(new MediaTreeChangeNotification(media, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
Audit(AuditType.Save, userId, media.Id);
|
||||
@@ -703,8 +700,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// </summary>
|
||||
/// <param name="medias">Collection of <see cref="IMedia"/> to save</param>
|
||||
/// <param name="userId">Id of the User saving the Media</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param>
|
||||
public Attempt<OperationResult> Save(IEnumerable<IMedia> medias, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
public Attempt<OperationResult> Save(IEnumerable<IMedia> medias, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages messages = EventMessagesFactory.Get();
|
||||
IMedia[] mediasA = medias.ToArray();
|
||||
@@ -712,7 +708,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (IScope scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new MediaSavingNotification(mediasA, messages);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Attempt.Cancel(messages);
|
||||
@@ -731,10 +727,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
_mediaRepository.Save(media);
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new MediaSavedNotification(mediasA, messages).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new MediaSavedNotification(mediasA, messages).WithStateFrom(savingNotification));
|
||||
// TODO: See note about suppressing events in content service
|
||||
scope.Notifications.Publish(new MediaTreeChangeNotification(treeChanges, messages));
|
||||
Audit(AuditType.Save, userId == -1 ? 0 : userId, Cms.Core.Constants.System.Root, "Bulk save media");
|
||||
|
||||
@@ -1093,9 +1087,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="raiseEvents"></param>
|
||||
/// <returns>True if sorting succeeded, otherwise False</returns>
|
||||
public bool Sort(IEnumerable<IMedia> items, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
|
||||
public bool Sort(IEnumerable<IMedia> items, int userId = Cms.Core.Constants.Security.SuperUserId)
|
||||
{
|
||||
IMedia[] itemsA = items.ToArray();
|
||||
if (itemsA.Length == 0)
|
||||
@@ -1108,7 +1101,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (IScope scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new MediaSavingNotification(itemsA, messages);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return false;
|
||||
@@ -1135,10 +1128,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
_mediaRepository.Save(media);
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new MediaSavedNotification(itemsA, messages).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new MediaSavedNotification(itemsA, messages).WithStateFrom(savingNotification));
|
||||
// TODO: See note about suppressing events in content service
|
||||
scope.Notifications.Publish(new MediaTreeChangeNotification(saved, TreeChangeTypes.RefreshNode, messages));
|
||||
Audit(AuditType.Sort, userId, 0);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(IMemberGroup memberGroup, bool raiseEvents = true)
|
||||
public void Save(IMemberGroup memberGroup)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(memberGroup.Name))
|
||||
{
|
||||
@@ -76,7 +76,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new MemberGroupSavingNotification(memberGroup, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
@@ -85,10 +85,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
_memberGroupRepository.Save(memberGroup);
|
||||
scope.Complete();
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new MemberGroupSavedNotification(memberGroup, evtMsgs).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new MemberGroupSavedNotification(memberGroup, evtMsgs).WithStateFrom(savingNotification));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -767,7 +767,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save(IMember member, bool raiseEvents = true)
|
||||
public void Save(IMember member)
|
||||
{
|
||||
// trimming username and email to make sure we have no trailing space
|
||||
member.Username = member.Username.Trim();
|
||||
@@ -778,7 +778,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (IScope scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new MemberSavingNotification(member, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
@@ -793,10 +793,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
_memberRepository.Save(member);
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new MemberSavedNotification(member, evtMsgs).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new MemberSavedNotification(member, evtMsgs).WithStateFrom(savingNotification));
|
||||
|
||||
Audit(AuditType.Save, 0, member.Id);
|
||||
|
||||
@@ -805,7 +802,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save(IEnumerable<IMember> members, bool raiseEvents = true)
|
||||
public void Save(IEnumerable<IMember> members)
|
||||
{
|
||||
var membersA = members.ToArray();
|
||||
|
||||
@@ -814,7 +811,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new MemberSavingNotification(membersA, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
@@ -831,10 +828,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
_memberRepository.Save(member);
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new MemberSavedNotification(membersA, evtMsgs).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new MemberSavedNotification(membersA, evtMsgs).WithStateFrom(savingNotification));
|
||||
|
||||
Audit(AuditType.Save, 0, -1, "Save multiple Members");
|
||||
|
||||
scope.Complete();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
@@ -273,16 +273,14 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// Saves an <see cref="IUser"/>
|
||||
/// </summary>
|
||||
/// <param name="entity"><see cref="IUser"/> to Save</param>
|
||||
/// <param name="raiseEvents">Optional parameter to raise events.
|
||||
/// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param>
|
||||
public void Save(IUser entity, bool raiseEvents = true)
|
||||
public void Save(IUser entity)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new UserSavingNotification(entity, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
@@ -297,10 +295,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
try
|
||||
{
|
||||
_userRepository.Save(entity);
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new UserSavedNotification(entity, evtMsgs).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new UserSavedNotification(entity, evtMsgs).WithStateFrom(savingNotification));
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
@@ -321,9 +316,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// Saves a list of <see cref="IUser"/> objects
|
||||
/// </summary>
|
||||
/// <param name="entities"><see cref="IEnumerable{IUser}"/> to save</param>
|
||||
/// <param name="raiseEvents">Optional parameter to raise events.
|
||||
/// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param>
|
||||
public void Save(IEnumerable<IUser> entities, bool raiseEvents = true)
|
||||
public void Save(IEnumerable<IUser> entities)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
@@ -332,7 +325,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var savingNotification = new UserSavingNotification(entitiesA, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
@@ -350,10 +343,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new UserSavedNotification(entitiesA, evtMsgs).WithStateFrom(savingNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new UserSavedNotification(entitiesA, evtMsgs).WithStateFrom(savingNotification));
|
||||
|
||||
//commit the whole lot in one go
|
||||
scope.Complete();
|
||||
@@ -816,9 +806,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// If null than no changes are made to the users who are assigned to this group, however if a value is passed in
|
||||
/// than all users will be removed from this group and only these users will be added
|
||||
/// </param>
|
||||
/// <param name="raiseEvents">Optional parameter to raise events.
|
||||
/// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param>
|
||||
public void Save(IUserGroup userGroup, int[] userIds = null, bool raiseEvents = true)
|
||||
public void Save(IUserGroup userGroup, int[] userIds = null)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
@@ -843,7 +832,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
// this is the default/expected notification for the IUserGroup entity being saved
|
||||
var savingNotification = new UserGroupSavingNotification(userGroup, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
@@ -851,7 +840,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
// this is an additional notification for special auditing
|
||||
var savingUserGroupWithUsersNotification = new UserGroupWithUsersSavingNotification(userGroupWithUsers, evtMsgs);
|
||||
if (raiseEvents && scope.Notifications.PublishCancelable(savingUserGroupWithUsersNotification))
|
||||
if (scope.Notifications.PublishCancelable(savingUserGroupWithUsersNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
@@ -859,11 +848,8 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
_userGroupRepository.AddOrUpdateGroupWithUsers(userGroup, userIds);
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
scope.Notifications.Publish(new UserGroupSavedNotification(userGroup, evtMsgs).WithStateFrom(savingNotification));
|
||||
scope.Notifications.Publish(new UserGroupWithUsersSavedNotification(userGroupWithUsers, evtMsgs).WithStateFrom(savingUserGroupWithUsersNotification));
|
||||
}
|
||||
scope.Notifications.Publish(new UserGroupSavedNotification(userGroup, evtMsgs).WithStateFrom(savingNotification));
|
||||
scope.Notifications.Publish(new UserGroupWithUsersSavedNotification(userGroupWithUsers, evtMsgs).WithStateFrom(savingUserGroupWithUsersNotification));
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
@@ -111,10 +111,6 @@
|
||||
<Compile Remove="obj\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\Notifications" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user