def _cleanAndRebuildIfNeeded(portal, cleanrebuild):
    """
    Rebuild the given catalogs.
    :portal: the Plone portal object
    :cleanrebuild: a list with catalog ids
    """
    for cat in cleanrebuild:
        catalog = getToolByName(portal, cat)
        if catalog:
            if hasattr(catalog, "softClearFindAndRebuild"):
                catalog.softClearFindAndRebuild()
            else:
                catalog.clearFindAndRebuild()
        else:
            logger.warning('%s do not found' % cat)