Commit 748357cd authored by Julien Muchembled's avatar Julien Muchembled

Make first migration of types tool (CMF -> ERP5) work again

It was broken by the second migration (aq_dynamic -> erp5.portal_type).

And now the migration is not triggered by aq_dynamic, there is no reason anymore
to abort the transaction in OldTypesTool._migrateTypesTool if anything fails.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45288 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8b139200
...@@ -175,7 +175,9 @@ class LocalRoleAssignorMixIn(object): ...@@ -175,7 +175,9 @@ class LocalRoleAssignorMixIn(object):
def _importRole(self, role_property_dict): def _importRole(self, role_property_dict):
"""Import a role from a BT or from an old portal type""" """Import a role from a BT or from an old portal type"""
role = self.newContent(portal_type='Role Information') import erp5
RoleInformation = getattr(erp5.portal_type, 'Role Information')
role = RoleInformation(self.generateNewId())
for k, v in role_property_dict.iteritems(): for k, v in role_property_dict.iteritems():
if k == 'condition': if k == 'condition':
if isinstance(v, Expression): if isinstance(v, Expression):
...@@ -193,7 +195,7 @@ class LocalRoleAssignorMixIn(object): ...@@ -193,7 +195,7 @@ class LocalRoleAssignorMixIn(object):
k = 'role_base_category_script_id' k = 'role_base_category_script_id'
setattr(role, k, v) setattr(role, k, v)
role.uid = None role.uid = None
return role return self[self._setObject(role.id, role, set_owner=0)]
class ERP5TypeInformation(XMLObject, class ERP5TypeInformation(XMLObject,
FactoryTypeInformation, FactoryTypeInformation,
......
...@@ -391,32 +391,54 @@ sys.modules[OldRoleInformation.__name__] = OldRoleInformation ...@@ -391,32 +391,54 @@ sys.modules[OldRoleInformation.__name__] = OldRoleInformation
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
OldRoleInformation.RoleInformation = SimpleItem OldRoleInformation.RoleInformation = SimpleItem
def _eventLessSetObject(container):
_setObject = container._setObject
def wrapper(*args, **kw):
try:
return _setObject(suppress_events=True, *args, **kw)
except TypeError:
return _setObject(*args, **kw)
return wrapper
class OldTypesTool(OFSFolder): class OldTypesTool(OFSFolder):
id = 'cmf_portal_types' id = 'cmf_portal_types'
def _migratePortalType(self, types_tool, old_type): def _migratePortalType(self, types_tool, old_type):
if old_type.__class__ is not ERP5TypeInformation: import erp5
BaseType = getattr(erp5.portal_type, 'Base Type')
type_id = old_type.id
if old_type.__class__ is not BaseType:
LOG('OldTypesTool._migratePortalType', WARNING, LOG('OldTypesTool._migratePortalType', WARNING,
"Can't convert %r (meta_type is %r)." "Can't convert %r (meta_type is %r)."
% (old_type, old_type.meta_type)) % (old_type, old_type.meta_type))
return return
new_type = ERP5TypeInformation(old_type.id, uid=None) new_type = BaseType(type_id, uid=None)
types_tool._setObject(new_type.id, new_type, set_owner=0) _eventLessSetObject(types_tool)(type_id, new_type, set_owner=0)
new_type = types_tool[new_type.id] new_type = types_tool[type_id]
for k, v in old_type.__dict__.iteritems(): def generateNewId():
if k == '_actions': new_id = str(int(new_type.__dict__.get('last_id', 0)) + 1)
for action in v: new_type.last_id = new_id
new_type._importOldAction(action) return new_id
elif k == '_roles': try:
for role in v: new_type.generateNewId = generateNewId
new_type._importRole(role.__getstate__()) new_type._setObject = _eventLessSetObject(new_type)
elif k not in ('uid', 'isIndexable'): for k, v in old_type.__dict__.iteritems():
if k == '_property_domain_dict': if k == '_actions':
v = dict((k, t.__class__(property_name=t.property_name, for action in v:
domain_name=t.domain_name)) new_type._importOldAction(action)
for k, t in v.iteritems()) elif k == '_roles':
setattr(new_type, k, v) for role in v:
new_type._importRole(role.__getstate__())
elif k not in ('uid', 'isIndexable'):
if k == '_property_domain_dict':
v = dict((k, t.__class__(property_name=t.property_name,
domain_name=t.domain_name))
for k, t in v.iteritems())
setattr(new_type, k, v)
finally:
del new_type.generateNewId
del new_type._setObject
def _migrateTypesTool(self, parent): def _migrateTypesTool(self, parent):
# 'parent' has no acquisition wrapper so migration must be done without # 'parent' has no acquisition wrapper so migration must be done without
...@@ -428,30 +450,22 @@ class OldTypesTool(OFSFolder): ...@@ -428,30 +450,22 @@ class OldTypesTool(OFSFolder):
break break
types_tool = TypesTool() types_tool = TypesTool()
types_tool.__ac_local_roles__ = self.__ac_local_roles__.copy() types_tool.__ac_local_roles__ = self.__ac_local_roles__.copy()
try: setattr(parent, self.id, self)
setattr(parent, self.id, self) object_info['id'] = self.id
object_info['id'] = self.id del parent.portal_types
del parent.portal_types _eventLessSetObject(parent)(TypesTool.id, types_tool, set_owner=0)
parent._setObject(TypesTool.id, types_tool, set_owner=0) types_tool = types_tool.__of__(parent)
types_tool = types_tool.__of__(parent) if not parent.portal_categories.hasObject('action_type'):
if not parent.portal_categories.hasObject('action_type'): # Required to generate ActionInformation.getActionType accessor.
# Required to generate ActionInformation.getActionType accessor. import erp5
from Products.ERP5Type.Document.BaseCategory import BaseCategory action_type = getattr(erp5.portal_type, 'Base Category')('action_type')
action_type = BaseCategory('action_type') action_type.uid = None
action_type.uid = None parent.portal_categories._setObject(action_type.id, action_type)
parent.portal_categories._setObject(action_type.id, action_type) for type_info in self.objectValues():
for type_info in self.objectValues(): self._migratePortalType(types_tool, type_info)
self._migratePortalType(types_tool, type_info) types_tool.activate()._finalizeMigration()
types_tool.activate()._finalizeMigration() LOG('OldTypesTool', WARNING, "... portal_types converted.")
except: return types_tool
transaction.abort()
LOG('OldTypesTool', PANIC, 'Could not convert portal_types: ',
error=sys.exc_info())
raise # XXX The exception may be hidden by acquisition code
# (None returned instead)
else:
LOG('OldTypesTool', WARNING, "... portal_types converted.")
return types_tool
def __of__(self, parent): def __of__(self, parent):
base_self = aq_base(self) # Is it required ? base_self = aq_base(self) # Is it required ?
......
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