Monkey patch for clear-and-rebuild catalog added. This fixes story 847941. Nested comments are not reindexed yet.

svn path=/plone.app.discussion/trunk/; revision=30574
This commit is contained in:
Timo Stollenwerk 2009-10-14 14:58:08 +00:00
parent 83b631413a
commit 9befc4c651
3 changed files with 68 additions and 3 deletions

View File

@ -1,6 +1,7 @@
<configure <configure
xmlns="http://namespaces.zope.org/zope" xmlns="http://namespaces.zope.org/zope"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup" xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:monkey="http://namespaces.plone.org/monkey"
i18n_domain="plone.app.discussion"> i18n_domain="plone.app.discussion">
<include package="plone.indexer" /> <include package="plone.indexer" />
@ -18,7 +19,20 @@
for="Products.CMFPlone.interfaces.IPloneSiteRoot" for="Products.CMFPlone.interfaces.IPloneSiteRoot"
/> />
<!-- Monkey Patches -->
<include package="collective.monkeypatcher" />
<monkey:patch
description="This allows Catalog Tool to find comments
during clear-and-rebuild catalog"
class="Products.CMFPlone.CatalogTool.CatalogTool"
original="clearFindAndRebuild"
replacement=".patches.patchedClearFindAndRebuild"
/>
<!-- Comments --> <!-- Comments -->
<class class=".comment.Comment"> <class class=".comment.Comment">
<require interface=".interfaces.IComment" permission="zope2.View" /> <require interface=".interfaces.IComment" permission="zope2.View" />
<require attributes="Title Creator getId getText" permission="zope2.View" /> <require attributes="Title Creator getId getText" permission="zope2.View" />
@ -30,6 +44,7 @@
/> />
<!-- Conversations --> <!-- Conversations -->
<class class=".conversation.Conversation"> <class class=".conversation.Conversation">
<require interface=".interfaces.IConversation" permission="zope2.View" /> <require interface=".interfaces.IConversation" permission="zope2.View" />
</class> </class>

View File

@ -0,0 +1,47 @@
from Acquisition import aq_inner, aq_parent
from zope.annotation.interfaces import IAnnotations
from Products.CMFPlone.utils import base_hasattr
from Products.CMFPlone.utils import safe_callable
from Products.CMFCore.utils import getToolByName
from plone.app.discussion.conversation import ANNOTATION_KEY
# security.declareProtected(ManageZCatalogEntries, 'clearFindAndRebuild')
def patchedClearFindAndRebuild(self):
"""Empties catalog, then finds all contentish objects (i.e. objects
with an indexObject method), and reindexes them.
This may take a long time.
"""
def indexObject(obj, path):
if (base_hasattr(obj, 'indexObject') and
safe_callable(obj.indexObject)):
try:
obj.indexObject()
annotions = IAnnotations(obj)
catalog = getToolByName(obj, 'portal_catalog', None)
if ANNOTATION_KEY in annotions:
conversation = annotions[ANNOTATION_KEY]
conversation = conversation.__of__(obj)
for comment in conversation.getComments():
try:
comment = conversation.getComments().next()
comment = comment.__of__(conversation)
if catalog:
catalog.indexObject(comment)
except StopIteration:
pass
except TypeError:
# Catalogs have 'indexObject' as well, but they
# take different args, and will fail
pass
self.manage_catalogClear()
portal = aq_parent(aq_inner(self))
portal.ZopeFindAndApply(portal, search_sub=True, apply_func=indexObject)

View File

@ -230,11 +230,14 @@ class CommentCatalogTest(PloneTestCase):
self.assertEquals(self.comment_brain.in_response_to, 'doc1') self.assertEquals(self.comment_brain.in_response_to, 'doc1')
def test_clear_and_rebuild_catalog(self): def test_clear_and_rebuild_catalog(self):
# ToDo: This test fails if clear and rebuild is run # Clear and rebuild catalog
#self.catalog.clearFindAndRebuild() self.catalog.clearFindAndRebuild()
# Check if comment is still there
brains = self.catalog.searchResults(portal_type = 'Discussion Item') brains = self.catalog.searchResults(portal_type = 'Discussion Item')
self.failUnless(brains) self.failUnless(brains)
#comment_brain = brains[0] comment_brain = brains[0]
self.assertEquals(comment_brain.Title, 'Comment 1')
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)