2011-12-21 15:07:33 +01:00
|
|
|
from zope.component import queryUtility
|
|
|
|
|
|
|
|
from Acquisition import aq_inner, aq_parent
|
2009-10-14 16:58:08 +02:00
|
|
|
|
|
|
|
from zope.annotation.interfaces import IAnnotations
|
|
|
|
|
|
|
|
from Products.CMFPlone.utils import base_hasattr
|
|
|
|
from Products.CMFPlone.utils import safe_callable
|
|
|
|
|
|
|
|
from plone.app.discussion.conversation import ANNOTATION_KEY
|
2011-12-21 15:07:33 +01:00
|
|
|
from plone.app.discussion.interfaces import ICommentingTool
|
2009-10-14 16:58:08 +02:00
|
|
|
|
2012-01-14 06:57:25 +01:00
|
|
|
|
2009-10-14 16:58:08 +02:00
|
|
|
def patchedClearFindAndRebuild(self):
|
2010-08-28 21:45:53 +02:00
|
|
|
"""Empties catalog, then finds all contentish objects (i.e. objects
|
|
|
|
with an indexObject method), and reindexes them.
|
|
|
|
This may take a long time.
|
|
|
|
"""
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-08-28 21:45:53 +02:00
|
|
|
def indexObject(obj, path):
|
|
|
|
|
|
|
|
if (base_hasattr(obj, 'indexObject') and
|
|
|
|
safe_callable(obj.indexObject)):
|
|
|
|
|
|
|
|
try:
|
|
|
|
obj.indexObject()
|
|
|
|
|
|
|
|
annotions = IAnnotations(obj)
|
2011-12-21 19:17:58 +01:00
|
|
|
ctool = queryUtility(ICommentingTool)
|
2010-08-28 21:45:53 +02:00
|
|
|
if ANNOTATION_KEY in annotions:
|
|
|
|
conversation = annotions[ANNOTATION_KEY]
|
|
|
|
conversation = conversation.__of__(obj)
|
|
|
|
for comment in conversation.getComments():
|
|
|
|
try:
|
2011-12-21 19:17:58 +01:00
|
|
|
if ctool:
|
|
|
|
ctool.indexObject(comment)
|
2012-01-14 06:57:25 +01:00
|
|
|
except StopIteration: # pragma: no cover
|
2010-08-28 21:45:53 +02:00
|
|
|
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)
|