From b940a2e56d3f1c3df26c7cdf7a6179f43be49ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com> Date: Mon, 30 Jan 2006 13:06:56 +0000 Subject: [PATCH] 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 --- product/ERP5/Document/BusinessTemplate.py | 36 ++++++++++++++++++++--- product/ERP5/Tool/TrashTool.py | 20 +++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py index 81f09039f7..431c1f6d15 100755 --- a/product/ERP5/Document/BusinessTemplate.py +++ b/product/ERP5/Document/BusinessTemplate.py @@ -555,8 +555,34 @@ class ObjectTemplateItem(BaseTemplateItem): obj = container._getOb(object_id) obj.manage_afterClone(obj) 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 - if len(subobjects_dict) > 0: + elif len(subobjects_dict) > 0: # get a jar connection = obj._p_jar o = obj @@ -569,7 +595,7 @@ class ObjectTemplateItem(BaseTemplateItem): subobject_data.seek(0) subobject = connection.importFile(subobject_data) 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',): # It is necessary to make sure that the sql connection # in this method is valid. @@ -1081,7 +1107,6 @@ class PortalTypeTemplateItem(ObjectTemplateItem): else: ObjectTemplateItem._importFile(self, file_name, file) - class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): def build(self, context, **kw): @@ -1103,7 +1128,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): workflow_list.append(workflow) self._objects[portal_type] = workflow_list else: - self._objects[portal_type] = [workflow] + self._objects[portal_type] = [workflow,] else: LOG('BusinessTemplate build', 0, 'portal type %s not found in workflow chain' %(portal_type)) @@ -1113,6 +1138,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): keys.sort() for key in keys: workflow_list = self._objects[key] + LOG('generate xml', 0, workflow_list) xml_data += os.linesep+' <chain>' xml_data += os.linesep+' <type>%s</type>' %(key,) xml_data += os.linesep+' <workflow>%s</workflow>' %(', '.join(workflow_list)) @@ -1167,6 +1193,8 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): dict[str(ptype)] = str(workflow) self._objects = dict +# just for backward compatibility +PortalTypeTemplateWorkflowChainItem = PortalTypeWorkflowChainTemplateItem class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem): diff --git a/product/ERP5/Tool/TrashTool.py b/product/ERP5/Tool/TrashTool.py index 45fac22a59..5ae1c27b86 100755 --- a/product/ERP5/Tool/TrashTool.py +++ b/product/ERP5/Tool/TrashTool.py @@ -32,6 +32,7 @@ from Globals import InitializeClass, DTMLFile from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type import Permissions from Products.ERP5 import _dtmldir +from Products.ERP5.Document.BusinessTemplate import getChainByType from zLOG import LOG from DateTime import DateTime from Acquisition import aq_base @@ -93,9 +94,28 @@ class TrashTool(BaseTool): # so object is not backup LOG("Trash Tool backupObject", 100, "Can't backup object %s" %(object_id)) 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) subobjects_dict = {} + if not keep_sub: # export subobjects if save: -- 2.30.9