diff --git a/src/Umbraco.Core/Events/IScopedNotificationPublisher.cs b/src/Umbraco.Core/Events/IScopedNotificationPublisher.cs
index 7df9167ce6..75fbf83860 100644
--- a/src/Umbraco.Core/Events/IScopedNotificationPublisher.cs
+++ b/src/Umbraco.Core/Events/IScopedNotificationPublisher.cs
@@ -1,6 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
+using System;
using System.Threading.Tasks;
using Umbraco.Cms.Core.Notifications;
@@ -8,6 +9,12 @@ namespace Umbraco.Cms.Core.Events
{
public interface IScopedNotificationPublisher
{
+ ///
+ /// Supresses all notifications from being added/created until the result object is disposed.
+ ///
+ ///
+ IDisposable Supress();
+
///
/// Publishes a cancelable notification to the notification subscribers
///
diff --git a/src/Umbraco.Core/Events/ScopedNotificationPublisher.cs b/src/Umbraco.Core/Events/ScopedNotificationPublisher.cs
index c9b0080218..6ea7ee5b6a 100644
--- a/src/Umbraco.Core/Events/ScopedNotificationPublisher.cs
+++ b/src/Umbraco.Core/Events/ScopedNotificationPublisher.cs
@@ -12,6 +12,8 @@ namespace Umbraco.Cms.Core.Events
{
private readonly IEventAggregator _eventAggregator;
private readonly List _notificationOnScopeCompleted;
+ private readonly object _locker = new object();
+ private bool _isSuppressed = false;
public ScopedNotificationPublisher(IEventAggregator eventAggregator)
{
@@ -26,6 +28,11 @@ namespace Umbraco.Cms.Core.Events
throw new ArgumentNullException(nameof(notification));
}
+ if (_isSuppressed)
+ {
+ return false;
+ }
+
_eventAggregator.Publish(notification);
return notification.Cancel;
}
@@ -37,6 +44,11 @@ namespace Umbraco.Cms.Core.Events
throw new ArgumentNullException(nameof(notification));
}
+ if (_isSuppressed)
+ {
+ return false;
+ }
+
await _eventAggregator.PublishAsync(notification);
return notification.Cancel;
}
@@ -48,6 +60,11 @@ namespace Umbraco.Cms.Core.Events
throw new ArgumentNullException(nameof(notification));
}
+ if (_isSuppressed)
+ {
+ return;
+ }
+
_notificationOnScopeCompleted.Add(notification);
}
@@ -57,7 +74,7 @@ namespace Umbraco.Cms.Core.Events
{
if (completed)
{
- foreach (var notification in _notificationOnScopeCompleted)
+ foreach (INotification notification in _notificationOnScopeCompleted)
{
_eventAggregator.Publish(notification);
}
@@ -68,5 +85,45 @@ namespace Umbraco.Cms.Core.Events
_notificationOnScopeCompleted.Clear();
}
}
+
+ public IDisposable Supress()
+ {
+ lock(_locker)
+ {
+ if (_isSuppressed)
+ {
+ throw new InvalidOperationException("Notifications are already suppressed");
+ }
+ return new Suppressor(this);
+ }
+ }
+
+ private class Suppressor : IDisposable
+ {
+ private bool _disposedValue;
+ private readonly ScopedNotificationPublisher _scopedNotificationPublisher;
+
+ public Suppressor(ScopedNotificationPublisher scopedNotificationPublisher)
+ {
+ _scopedNotificationPublisher = scopedNotificationPublisher;
+ _scopedNotificationPublisher._isSuppressed = true;
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposedValue)
+ {
+ if (disposing)
+ {
+ lock (_scopedNotificationPublisher._locker)
+ {
+ _scopedNotificationPublisher._isSuppressed = false;
+ }
+ }
+ _disposedValue = true;
+ }
+ }
+ public void Dispose() => Dispose(disposing: true);
+ }
}
}
diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs
index cef8a8c6d6..e58664fef8 100644
--- a/src/Umbraco.Core/Services/IContentService.cs
+++ b/src/Umbraco.Core/Services/IContentService.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
@@ -236,13 +236,13 @@ namespace Umbraco.Cms.Core.Services
///
/// Saves a document.
///
- OperationResult Save(IContent content, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ OperationResult Save(IContent content, int userId = Constants.Security.SuperUserId);
///
/// Saves documents.
///
// TODO: why only 1 result not 1 per content?!
- OperationResult Save(IEnumerable contents, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ OperationResult Save(IEnumerable contents, int userId = Constants.Security.SuperUserId);
///
/// Deletes a document.
@@ -325,12 +325,12 @@ namespace Umbraco.Cms.Core.Services
///
/// Sorts documents.
///
- OperationResult Sort(IEnumerable items, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ OperationResult Sort(IEnumerable items, int userId = Constants.Security.SuperUserId);
///
/// Sorts documents.
///
- OperationResult Sort(IEnumerable ids, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ OperationResult Sort(IEnumerable ids, int userId = Constants.Security.SuperUserId);
#endregion
@@ -349,8 +349,7 @@ namespace Umbraco.Cms.Core.Services
/// The document to publish.
/// The culture to publish.
/// The identifier of the user performing the action.
- /// A value indicating whether to raise events.
- PublishResult SaveAndPublish(IContent content, string culture = "*", int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ PublishResult SaveAndPublish(IContent content, string culture = "*", int userId = Constants.Security.SuperUserId);
///
/// Saves and publishes a document.
@@ -363,8 +362,7 @@ namespace Umbraco.Cms.Core.Services
/// The document to publish.
/// The cultures to publish.
/// The identifier of the user performing the action.
- /// A value indicating whether to raise events.
- PublishResult SaveAndPublish(IContent content, string[] cultures, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ PublishResult SaveAndPublish(IContent content, string[] cultures, int userId = Constants.Security.SuperUserId);
///
/// Saves and publishes a document branch.
diff --git a/src/Umbraco.Core/Services/IContentServiceBase.cs b/src/Umbraco.Core/Services/IContentServiceBase.cs
index 9ab7fc7acc..a62d039abb 100644
--- a/src/Umbraco.Core/Services/IContentServiceBase.cs
+++ b/src/Umbraco.Core/Services/IContentServiceBase.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
@@ -8,7 +8,7 @@ namespace Umbraco.Cms.Core.Services
where TItem: class, IContentBase
{
TItem GetById(Guid key);
- Attempt Save(IEnumerable contents, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ Attempt Save(IEnumerable contents, int userId = Constants.Security.SuperUserId);
}
///
diff --git a/src/Umbraco.Core/Services/IDataTypeService.cs b/src/Umbraco.Core/Services/IDataTypeService.cs
index f8e91d07d8..c7b13c04e1 100644
--- a/src/Umbraco.Core/Services/IDataTypeService.cs
+++ b/src/Umbraco.Core/Services/IDataTypeService.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
@@ -68,15 +68,7 @@ namespace Umbraco.Cms.Core.Services
/// to save
/// Id of the user issuing the save
void Save(IEnumerable dataTypeDefinitions, int userId = Constants.Security.SuperUserId);
-
- ///
- /// Saves a collection of
- ///
- /// to save
- /// Id of the user issuing the save
- /// Boolean indicating whether or not to raise events
- void Save(IEnumerable dataTypeDefinitions, int userId, bool raiseEvents);
-
+
///
/// Deletes an
///
diff --git a/src/Umbraco.Core/Services/IMediaService.cs b/src/Umbraco.Core/Services/IMediaService.cs
index fc4d4fd612..6c9bf21ecc 100644
--- a/src/Umbraco.Core/Services/IMediaService.cs
+++ b/src/Umbraco.Core/Services/IMediaService.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using Umbraco.Cms.Core.Models;
@@ -198,16 +198,14 @@ namespace Umbraco.Cms.Core.Services
///
/// The to save
/// Id of the User saving the Media
- /// Optional boolean indicating whether or not to raise events.
- Attempt Save(IMedia media, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ Attempt Save(IMedia media, int userId = Constants.Security.SuperUserId);
///
/// Saves a collection of objects
///
/// Collection of to save
/// Id of the User saving the Media
- /// Optional boolean indicating whether or not to raise events.
- Attempt Save(IEnumerable medias, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ Attempt Save(IEnumerable medias, int userId = Constants.Security.SuperUserId);
///
/// Gets an object by its 'UniqueId'
@@ -304,7 +302,7 @@ namespace Umbraco.Cms.Core.Services
///
///
/// True if sorting succeeded, otherwise False
- bool Sort(IEnumerable items, int userId = Constants.Security.SuperUserId, bool raiseEvents = true);
+ bool Sort(IEnumerable items, int userId = Constants.Security.SuperUserId);
///
/// Creates an object using the alias of the
diff --git a/src/Umbraco.Core/Services/IMemberGroupService.cs b/src/Umbraco.Core/Services/IMemberGroupService.cs
index 16028ded3f..0b72906c2f 100644
--- a/src/Umbraco.Core/Services/IMemberGroupService.cs
+++ b/src/Umbraco.Core/Services/IMemberGroupService.cs
@@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.Services
IMemberGroup GetById(Guid id);
IEnumerable GetByIds(IEnumerable ids);
IMemberGroup GetByName(string name);
- void Save(IMemberGroup memberGroup, bool raiseEvents = true);
+ void Save(IMemberGroup memberGroup);
void Delete(IMemberGroup memberGroup);
}
}
diff --git a/src/Umbraco.Core/Services/IMembershipMemberService.cs b/src/Umbraco.Core/Services/IMembershipMemberService.cs
index c91eba5250..6093c0a4fe 100644
--- a/src/Umbraco.Core/Services/IMembershipMemberService.cs
+++ b/src/Umbraco.Core/Services/IMembershipMemberService.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
@@ -125,18 +125,14 @@ namespace Umbraco.Cms.Core.Services
///
/// An can be of type or
/// or to Save
- /// Optional parameter to raise events.
- /// Default is True otherwise set to False to not raise events
- void Save(T entity, bool raiseEvents = true);
+ void Save(T entity);
///
/// Saves a list of objects
///
/// An can be of type or
/// to save
- /// Optional parameter to raise events.
- /// Default is True otherwise set to False to not raise events
- void Save(IEnumerable entities, bool raiseEvents = true);
+ void Save(IEnumerable entities);
///
/// Finds a list of objects by a partial email string
diff --git a/src/Umbraco.Core/Services/IUserService.cs b/src/Umbraco.Core/Services/IUserService.cs
index a4af73e084..25ce49b65d 100644
--- a/src/Umbraco.Core/Services/IUserService.cs
+++ b/src/Umbraco.Core/Services/IUserService.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Persistence.Querying;
@@ -243,9 +243,7 @@ namespace Umbraco.Cms.Core.Services
/// 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
///
- /// Optional parameter to raise events.
- /// Default is True otherwise set to False to not raise events
- void Save(IUserGroup userGroup, int[] userIds = null, bool raiseEvents = true);
+ void Save(IUserGroup userGroup, int[] userIds = null);
///
/// Deletes a UserGroup
diff --git a/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs b/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
index 3d4c6dfbbe..b6fa009d2e 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
@@ -381,8 +381,7 @@ namespace Umbraco.Cms.Core.Services.Implement
///
///
///
- Attempt IContentServiceBase.Save(IEnumerable contents, int userId,
- bool raiseEvents) => Attempt.Succeed(Save(contents, userId, raiseEvents));
+ Attempt IContentServiceBase.Save(IEnumerable contents, int userId) => Attempt.Succeed(Save(contents, userId));
///
/// Gets objects by Ids
@@ -756,7 +755,7 @@ namespace Umbraco.Cms.Core.Services.Implement
#region Save, Publish, Unpublish
///
- 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 +773,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 +799,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 +824,7 @@ namespace Umbraco.Cms.Core.Services.Implement
}
///
- public OperationResult Save(IEnumerable contents, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
+ public OperationResult Save(IEnumerable contents, int userId = Cms.Core.Constants.Security.SuperUserId)
{
EventMessages eventMessages = EventMessagesFactory.Get();
IContent[] contentsA = contents.ToArray();
@@ -831,7 +832,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 +851,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 +864,7 @@ namespace Umbraco.Cms.Core.Services.Implement
}
///
- 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 +912,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;
}
}
///
- 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 +938,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 +948,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 +959,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 +1069,7 @@ namespace Umbraco.Cms.Core.Services.Implement
/// The document is *always* saved, even when publishing fails.
///
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 +1085,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;
}
@@ -2383,7 +2385,7 @@ namespace Umbraco.Cms.Core.Services.Implement
///
///
/// Result indicating what action was taken when handling the command.
- public OperationResult Sort(IEnumerable items, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
+ public OperationResult Sort(IEnumerable items, int userId = Cms.Core.Constants.Security.SuperUserId)
{
var evtMsgs = EventMessagesFactory.Get();
@@ -2394,7 +2396,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;
}
@@ -2412,7 +2414,7 @@ namespace Umbraco.Cms.Core.Services.Implement
///
///
/// Result indicating what action was taken when handling the command.
- public OperationResult Sort(IEnumerable ids, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
+ public OperationResult Sort(IEnumerable ids, int userId = Cms.Core.Constants.Security.SuperUserId)
{
var evtMsgs = EventMessagesFactory.Get();
@@ -2424,29 +2426,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();
@@ -2479,16 +2479,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));
}
diff --git a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs
index b20be692df..50caca0ec8 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs
@@ -434,18 +434,7 @@ namespace Umbraco.Cms.Core.Services.Implement
///
/// to save
/// Id of the user issuing the save
- public void Save(IEnumerable dataTypeDefinitions, int userId = Cms.Core.Constants.Security.SuperUserId)
- {
- Save(dataTypeDefinitions, userId, true);
- }
-
- ///
- /// Saves a collection of
- ///
- /// to save
- /// Id of the user issuing the save
- /// Boolean indicating whether or not to raise events
- public void Save(IEnumerable dataTypeDefinitions, int userId, bool raiseEvents)
+ public void Save(IEnumerable 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();
diff --git a/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs b/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs
index 34d1c2a5ce..bdf672ce7a 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs
@@ -654,14 +654,14 @@ namespace Umbraco.Cms.Core.Services.Implement
/// The to save
/// Id of the User saving the Media
/// Optional boolean indicating whether or not to raise events.
- public Attempt Save(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
+ public Attempt 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 +685,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 supressing events in content service
scope.Notifications.Publish(new MediaTreeChangeNotification(media, TreeChangeTypes.RefreshNode, eventMessages));
Audit(AuditType.Save, userId, media.Id);
@@ -704,7 +702,7 @@ namespace Umbraco.Cms.Core.Services.Implement
/// Collection of to save
/// Id of the User saving the Media
/// Optional boolean indicating whether or not to raise events.
- public Attempt Save(IEnumerable medias, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
+ public Attempt Save(IEnumerable medias, int userId = Cms.Core.Constants.Security.SuperUserId)
{
EventMessages messages = EventMessagesFactory.Get();
IMedia[] mediasA = medias.ToArray();
@@ -712,7 +710,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 +729,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 supressing 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");
@@ -1095,7 +1091,7 @@ namespace Umbraco.Cms.Core.Services.Implement
///
///
/// True if sorting succeeded, otherwise False
- public bool Sort(IEnumerable items, int userId = Cms.Core.Constants.Security.SuperUserId, bool raiseEvents = true)
+ public bool Sort(IEnumerable items, int userId = Cms.Core.Constants.Security.SuperUserId)
{
IMedia[] itemsA = items.ToArray();
if (itemsA.Length == 0)
@@ -1108,7 +1104,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 +1131,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 supressing events in content service
scope.Notifications.Publish(new MediaTreeChangeNotification(saved, TreeChangeTypes.RefreshNode, messages));
Audit(AuditType.Sort, userId, 0);
diff --git a/src/Umbraco.Infrastructure/Services/Implement/MemberGroupService.cs b/src/Umbraco.Infrastructure/Services/Implement/MemberGroupService.cs
index 096ff164a0..9d68415ad5 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/MemberGroupService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/MemberGroupService.cs
@@ -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));
}
}
diff --git a/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs b/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs
index 94476ff1e1..f6aac98682 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs
@@ -767,7 +767,7 @@ namespace Umbraco.Cms.Core.Services.Implement
}
///
- 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
}
///
- public void Save(IEnumerable members, bool raiseEvents = true)
+ public void Save(IEnumerable 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();
diff --git a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs
index 743b4816da..978dbb5bda 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs
@@ -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
///
/// to Save
- /// Optional parameter to raise events.
- /// Default is True otherwise set to False to not raise events
- 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 objects
///
/// to save
- /// Optional parameter to raise events.
- /// Default is True otherwise set to False to not raise events
- public void Save(IEnumerable entities, bool raiseEvents = true)
+ public void Save(IEnumerable 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();
@@ -818,7 +808,7 @@ namespace Umbraco.Cms.Core.Services.Implement
///
/// Optional parameter to raise events.
/// Default is True otherwise set to False to not raise events
- 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 +833,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 +841,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 +849,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();
}
diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj
index d759c8da9b..712323656d 100644
--- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj
+++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj
@@ -111,10 +111,6 @@
-
-
-
-