Tuesday, January 26, 2010

Indexing of content created by Generic Setup

Just adding a 'profiles/default/structure' to your site will add content, but it won't be indexed properly. You'll have to manually upgrade the portal catalog. To fix this, add this to 'configure.zcml':

<genericsetup:importStep
name="my.policy_updateCatalog"
title="Update catalog"
description="After creating content (from profiles/default/structure), the catalog needs to be updated."
handler="my.policy.setuphandlers.updateCatalog">
<depends name="content"/>
</genericsetup:importStep>

This is the preferred way to define dependencies for import profiles: The import step declares its dependency on the content import step. content is the name for the step which creates content from profiles/default/structure.

You could then add a method which updates the catalog in the product's setuphandlers.py:
def updateCatalog(context, clear=True):
portal = context.getSite()
logger = context.getLogger('my.policy updateCatalog')
logger.info('Updating catalog (with clear=%s) so items in profiles/default/structure are indexed...' % clear )
catalog = portal.portal_catalog
err = catalog.refreshCatalog(clear=clear)
if not err:
logger.info('...done.')
else:
logger.warn('Could not update catalog.')

No comments: