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

Simplify automatic migration of action providers

parent a3540a95
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
############################################################################## ##############################################################################
import logging import logging
import transaction
from Acquisition import aq_parent
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -29,23 +27,14 @@ except ImportError: ...@@ -29,23 +27,14 @@ except ImportError:
def migrateNonProviders(portal_actions): def migrateNonProviders(portal_actions):
portal_actions_path = '/'.join(portal_actions.getPhysicalPath()) portal_actions_path = '/'.join(portal_actions.getPhysicalPath())
root = portal_actions.getPhysicalRoot() portal = portal_actions.getPortalObject()
# 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) action_providers = list(portal_actions.action_providers)
for provider_name in portal_actions.listActionProviders(): for provider_name in portal_actions.listActionProviders():
provider = getattr(portal, provider_name) provider = getattr(portal, provider_name)
if ( getattr(provider, '_actions', ()) and if ( getattr(provider, '_actions', ()) and
getattr(provider, 'listActionInfos', None) is None ): getattr(provider, 'listActionInfos', None) is None ):
msg = ('migrating actions from %r to %r' % logger.info('migrating actions from %r to %r',
(portal_actions_path, '/'.join(provider.getPhysicalPath()))) portal_actions_path, '/'.join(provider.getPhysicalPath()))
logger.warning(msg)
txn.note(msg)
portal_actions._actions += provider._actions portal_actions._actions += provider._actions
del provider._actions del provider._actions
if (getattr(provider, 'listActionInfos', None) is None and if (getattr(provider, 'listActionInfos', None) is None and
...@@ -54,12 +43,6 @@ def migrateNonProviders(portal_actions): ...@@ -54,12 +43,6 @@ def migrateNonProviders(portal_actions):
not(IActionProvider_providedBy(provider))): not(IActionProvider_providedBy(provider))):
action_providers.remove(provider_name) action_providers.remove(provider_name)
portal_actions.action_providers = tuple(action_providers) 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 ActionsTool_listFilteredActionsFor = ActionsTool.listFilteredActionsFor
...@@ -96,9 +79,12 @@ def listFilteredActionsFor(self, object=None): ...@@ -96,9 +79,12 @@ def listFilteredActionsFor(self, object=None):
# for Action Providers written for CMF versions before 1.5 # for Action Providers written for CMF versions before 1.5
actions.extend( self._listActionInfos(provider, object) ) actions.extend( self._listActionInfos(provider, object) )
else: else:
# This should only be triggered once
# We're in 2.12 and we need to migrate objects that are no longer # We're in 2.12 and we need to migrate objects that are no longer
# IActionProviders: # IActionProviders:
migrateNonProviders(self) migrateNonProviders(self)
# Recompute from beginning
return self.listFilteredActionsFor(object=object)
actions.sort(key=lambda x:x.get('priority', 0)) actions.sort(key=lambda x:x.get('priority', 0))
# Reorganize the actions by category. # 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