[Erp5-report] r35280 leonardo - /erp5/trunk/products/ERP5Type/patches/ActionsTool.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed May 12 20:22:54 CEST 2010
Author: leonardo
Date: Wed May 12 20:22:53 2010
New Revision: 35280
URL: http://svn.erp5.org?rev=35280&view=rev
Log:
Automatic migration of actions from non-IActionProviders to portal_actions on Zope 2.12
Modified:
erp5/trunk/products/ERP5Type/patches/ActionsTool.py
Modified: erp5/trunk/products/ERP5Type/patches/ActionsTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/ActionsTool.py?rev=35280&r1=35279&r2=35280&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/ActionsTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/patches/ActionsTool.py [utf8] Wed May 12 20:22:53 2010
@@ -12,6 +12,12 @@
#
##############################################################################
+import logging
+import transaction
+from Acquisition import aq_parent
+
+logger = logging.getLogger(__name__)
+
from Products.CMFCore.ActionsTool import ActionsTool
try:
from Products.CMFCore.interfaces import IActionProvider
@@ -21,6 +27,36 @@
from Products.CMFCore.ActionsTool import IActionProvider
IActionProvider_providedBy = IActionProvider.isImplementedBy
+def migrateNonProviders(portal_actions):
+ portal_actions_path = '/'.join(portal_actions.getPhysicalPath())
+ root = portal_actions.getPhysicalRoot()
+ # Discard all changes so far, we'll restart the request later so no changes
+ # are lost.
+ root._p_jar.sync()
+ txn = transaction.get()
+
+ portal_actions = root.unrestrictedTraverse(portal_actions_path)
+ portal = aq_parent(portal_actions)
+ action_providers = list(portal_actions.action_providers)
+ for provider_name in portal_actions.listActionProviders():
+ provider = getattr(portal, provider_name)
+ if ( getattr(provider, '_actions', ()) and
+ getattr(provider, 'listActionInfos', None) is None ):
+ msg = ('migrating actions from %r to %r' %
+ (portal_actions_path, '/'.join(provider.getPhysicalPath())))
+ logger.warning(msg)
+ txn.note(msg)
+ portal_actions._actions += provider._actions
+ del provider._actions
+ action_providers.remove(provider_name)
+ portal_actions.action_providers = tuple(action_providers)
+
+ txn.note('Migrated actions from non IActionProviders to portal_actions')
+ txn.commit()
+ # restart the transaction with actions already migrated
+ from ZODB.POSException import ConflictError
+ raise ConflictError('Action Migration Completed, please restart request.')
+
ActionsTool_listFilteredActionsFor = ActionsTool.listFilteredActionsFor
def listFilteredActionsFor(self, object=None):
@@ -28,6 +64,13 @@
This patch removes inclusion of actions from the object itself.
It was never used and now, it breaks objects inside Types Tool.
+
+ It also checks for a new ERP5-only actions API (getActionListFor), but
+ this API should be moved to listActionInfos() of each tool so as not to
+ create duplicate code paths that are sources of bugs.
+
+ Finally, this patch detects tools that are no longer action providers and
+ invokes the migration of their actions to portal_actions
"""
actions = []
@@ -42,9 +85,16 @@
if action.test(ec))
elif IActionProvider_providedBy(provider):
actions.extend( provider.listActionInfos(object=object) )
- else:
+ elif getattr(provider, '_listActionInfos', None) is not None:
+ # BACK: drop this clause and the 'else' clause below when we
+ # drop CMF 1.5
+
# for Action Providers written for CMF versions before 1.5
actions.extend( self._listActionInfos(provider, object) )
+ else:
+ # We're in 2.12 and we need to migrate objects that are no longer
+ # IActionProviders:
+ migrateNonProviders(self)
# Reorganize the actions by category.
filtered_actions={'user':[],
More information about the Erp5-report
mailing list