From 446ff0591b02b19456f65d98c4a2b24d3ffd8fa1 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 21 Dec 2012 07:42:37 +0500 Subject: [PATCH] Adds Deleting/Deleted events to the EmptyRecycleBin methods of Content/Media services. --- src/Umbraco.Core/Services/ContentService.cs | 8 ++++++++ src/Umbraco.Core/Services/MediaService.cs | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 70e54ad56c..af61a4891f 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -785,6 +785,7 @@ namespace Umbraco.Core.Services var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateContentRepository(uow)) { + //TODO: Why are we setting a writer if we are just deleting the object? (I'm probably overlooking something here...?) SetWriter(content, userId); repository.Delete(content); uow.Commit(); @@ -944,6 +945,8 @@ namespace Umbraco.Core.Services /// public void EmptyRecycleBin() { + //TODO: Why don't we have a base class to share between MediaService/ContentService as some of this is exacty the same? + var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateContentRepository(uow)) { @@ -952,7 +955,12 @@ namespace Umbraco.Core.Services foreach (var content in contents) { + if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs(content), this)) + continue; + repository.Delete(content); + + Deleted.RaiseEvent(new DeleteEventArgs(content, false), this); } uow.Commit(); } diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs index 7e0b3ae064..e098c0a171 100644 --- a/src/Umbraco.Core/Services/MediaService.cs +++ b/src/Umbraco.Core/Services/MediaService.cs @@ -303,7 +303,6 @@ namespace Umbraco.Core.Services /// public void EmptyRecycleBin() { - //TODO: Should have an event for this. //TODO: Why don't we have a base class to share between MediaService/ContentService as some of this is exacty the same? var uow = _uowProvider.GetUnitOfWork(); @@ -314,7 +313,12 @@ namespace Umbraco.Core.Services foreach (var content in contents) { + if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs(content), this)) + continue; + repository.Delete(content); + + Deleted.RaiseEvent(new DeleteEventArgs(content, false), this); } uow.Commit(); }