Fix catalog updates for IObjectMovedEvent

If comments were moved because an object on a higher level than the
commented object was moved, these comments were wrongly reindexed.
The commented object also got a wrong __parent__ pointer.

This fixes https://dev.plone.org/ticket/13172.
This commit is contained in:
Gaudenz Steinlin
2012-09-17 16:52:05 +02:00
parent 05c2c19c93
commit 56b08b2247
2 changed files with 55 additions and 3 deletions
+10 -3
View File
@@ -243,9 +243,17 @@ 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:
return
# This method is also called for sublocations of moved objects. We therefore can't
# assume that event.object == obj and event.{old,new}{Parent,Name} may refer to
# the actually moved object further up in the object hierarchy.
# The object is already moved at this point. so obj.getPhysicalPath retruns the new path.
# get the part of the path that was moved.
moved_path = obj.getPhysicalPath()[len(event.newParent.getPhysicalPath()) + 1:]
# Remove comments at the old location from catalog
catalog = getToolByName(obj, 'portal_catalog')
old_path = '/'.join(event.oldParent.getPhysicalPath() + (event.oldName,))
old_path = '/'.join(event.oldParent.getPhysicalPath() + (event.oldName,) + moved_path)
brains = catalog.searchResults(dict(
path={'query': old_path},
portal_type="Discussion Item"
@@ -256,8 +264,7 @@ def notify_content_object_moved(obj, event):
conversation = IConversation(obj, None)
if conversation is not None:
for comment in conversation.getComments():
aq_base(comment).__parent__.__parent__.__parent__ = event.newParent
catalog.reindexObject(aq_base(comment))
comment.reindexObject()
def notify_user(obj, event):