Commit 845e3c64 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

reimplement 'keep_workflow_path_list' feature, because r42752 was done by the...

reimplement 'keep_workflow_path_list' feature, because r42752 was done by the misunderstood idea. it should mean 'objects whose workflow history are exported', not 'existing objects whose workflow history should be kept'.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44605 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a1ef81f8
...@@ -563,7 +563,7 @@ class BaseTemplateItem(Implicit, Persistent): ...@@ -563,7 +563,7 @@ class BaseTemplateItem(Implicit, Persistent):
obj.__class__ = newklass obj.__class__ = newklass
return obj return obj
def removeProperties(self, obj, export): def removeProperties(self, obj, export, keep_workflow_history=False):
""" """
Remove unneeded properties for export Remove unneeded properties for export
""" """
...@@ -572,8 +572,10 @@ class BaseTemplateItem(Implicit, Persistent): ...@@ -572,8 +572,10 @@ class BaseTemplateItem(Implicit, Persistent):
classname = klass.__name__ classname = klass.__name__
attr_set = set(('_dav_writelocks', '_filepath', '_owner', 'uid', attr_set = set(('_dav_writelocks', '_filepath', '_owner', 'uid',
'workflow_history', '__ac_local_roles__')) '__ac_local_roles__'))
if export: if export:
if not keep_workflow_history:
attr_set.add('workflow_history')
# PythonScript covers both Zope Python scripts # PythonScript covers both Zope Python scripts
# and ERP5 Python Scripts # and ERP5 Python Scripts
if isinstance(obj, PythonScript): if isinstance(obj, PythonScript):
...@@ -701,7 +703,8 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -701,7 +703,8 @@ class ObjectTemplateItem(BaseTemplateItem):
relative_url = '/'.join([url,id]) relative_url = '/'.join([url,id])
obj = p.unrestrictedTraverse(relative_url) obj = p.unrestrictedTraverse(relative_url)
obj = obj._getCopy(context) obj = obj._getCopy(context)
obj = self.removeProperties(obj, 1) keep_workflow_history = self.isKeepWorkflowObject(relative_url)
obj = self.removeProperties(obj, 1, keep_workflow_history)
id_list = obj.objectIds() # FIXME duplicated variable name id_list = obj.objectIds() # FIXME duplicated variable name
if hasattr(aq_base(obj), 'groups'): # XXX should check metatype instead if hasattr(aq_base(obj), 'groups'): # XXX should check metatype instead
# we must keep groups because they are deleted along with subobjects # we must keep groups because they are deleted along with subobjects
...@@ -728,7 +731,8 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -728,7 +731,8 @@ class ObjectTemplateItem(BaseTemplateItem):
except AttributeError: except AttributeError:
raise AttributeError, "Could not find object '%s' during business template processing." % relative_url raise AttributeError, "Could not find object '%s' during business template processing." % relative_url
_recursiveRemoveUid(obj) _recursiveRemoveUid(obj)
obj = self.removeProperties(obj, 1) keep_workflow_history = self.isKeepWorkflowObject(relative_url)
obj = self.removeProperties(obj, 1, keep_workflow_history)
id_list = obj.objectIds() id_list = obj.objectIds()
if hasattr(aq_base(obj), 'groups'): # XXX should check metatype instead if hasattr(aq_base(obj), 'groups'): # XXX should check metatype instead
# we must keep groups because they are deleted along with subobjects # we must keep groups because they are deleted along with subobjects
...@@ -1020,7 +1024,6 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1020,7 +1024,6 @@ class ObjectTemplateItem(BaseTemplateItem):
saved_uid_dict = {} saved_uid_dict = {}
subobjects_dict = {} subobjects_dict = {}
portal_type_dict = {} portal_type_dict = {}
workflow_history = None
old_obj = container._getOb(object_id, None) old_obj = container._getOb(object_id, None)
object_existed = old_obj is not None object_existed = old_obj is not None
if object_existed: if object_existed:
...@@ -1047,11 +1050,6 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1047,11 +1050,6 @@ class ObjectTemplateItem(BaseTemplateItem):
portal_type_dict[attr] = getattr(old_obj, attr, ()) portal_type_dict[attr] = getattr(old_obj, attr, ())
portal_type_dict['workflow_chain'] = \ portal_type_dict['workflow_chain'] = \
getChainByType(context)[1].get('chain_' + object_id, '') getChainByType(context)[1].get('chain_' + object_id, '')
# try to keep workflow history for specified objects.
workflow_history = getattr(old_obj, 'workflow_history', None)
if workflow_history is not None \
and context.isKeepWorkflowObject(path):
workflow_history = deepcopy(workflow_history)
container.manage_delObjects([object_id]) container.manage_delObjects([object_id])
# install object # install object
...@@ -1100,7 +1098,11 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1100,7 +1098,11 @@ class ObjectTemplateItem(BaseTemplateItem):
# useless because we will already reindex every created object, so # useless because we will already reindex every created object, so
# we avoid duplication of reindexation # we avoid duplication of reindexation
obj.isIndexable = ConstantGetter('isIndexable', value=False) obj.isIndexable = ConstantGetter('isIndexable', value=False)
# keep workflow history if exists
workflow_history = getattr(obj, 'workflow_history', None)
obj.manage_afterClone(obj) obj.manage_afterClone(obj)
if workflow_history is not None:
setattr(obj, 'workflow_history', workflow_history)
del obj.isIndexable del obj.isIndexable
if getattr(aq_base(obj), 'reindexObject', None) is not None: if getattr(aq_base(obj), 'reindexObject', None) is not None:
obj.reindexObject() obj.reindexObject()
...@@ -1131,9 +1133,6 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1131,9 +1133,6 @@ class ObjectTemplateItem(BaseTemplateItem):
# an object which cannot (e.g. External Method). # an object which cannot (e.g. External Method).
LOG('BusinessTemplate', WARNING, LOG('BusinessTemplate', WARNING,
'could not restore %r in %r' % (subobject_id, obj)) 'could not restore %r in %r' % (subobject_id, obj))
# copy workflow history if required
if workflow_history is not None:
setattr(obj, 'workflow_history', workflow_history)
if obj.meta_type in ('Z SQL Method',): if obj.meta_type in ('Z SQL Method',):
fixZSQLMethod(portal, obj) fixZSQLMethod(portal, obj)
# portal transforms specific initialization # portal transforms specific initialization
...@@ -1402,7 +1401,8 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -1402,7 +1401,8 @@ class PathTemplateItem(ObjectTemplateItem):
obj = obj.__of__(context) obj = obj.__of__(context)
_recursiveRemoveUid(obj) _recursiveRemoveUid(obj)
id_list = obj.objectIds() id_list = obj.objectIds()
obj = self.removeProperties(obj, 1) keep_workflow_history = self.isKeepWorkflowObject(relative_url)
obj = self.removeProperties(obj, 1, keep_workflow_history)
if hasattr(aq_base(obj), 'groups'): if hasattr(aq_base(obj), 'groups'):
# we must keep groups because it's ereased when we delete subobjects # we must keep groups because it's ereased when we delete subobjects
groups = deepcopy(obj.groups) groups = deepcopy(obj.groups)
...@@ -1520,7 +1520,8 @@ class CategoryTemplateItem(ObjectTemplateItem): ...@@ -1520,7 +1520,8 @@ class CategoryTemplateItem(ObjectTemplateItem):
relative_url = '/'.join([url,id]) relative_url = '/'.join([url,id])
obj = p.unrestrictedTraverse(relative_url) obj = p.unrestrictedTraverse(relative_url)
obj = obj._getCopy(context) obj = obj._getCopy(context)
obj = self.removeProperties(obj, 1) keep_workflow_history = self.isKeepWorkflowObject(relative_url)
obj = self.removeProperties(obj, 1, keep_workflow_history)
id_list = obj.objectIds() id_list = obj.objectIds()
if id_list: if id_list:
self.build_sub_objects(context, id_list, relative_url) self.build_sub_objects(context, id_list, relative_url)
...@@ -1542,7 +1543,8 @@ class CategoryTemplateItem(ObjectTemplateItem): ...@@ -1542,7 +1543,8 @@ class CategoryTemplateItem(ObjectTemplateItem):
else: else:
raise ValueError, "%s not found" % relative_url raise ValueError, "%s not found" % relative_url
_recursiveRemoveUid(obj) _recursiveRemoveUid(obj)
obj = self.removeProperties(obj, 1) keep_workflow_history = self.isKeepWorkflowObject(relative_url)
obj = self.removeProperties(obj, 1, keep_workflow_history)
include_sub_categories = obj.__of__(context).getProperty('business_template_include_sub_categories', 0) include_sub_categories = obj.__of__(context).getProperty('business_template_include_sub_categories', 0)
id_list = obj.objectIds() id_list = obj.objectIds()
if len(id_list) > 0 and include_sub_categories: if len(id_list) > 0 and include_sub_categories:
...@@ -1905,7 +1907,9 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -1905,7 +1907,9 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
'hidden_content_type_list', 'hidden_content_type_list',
'property_sheet_list', 'property_sheet_list',
'base_category_list', 'base_category_list',
'last_id', 'uid', 'workflow_history'): 'last_id', 'uid') or \
(attr == 'workflow_history' and
not self.isKeepWorkflowObject(relative_url)):
delattr(obj, attr) delattr(obj, attr)
self._objects[relative_url] = obj self._objects[relative_url] = obj
obj.wl_clearLocks() obj.wl_clearLocks()
...@@ -2769,7 +2773,8 @@ class ActionTemplateItem(ObjectTemplateItem): ...@@ -2769,7 +2773,8 @@ class ActionTemplateItem(ObjectTemplateItem):
continue continue
raise NotFound('Action %r not found' % id) raise NotFound('Action %r not found' % id)
key = posixpath.join(url[-2], url[-1], value) key = posixpath.join(url[-2], url[-1], value)
self._objects[key] = self.removeProperties(action, 1) keep_workflow_history = self.isKeepWorkflowObject(key)
self._objects[key] = self.removeProperties(action, 1, keep_workflow_history)
self._objects[key].wl_clearLocks() self._objects[key].wl_clearLocks()
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
......
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Paths of objects whose workflow histories should be kept</string> </value> <value> <string>Paths of objects whose workflow histories should be exported</string> </value>
</item> </item>
<item> <item>
<key> <string>unicode</string> </key> <key> <string>unicode</string> </key>
......
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