diff --git a/CHANGES.txt b/CHANGES.txt
index 4960a23..7341044 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,9 @@ Changelog
1.0b4 (unreleased)
------------------
+* Fix #2494228: Remove comments as well when a content object is deleted.
+ [timo]
+
* Fix unicode error when non-ASCII characters are typed into the name field of a
comment by anonymous users.
[regebro]
diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py
index 28080b4..35373e0 100644
--- a/plone/app/discussion/comment.py
+++ b/plone/app/discussion/comment.py
@@ -2,11 +2,13 @@
"""
from datetime import datetime
-from zope.interface import implements
+from zope.annotation.interfaces import IAnnotations, IAnnotatable
from zope.component.factory import Factory
from zope.component import queryUtility
+from zope.interface import implements
+
from Acquisition import aq_parent, Implicit
from AccessControl.Role import RoleManager
@@ -21,7 +23,9 @@ from OFS.Traversable import Traversable
from plone.registry.interfaces import IRegistry
-from plone.app.discussion.interfaces import IComment, IDiscussionSettings
+from plone.app.discussion.interfaces import IComment
+from plone.app.discussion.interfaces import IConversation
+from plone.app.discussion.interfaces import IDiscussionSettings
try:
# Plone 4:
@@ -139,6 +143,15 @@ def notify_content_object(obj, event):
'last_comment_date',
'commentators',))
+def notify_content_object_deleted(obj, event):
+ """Remove all comments of a content object when the content object has been
+ deleted.
+ """
+ if IAnnotatable.providedBy(obj):
+ conversation = IConversation(obj)
+ for comment in conversation.getComments():
+ del conversation[comment.id]
+
def notify_user(obj, event):
"""Tell the user when a comment is added
"""
diff --git a/plone/app/discussion/subscribers.zcml b/plone/app/discussion/subscribers.zcml
index 67cd8f1..6e0cb1f 100644
--- a/plone/app/discussion/subscribers.zcml
+++ b/plone/app/discussion/subscribers.zcml
@@ -3,7 +3,7 @@
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone.app.discussion">
-
+
@@ -51,8 +51,17 @@
handler=".comment.notify_moderator"
/>
-
+
+
+
+
+
+
-
+
+
+
diff --git a/plone/app/discussion/tests/test_conversation.py b/plone/app/discussion/tests/test_conversation.py
index 823ef39..df4dd72 100644
--- a/plone/app/discussion/tests/test_conversation.py
+++ b/plone/app/discussion/tests/test_conversation.py
@@ -156,10 +156,9 @@ class ConversationTest(PloneTestCase):
self.portal.manage_delObjects(['doc1'])
# Make sure the comment has been deleted as well
- # XXX: Failing! Pivotal Tracker issue #2494228.
- #self.assertEquals(len(list(conversation.getComments())), 0)
- #self.assertEquals(sum(1 for w in conversation.getThreads()), 0)
- #self.assertEquals(conversation.total_comments, 0)
+ self.assertEquals(len(list(conversation.getComments())), 0)
+ self.assertEquals(sum(1 for w in conversation.getThreads()), 0)
+ self.assertEquals(conversation.total_comments, 0)
def test_allow_discussion(self):
# This is not a real test! It's only there to understand the