From b7dad192d5ce9345d44ae686039b9ad53aff0e06 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sun, 3 Jul 2011 18:36:02 +0000 Subject: [PATCH] Update comment brains in zcatalog when moving a content object with comments. This fixes http://dev.plone.org/plone/ticket/11331. Refs #11331 svn path=/plone.app.discussion/trunk/; revision=50937 --- CHANGES.txt | 4 +++ plone/app/discussion/comment.py | 23 +++++++++++++++++ plone/app/discussion/subscribers.zcml | 6 +++++ plone/app/discussion/tests/test_catalog.py | 30 ++++++++++++++++++++-- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 471fe61..0f1c159 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,10 @@ Changelog 2.0.6 (unreleased) ------------------ +- Update comment brains in zcatalog when moving a content object with comments. + This fixes http://dev.plone.org/plone/ticket/11331. + [timo] + - Plone 3 specific exclusion of plone.app.uuid removed. [timo] diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 6452961..40d4d0d 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -219,6 +219,29 @@ def notify_content_object_deleted(obj, event): del conversation[conversation.keys()[0]] +def notify_content_object_moved(obj, event): + if event.oldParent is None or event.newParent is None \ + or event.oldName is None or event.newName is None \ + or event.oldParent == event.newParent: + return + + old_path = "%s/%s" % ('/'.join(event.oldParent.getPhysicalPath()), + event.oldName, ) + new_path = '/'.join(obj.getPhysicalPath()) + obj.__of__(event.newParent) + conversation = IConversation(obj) + catalog = getToolByName(obj, 'portal_catalog') + from Acquisition import * + for brain in catalog.searchResults(portal_type = 'Discussion Item'): + catalog.uncatalog_object(brain.getPath()) + for comment in conversation.getComments(): + comment.__parent__.__parent__.__of__(event.newParent) + comment.__parent__.__parent__.__parent__ = event.newParent + catalog.reindexObject(aq_base(comment)) + catalog.catalog_object(aq_base(comment)) + + + def notify_user(obj, event): """Tell users when a comment has been added. diff --git a/plone/app/discussion/subscribers.zcml b/plone/app/discussion/subscribers.zcml index 73207ae..6e5e89c 100644 --- a/plone/app/discussion/subscribers.zcml +++ b/plone/app/discussion/subscribers.zcml @@ -39,6 +39,12 @@ handler=".comment.notify_content_object_deleted" /> + +