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
This commit is contained in:
parent
7378635115
commit
b7dad192d5
@ -4,6 +4,10 @@ Changelog
|
|||||||
2.0.6 (unreleased)
|
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.
|
- Plone 3 specific exclusion of plone.app.uuid removed.
|
||||||
[timo]
|
[timo]
|
||||||
|
|
||||||
|
@ -219,6 +219,29 @@ def notify_content_object_deleted(obj, event):
|
|||||||
del conversation[conversation.keys()[0]]
|
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):
|
def notify_user(obj, event):
|
||||||
"""Tell users when a comment has been added.
|
"""Tell users when a comment has been added.
|
||||||
|
|
||||||
|
@ -39,6 +39,12 @@
|
|||||||
handler=".comment.notify_content_object_deleted"
|
handler=".comment.notify_content_object_deleted"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<subscriber
|
||||||
|
for="Products.CMFCore.interfaces.IContentish
|
||||||
|
zope.app.container.interfaces.IObjectMovedEvent"
|
||||||
|
handler=".comment.notify_content_object_moved"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- Control panel event subscribers -->
|
<!-- Control panel event subscribers -->
|
||||||
|
|
||||||
<subscriber
|
<subscriber
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
"""
|
"""
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
|
|
||||||
|
import transaction
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from zope.component import createObject
|
from zope.component import createObject
|
||||||
@ -231,10 +233,34 @@ class CommentCatalogTest(unittest.TestCase):
|
|||||||
path={'query':
|
path={'query':
|
||||||
'/'.join(self.comment.getPhysicalPath())}))
|
'/'.join(self.comment.getPhysicalPath())}))
|
||||||
self.comment_brain = brains[0]
|
self.comment_brain = brains[0]
|
||||||
|
|
||||||
|
def test_move_comments_when_content_object_is_moved(self):
|
||||||
|
brains = self.catalog.searchResults(portal_type = 'Discussion Item')
|
||||||
|
self.assertEquals(len(brains), 1)
|
||||||
|
self.assertEquals(brains[0].getPath(),
|
||||||
|
'/plone/doc1/++conversation++default/' +
|
||||||
|
str(self.comment_id))
|
||||||
|
|
||||||
|
# Create new folder
|
||||||
|
self.portal.invokeFactory(id='folder1',
|
||||||
|
title='Folder 1',
|
||||||
|
type_name='Folder')
|
||||||
|
transaction.savepoint(1)
|
||||||
|
|
||||||
|
# Move doc1 to folder1
|
||||||
|
cp = self.portal.manage_cutObjects(ids=('doc1',))
|
||||||
|
self.portal.folder1.manage_pasteObjects(cp)
|
||||||
|
|
||||||
|
brains = self.catalog.searchResults(portal_type = 'Discussion Item')
|
||||||
|
|
||||||
|
self.assertEquals(len(brains), 1)
|
||||||
|
self.assertEquals(brains[0].getPath(),
|
||||||
|
'/plone/folder1/doc1/++conversation++default/' +
|
||||||
|
str(self.comment_id))
|
||||||
|
|
||||||
def test_title(self):
|
def test_title(self):
|
||||||
self.assertEqual(self.comment_brain.Title, 'Jim on Document 1')
|
self.assertEqual(self.comment_brain.Title, 'Jim on Document 1')
|
||||||
|
|
||||||
def test_no_name_title(self):
|
def test_no_name_title(self):
|
||||||
comment = createObject('plone.Comment')
|
comment = createObject('plone.Comment')
|
||||||
comment.text = 'Comment text'
|
comment.text = 'Comment text'
|
||||||
|
Loading…
Reference in New Issue
Block a user