Clear and rebuild Plone's portal_catalog
by
antonh
—
last modified
12-Jan-07 06:14 AM
For those of us supporting legacy Plone 2.0 sites, there is no "Clear and Rebuild" button on the Advanced tab of the portal_tool. So I've taken the code from the Catalog tool on Plone 2.1 and turned it into an External method...
This is the code, which I put in $INSTANCE_HOME/Extensions/ClearAndRebuild.py:
from Acquisition import aq_parent, aq_inner
def clearFindandRebuild(self):
"""Empties catalog, then finds all contentish objects, and
reindexes them. This may take a long time."""
self.manage_catalogClear()
portal = aq_parent(aq_inner(self))
for path, obj in portal.ZopeFind(portal, search_sub=True):
if hasattr(obj, 'indexObject'):
try:
obj.indexObject()
except TypeError:
#Catalogs have 'indexObject' as well, but they
#take different args and will fail
pass
After saving this, you just add an External method with:
Id: clear_and_rebuild
Module name: ClearAndRebuild
Function name: clearFindAndRebuild
Finally, add a Script (Python) to call the method. I just went for the basics:
context.portal_catalog.clear_and rebuild
print "Done."
return printed