mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
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:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user