Commit 61f8f3ef authored by Jérome Perrin's avatar Jérome Perrin

BusinessTemplate: always call onNewObject/onReplaceObject

Use super to always call the overridden method.

Extend the API to pass the business template being installed.

Call the hooks also when installing sub objects, they were not called
in one place.
parent b39b5e7b
......@@ -1156,22 +1156,24 @@ class ObjectTemplateItem(BaseTemplateItem):
"""
pass
def onNewObject(self, obj):
def onNewObject(self, obj, context):
"""
Installation hook.
Called when installation process determined that object to install is
new on current site (it's not replacing an existing object).
`obj` parameter is the newly created object in its acquisition context.
`context` is the business template instance, in its acquisition context.
Can be overridden by subclasses.
"""
pass
def onReplaceObject(self, obj):
def onReplaceObject(self, obj, context):
"""
Installation hook.
Called when installation process determined that object to install is
to replace an existing object on current site (it's not new).
`obj` parameter is the replaced object in its acquisition context.
`context` is the business template instance, in its acquisition context.
Can be overridden by subclasses.
"""
pass
......@@ -1416,9 +1418,9 @@ class ObjectTemplateItem(BaseTemplateItem):
if not object_existed:
# A new object was added, call the hook
self.onNewObject(obj)
self.onNewObject(obj, context)
else:
self.onReplaceObject(obj)
self.onReplaceObject(obj, context)
# mark a business template installation so in 'PortalType_afterClone' scripts
# we can implement logical for reseting or not attributes (i.e reference).
......@@ -1972,9 +1974,11 @@ class CategoryTemplateItem(ObjectTemplateItem):
def beforeInstall(self):
self._installed_new_category = False
return super(CategoryTemplateItem, self).beforeInstall()
def onNewObject(self, obj):
def onNewObject(self, obj, context):
self._installed_new_category = True
return super(CategoryTemplateItem, self).onNewObject(obj, context)
def afterInstall(self):
if self._installed_new_category:
......@@ -2392,7 +2396,8 @@ class WorkflowTemplateItem(ObjectTemplateItem):
continue
raise
container_ids = container.objectIds()
if object_id in container_ids: # Object already exists
object_existed = object_id in container_ids
if object_existed:
self._backupObject(action, trashbin, container_path, object_id, keep_subobjects=1)
container.manage_delObjects([object_id])
obj = self._objects[path]
......@@ -2402,6 +2407,11 @@ class WorkflowTemplateItem(ObjectTemplateItem):
obj = container._getOb(object_id)
obj.manage_afterClone(obj)
obj.wl_clearLocks()
if not object_existed:
# A new object was added, call the hook
self.onNewObject(obj, context)
else:
self.onReplaceObject(obj, context)
def uninstall(self, context, **kw):
object_path = kw.get('object_path', None)
......@@ -4218,7 +4228,7 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem):
raise NotImplementedError
def __init__(self, id_list, tool_id='portal_components', **kw):
ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
super(_ZodbComponentTemplateItem, self).__init__(id_list, tool_id=tool_id, **kw)
def isKeepWorkflowObjectLastHistoryOnly(self, path):
"""
......@@ -4248,9 +4258,13 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem):
obj.workflow_history[wf_id] = WorkflowHistoryList([wf_history])
def onNewObject(self, _):
def onNewObject(self, obj, context):
self._do_reset = True
return super(_ZodbComponentTemplateItem, self).onNewObject(obj, context)
def onReplaceObject(self, obj, context):
self._do_reset = True
onReplaceObject = onNewObject
return super(_ZodbComponentTemplateItem, self).onReplaceObject(obj, context)
def afterInstall(self):
"""
......
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