diff --git a/plone/app/discussion/configure.zcml b/plone/app/discussion/configure.zcml index a5178a5..a8012cf 100644 --- a/plone/app/discussion/configure.zcml +++ b/plone/app/discussion/configure.zcml @@ -1,6 +1,7 @@ @@ -18,7 +19,20 @@ for="Products.CMFPlone.interfaces.IPloneSiteRoot" /> + + + + + + + @@ -30,6 +44,7 @@ /> + diff --git a/plone/app/discussion/patches.py b/plone/app/discussion/patches.py new file mode 100644 index 0000000..f7d7829 --- /dev/null +++ b/plone/app/discussion/patches.py @@ -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) \ No newline at end of file diff --git a/plone/app/discussion/tests/test_catalog.py b/plone/app/discussion/tests/test_catalog.py index fb4ccc0..4afd6f5 100644 --- a/plone/app/discussion/tests/test_catalog.py +++ b/plone/app/discussion/tests/test_catalog.py @@ -230,11 +230,14 @@ class CommentCatalogTest(PloneTestCase): self.assertEquals(self.comment_brain.in_response_to, 'doc1') def test_clear_and_rebuild_catalog(self): - # ToDo: This test fails if clear and rebuild is run - #self.catalog.clearFindAndRebuild() + # Clear and rebuild catalog + self.catalog.clearFindAndRebuild() + + # Check if comment is still there brains = self.catalog.searchResults(portal_type = 'Discussion Item') self.failUnless(brains) - #comment_brain = brains[0] + comment_brain = brains[0] + self.assertEquals(comment_brain.Title, 'Comment 1') def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) \ No newline at end of file