Clear annotations in Plone CMFEditions history objects

I am trying to clear the content annotations (IAnnotations) from the remote Plone add-in. I successfully completed all the site content and deleted annotations in live objects.

However, CMFEditions / versioning retains old copies of the content, and I don’t know how to get through them and remove all the bad annotations that they have.

If I cannot clear these object references, after removing the add-in from buildout, you get ZODB BrokenObject errors when editing content containing annotations with missing objects in history.

+3
source share
1 answer

It's disgusting. Another reason addons should ONLY use primitive types for all of their data stores.

-, :

    repo_tool = getToolByName(obj, "portal_repository")
    if not repo_tool.isVersionable(obj):
        return
    history = repo_tool.getHistoryMetadata(obj)
    if not history:
        return       
    length = history.getLength(countPurged=False)
    for i in xrange(length - 1, -1, -1):
        try:
            version = repo_tool.retrieve(obj, i)
            annotations = IAnnotations(version.object)
            del annotations[KEY_TO_DELETE]
        except POSKeyError:
            pass
+5

All Articles