Commit 3fe7aa1e authored by Julien Muchembled's avatar Julien Muchembled

Simplify automatic migration of action providers

parent a3540a95
......@@ -13,8 +13,6 @@
##############################################################################
import logging
import transaction
from Acquisition import aq_parent
logger = logging.getLogger(__name__)
......@@ -29,23 +27,14 @@ except ImportError:
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)
portal = portal_actions.getPortalObject()
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)
logger.info('migrating actions from %r to %r',
portal_actions_path, '/'.join(provider.getPhysicalPath()))
portal_actions._actions += provider._actions
del provider._actions
if (getattr(provider, 'listActionInfos', None) is None and
......@@ -54,12 +43,6 @@ def migrateNonProviders(portal_actions):
not(IActionProvider_providedBy(provider))):
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
......@@ -96,9 +79,12 @@ def listFilteredActionsFor(self, object=None):
# for Action Providers written for CMF versions before 1.5
actions.extend( self._listActionInfos(provider, object) )
else:
# This should only be triggered once
# We're in 2.12 and we need to migrate objects that are no longer
# IActionProviders:
migrateNonProviders(self)
# Recompute from beginning
return self.listFilteredActionsFor(object=object)
actions.sort(key=lambda x:x.get('priority', 0))
# Reorganize the actions by category.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment