Current

This document is valid for the current version of Plone.

Use Generic Setup for defining versioning policies

by Plone Documentation Team last modified Jul 18, 2011 03:56 PM
From Plone 4.1 on, versioning policies for custom types can be configured using Generic Setup (repositorytool.xml)

If you activated versioning for your custom content types you most likely followed one of these How-Tos:

Both basically recommend to set the versioning policies CMFEditions is using in a custom setuphandler:

from Products.CMFEditions.setuphandlers import DEFAULT_POLICIES

portal_repository = getToolByName(portal, 'portal_repository')
versionable_types = list(portal_repository.getVersionableContentTypes())

for type_id in ['MyType', 'AnotherType']:
    if type_id not in versionable_types:
        versionable_types.append(type_id)
        # Add default versioning policies to the versioned type
        for policy_id in DEFAULT_POLICIES:
            portal_repository.addPolicyForContentType(type_id, policy_id)
portal_repository.setVersionableContentTypes(versionable_types)

when migrating to plone4.1 you'll get the following error:

ImportError: cannot import name DEFAULT_POLICIES

To make your Product compatible with Plone4.1 you can remove the code for setting versionableContenttypes above and simply add a file named repositorytool.xml to your package's Generic Setup profile and you're done:

<?xml version="1.0"?>
<repositorytool>
    <policymap>
        <type name="MyType">
            <policy name="at_edit_autoversion"/>
            <policy name="version_on_revert"/>
        </type>
        <type name="AnotherType">
            <policy name="at_edit_autoversion"/>
            <policy name="version_on_revert"/>
        </type>
    </policymap>
</repositorytool>

If you need to be backward compatible you can add repositorytool.xml (which will be used in plone >= 4.1) and add a condition to your setupandler. eg:

try:
    from Products.CMFEditions.setuphandlers import DEFAULT_POLICIES
    # we're on plone < 4.1, configure versionable types manually
    setVersionedTypes(portal)
except ImportError:
    # repositorytool.xml will be used
    pass