Make sure only comments to the content object are removed from the catalog when the content object is moved.
svn path=/plone.app.discussion/trunk/; revision=51527
This commit is contained in:
		
							parent
							
								
									0e47299c75
								
							
						
					
					
						commit
						cdf2beda40
					
				@ -8,6 +8,10 @@ Changelog
 | 
				
			|||||||
  renamed.
 | 
					  renamed.
 | 
				
			||||||
  [hannosch, timo]
 | 
					  [hannosch, timo]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Make sure only comments to the content object are removed from the catalog
 | 
				
			||||||
 | 
					  when the content object is moved.
 | 
				
			||||||
 | 
					  [hannosch, timo]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2.0.9 (2011-07-25)
 | 
					2.0.9 (2011-07-25)
 | 
				
			||||||
------------------
 | 
					------------------
 | 
				
			||||||
 | 
				
			|||||||
@ -227,7 +227,11 @@ def notify_content_object_moved(obj, event):
 | 
				
			|||||||
        return
 | 
					        return
 | 
				
			||||||
    # Remove comments at the old location from catalog
 | 
					    # Remove comments at the old location from catalog
 | 
				
			||||||
    catalog = getToolByName(obj, 'portal_catalog')
 | 
					    catalog = getToolByName(obj, 'portal_catalog')
 | 
				
			||||||
    for brain in catalog.searchResults(portal_type = 'Discussion Item'):
 | 
					    brains = catalog.searchResults(dict(
 | 
				
			||||||
 | 
					                 path={'query': '/'.join(event.oldParent.getPhysicalPath())},
 | 
				
			||||||
 | 
					                 portal_type="Discussion Item"
 | 
				
			||||||
 | 
					                 ))
 | 
				
			||||||
 | 
					    for brain in brains:
 | 
				
			||||||
        catalog.uncatalog_object(brain.getPath())
 | 
					        catalog.uncatalog_object(brain.getPath())
 | 
				
			||||||
    # Reindex comment at the new location
 | 
					    # Reindex comment at the new location
 | 
				
			||||||
    conversation = IConversation(obj)
 | 
					    conversation = IConversation(obj)
 | 
				
			||||||
 | 
				
			|||||||
@ -291,28 +291,41 @@ class CommentCatalogTest(unittest.TestCase):
 | 
				
			|||||||
        self.assertEqual(len(brains), 0)
 | 
					        self.assertEqual(len(brains), 0)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    def test_move_comments_when_content_object_is_moved(self):
 | 
					    def test_move_comments_when_content_object_is_moved(self):
 | 
				
			||||||
        brains = self.catalog.searchResults(portal_type = 'Discussion Item')
 | 
					        # Create two folders and a content object with a comment
 | 
				
			||||||
        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',
 | 
					        self.portal.invokeFactory(id='folder1',
 | 
				
			||||||
                                  title='Folder 1',
 | 
					                                  title='Folder 1',
 | 
				
			||||||
                                  type_name='Folder')
 | 
					                                  type_name='Folder')
 | 
				
			||||||
        transaction.savepoint(1)
 | 
					        self.portal.invokeFactory(id='folder2',
 | 
				
			||||||
 | 
					                                  title='Folder 2',
 | 
				
			||||||
 | 
					                                  type_name='Folder')
 | 
				
			||||||
 | 
					        self.portal.folder1.invokeFactory(id='moveme',
 | 
				
			||||||
 | 
					                                  title='Move Me',
 | 
				
			||||||
 | 
					                                  type_name='Document')        
 | 
				
			||||||
 | 
					        conversation = IConversation(self.portal.folder1.moveme)
 | 
				
			||||||
 | 
					        comment = createObject('plone.Comment')
 | 
				
			||||||
 | 
					        comment_id = conversation.addComment(comment)
 | 
				
			||||||
 | 
					        # We need to commit here so that _p_jar isn't None and move will work
 | 
				
			||||||
 | 
					        transaction.savepoint(optimistic=True)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        # Move doc1 to folder1
 | 
					        # Move moveme from folder1 to folder2
 | 
				
			||||||
        cp = self.portal.manage_cutObjects(ids=('doc1',))
 | 
					        cp = self.portal.folder1.manage_cutObjects(ids=('moveme',))
 | 
				
			||||||
        self.portal.folder1.manage_pasteObjects(cp)
 | 
					        self.portal.folder2.manage_pasteObjects(cp)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        brains = self.catalog.searchResults(portal_type = 'Discussion Item')
 | 
					        # Make sure no old comment brains are 
 | 
				
			||||||
        
 | 
					        brains = self.catalog.searchResults(dict(
 | 
				
			||||||
        self.assertEquals(len(brains), 1)
 | 
					                 portal_type="Discussion Item",
 | 
				
			||||||
 | 
					                 path={'query': '/'.join(self.portal.folder1.getPhysicalPath())}
 | 
				
			||||||
 | 
					                 ))
 | 
				
			||||||
 | 
					        self.assertEquals(len(brains), 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        brains = self.catalog.searchResults(dict(
 | 
				
			||||||
 | 
					                 portal_type="Discussion Item",
 | 
				
			||||||
 | 
					                 path={'query': '/'.join(self.portal.folder2.getPhysicalPath())}
 | 
				
			||||||
 | 
					                 ))
 | 
				
			||||||
 | 
					        self.assertEquals(len(brains), 1)        
 | 
				
			||||||
        self.assertEquals(brains[0].getPath(), 
 | 
					        self.assertEquals(brains[0].getPath(), 
 | 
				
			||||||
                          '/plone/folder1/doc1/++conversation++default/' + 
 | 
					                          '/plone/folder2/moveme/++conversation++default/' + 
 | 
				
			||||||
                          str(self.comment_id))
 | 
					                          str(comment_id))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_update_comments_when_content_object_is_renamed(self):
 | 
					    def test_update_comments_when_content_object_is_renamed(self):
 | 
				
			||||||
        # We need to commit here so that _p_jar isn't None and move will work
 | 
					        # We need to commit here so that _p_jar isn't None and move will work
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user