Quantcast
Channel: Planet Plone - Where Developers And Integrators Write
Viewing all articles
Browse latest Browse all 3535

Maurits van Rees: Plone 3 versus 4.1 Compatibility

$
0
0

I see a bit too often that some kind soul adds Plone 4.1 compatibility to a package and then does not notice that Plone 3 compatibility is destroyed. In at least one case this is totally not needed and easily avoided.

The problem that people try to solve is that on Plone 4.1 a lot of packages will need to explicitly load the permissions.zcml file of Products.CMFCore. That could be done like this, but this is bad:

<!-- BAD CODE: this breaks Plone 3 compatibility! -->
<include package="Products.CMFCore" file="permissions.zcml" />

The problem with this code is that it breaks Plone 3 compatibility: the Products.CMFCore version used in Plone 3 does not have a permissions.zcml file! You will get an error like this when you try to startup your Plone 3 site:

IOError: [Errno 2] No such file or directory: '.../Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/permissions.zcml'

Note that on Plone 4.0 the loading of this file works fine but is not needed, so avoiding it is probably very slightly better in startup time. No big deal though.

The proper way is to load this file conditionally. This is easy enough, with just two extra lines:

<!-- Good code: this keeps Plone 3 compatibility; thanks! -->
<include package="Products.CMFCore" file="permissions.zcml"
         xmlns:zcml="http://namespaces.zope.org/zcml"
         zcml:condition="have plone-41" />

Of course if you know that for other reasons your package is not Plone 3 compatible then you could safely omit the condition. But it does not hurt to keep it for clarity.

All this is shown in the Plone Upgrade Guide at http://plone.org/upgrade, specifically here.

Note that the plone-41 definition that is used in the zcml:condition is defined in the meta.zcml file of Products.CMFPlone 4.1.3 as follows:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:meta="http://namespaces.zope.org/meta">

    <meta:provides feature="plone-4" />
    <meta:provides feature="plone-41" />

</configure>

So if you think you could use something similar in your code, this is where to start looking.

Meanwhile, loaded with this knowledge you can participate safely in the Plone TuneUp this Friday 16 December 2011, and update some packages for Plone 4. Thanks!


Viewing all articles
Browse latest Browse all 3535

Trending Articles