Commit b940a2e5 authored by Aurel's avatar Aurel

don't lost properties at upgrade of portal types


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5416 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ebd6606f
...@@ -555,8 +555,34 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -555,8 +555,34 @@ class ObjectTemplateItem(BaseTemplateItem):
obj = container._getOb(object_id) obj = container._getOb(object_id)
obj.manage_afterClone(obj) obj.manage_afterClone(obj)
obj.wl_clearLocks() obj.wl_clearLocks()
# if portal types upgrade, set backup properties
if getattr(obj, 'meta_type', None) == 'ERP5 Type Information' and len(subobjects_dict) > 0:
setattr(obj, 'allowed_content_types', subobjects_dict['allowed_content_type_list'] or [])
setattr(obj, 'hidden_content_type_list', subobjects_dict['hidden_content_type_list'] or [])
setattr(obj, 'property_sheet_list', subobjects_dict['property_sheet_list'] or [])
setattr(obj, 'base_category_list', subobjects_dict['base_category_list'] or [])
setattr(obj, '_roles', subobjects_dict['roles_list'] or [])
# set actions
action_list = subobjects_dict['action_list']
for action in action_list:
obj.addAction(id = action.id
, name = action.title
, action = action.action.text
, condition = action.getCondition()
, permission = action.permissions
, category = action.category
, visible = action.visible
, icon = getattr(action, 'icon', None) and action.icon.text or ''
, priority = action.priority
)
# set workflow chain
wf_chain = subobjects_dict['workflow_chain']
chain_dict = getChainByType(context)[1]
default_chain = ''
chain_dict['chain_%s' %(object_id)] = wf_chain
context.portal_workflow.manage_changeWorkflows(default_chain, props=chain_dict)
# import sub objects if there is # import sub objects if there is
if len(subobjects_dict) > 0: elif len(subobjects_dict) > 0:
# get a jar # get a jar
connection = obj._p_jar connection = obj._p_jar
o = obj o = obj
...@@ -569,7 +595,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -569,7 +595,7 @@ class ObjectTemplateItem(BaseTemplateItem):
subobject_data.seek(0) subobject_data.seek(0)
subobject = connection.importFile(subobject_data) subobject = connection.importFile(subobject_data)
if subobject_id not in obj.objectIds(): if subobject_id not in obj.objectIds():
obj._setObject(subobject_id, subobject) obj._setObject(subobject_id, subobject)
if obj.meta_type in ('Z SQL Method',): if obj.meta_type in ('Z SQL Method',):
# It is necessary to make sure that the sql connection # It is necessary to make sure that the sql connection
# in this method is valid. # in this method is valid.
...@@ -1081,7 +1107,6 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -1081,7 +1107,6 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
else: else:
ObjectTemplateItem._importFile(self, file_name, file) ObjectTemplateItem._importFile(self, file_name, file)
class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
...@@ -1103,7 +1128,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): ...@@ -1103,7 +1128,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
workflow_list.append(workflow) workflow_list.append(workflow)
self._objects[portal_type] = workflow_list self._objects[portal_type] = workflow_list
else: else:
self._objects[portal_type] = [workflow] self._objects[portal_type] = [workflow,]
else: else:
LOG('BusinessTemplate build', 0, 'portal type %s not found in workflow chain' %(portal_type)) LOG('BusinessTemplate build', 0, 'portal type %s not found in workflow chain' %(portal_type))
...@@ -1113,6 +1138,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): ...@@ -1113,6 +1138,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
keys.sort() keys.sort()
for key in keys: for key in keys:
workflow_list = self._objects[key] workflow_list = self._objects[key]
LOG('generate xml', 0, workflow_list)
xml_data += os.linesep+' <chain>' xml_data += os.linesep+' <chain>'
xml_data += os.linesep+' <type>%s</type>' %(key,) xml_data += os.linesep+' <type>%s</type>' %(key,)
xml_data += os.linesep+' <workflow>%s</workflow>' %(', '.join(workflow_list)) xml_data += os.linesep+' <workflow>%s</workflow>' %(', '.join(workflow_list))
...@@ -1167,6 +1193,8 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): ...@@ -1167,6 +1193,8 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
dict[str(ptype)] = str(workflow) dict[str(ptype)] = str(workflow)
self._objects = dict self._objects = dict
# just for backward compatibility
PortalTypeTemplateWorkflowChainItem = PortalTypeWorkflowChainTemplateItem
class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem): class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem):
......
...@@ -32,6 +32,7 @@ from Globals import InitializeClass, DTMLFile ...@@ -32,6 +32,7 @@ from Globals import InitializeClass, DTMLFile
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5 import _dtmldir from Products.ERP5 import _dtmldir
from Products.ERP5.Document.BusinessTemplate import getChainByType
from zLOG import LOG from zLOG import LOG
from DateTime import DateTime from DateTime import DateTime
from Acquisition import aq_base from Acquisition import aq_base
...@@ -93,9 +94,28 @@ class TrashTool(BaseTool): ...@@ -93,9 +94,28 @@ class TrashTool(BaseTool):
# so object is not backup # so object is not backup
LOG("Trash Tool backupObject", 100, "Can't backup object %s" %(object_id)) LOG("Trash Tool backupObject", 100, "Can't backup object %s" %(object_id))
pass pass
# in case of portal types, export properties instead of subobjects
if getattr(obj, 'meta_type', None) == 'ERP5 Type Information':
subobjects_dict = {}
subobjects_dict['allowed_content_type_list'] = getattr(obj, 'allowed_content_types', []) or []
subobjects_dict['hidden_content_type_list'] = getattr(obj, 'hidden_content_type_list', []) or []
subobjects_dict['property_sheet_list'] = getattr(obj, 'property_sheet_list', []) or []
subobjects_dict['base_category_list'] = getattr(obj, 'base_category_list', []) or []
subobjects_dict['roles_list'] = getattr(obj, '_roles', []) or []
action_list = obj.listActions() or []
subobjects_dict['action_list'] = []
for action in action_list:
subobjects_dict['action_list'].append(action._getCopy(obj))
wf_chain = getChainByType(self.getPortalObject())[1]
if wf_chain.has_key(object_id):
subobjects_dict['workflow_chain'] = wf_chain[object_id]
else:
subobjects_dict['workflow_chain'] = ''
return subobjects_dict
keep_sub = kw.get('keep_subobjects', 0) keep_sub = kw.get('keep_subobjects', 0)
subobjects_dict = {} subobjects_dict = {}
if not keep_sub: if not keep_sub:
# export subobjects # export subobjects
if save: if save:
......
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