From 08de41508f3ee258a15fa168f302a7bd42f3b51d Mon Sep 17 00:00:00 2001 From: ErikPorter Date: Sat, 16 Jan 2010 06:45:46 +0000 Subject: [PATCH] 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 --- .../Models/CommentsHandler.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs b/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs index 60535031f..caf1a10dc 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs @@ -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 commentsRepository, - IRepository hasCommentsRepository) { + IRepository hasCommentsRepository, + ICommentService commentService) { Filters.Add(new ActivatingFilter("sandboxpage")); Filters.Add(new ActivatingFilter("blogpost")); @@ -21,8 +24,14 @@ namespace Orchard.Comments.Models { OnLoading((context, comments) => { comments.Comments = commentsRepository.Fetch(x => x.CommentedOn == context.ContentItem.Id && x.Status == CommentStatus.Approved); }); + + OnRemoved((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); + } + }); } - - } -} +} \ No newline at end of file