Hooked up comments to cascade delete if their parent content items get removed.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045516
This commit is contained in:
ErikPorter
2010-01-16 06:45:46 +00:00
parent 70524a3e62
commit 08de41508f

View File

@@ -1,4 +1,6 @@
using JetBrains.Annotations;
using System.Linq;
using JetBrains.Annotations;
using Orchard.Comments.Services;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
@@ -7,7 +9,8 @@ namespace Orchard.Comments.Models {
public class HasCommentsHandler : ContentHandler {
public HasCommentsHandler(
IRepository<Comment> commentsRepository,
IRepository<HasCommentsRecord> hasCommentsRepository) {
IRepository<HasCommentsRecord> hasCommentsRepository,
ICommentService commentService) {
Filters.Add(new ActivatingFilter<HasComments>("sandboxpage"));
Filters.Add(new ActivatingFilter<HasComments>("blogpost"));
@@ -21,8 +24,14 @@ namespace Orchard.Comments.Models {
OnLoading<HasComments>((context, comments) => {
comments.Comments = commentsRepository.Fetch(x => x.CommentedOn == context.ContentItem.Id && x.Status == CommentStatus.Approved);
});
OnRemoved<HasComments>((context, c) => {
if (context.ContentType == "blogpost" || context.ContentType == "sandboxpage") {
//TODO: (erikpo) Once comments are content items, replace the following repository delete call to a content manager remove call
commentService.GetCommentsForCommentedContent(context.ContentItem.Id).ToList().ForEach(
commentsRepository.Delete);
}
});
}
}
}
}