Example #1
0
def wiki_page_edited(page, event):
    history = IWikiHistory(page)
    if IReversionEvent.providedBy(event):
        return history.new_history_item(message=event.reversion_message,
                                        history=event.old_history,
                                        reversion=True,
                                        author=event.rollback_author)
    return history.new_history_item(author=get_member(page))
n = app.openplans
setSite(n)
cat = n.portal_catalog

batch = 200
page_brains = cat(Type='Page')
i = 0
for page_brain in page_brains:
    try:
        page = page_brain.getObject()
    except AttributeError:
        # catalog ghost... might as well clear it out
        cat._catalog.uncatalogObject(page_brain.getPath())
        continue
    try:
        cache = IWikiHistory(page)
    except TypeError:
        # couldn't adapt, we don't cache history, skip it
        continue
    cache.resync_history_cache()
    logger.log(INFO, '%s history cache updated' % page_brain.getPath())
    i += 1
    if i == batch:
        msg = 'incremental page history sync commit: %d' % batch
        transaction.get().note(msg)
        transaction.commit()
        logger.log(INFO, msg)
        i = 0

transaction.get().note('final page history sync commit: %d' % i)
transaction.commit()