Commit e14aabd8 authored by Nicolas Dumazet's avatar Nicolas Dumazet

As far as I can tell, we only ever user trigger_workflows

If this is not the case, we should adapt code registrating methods
to skip non-triggers instead of checking invalid transitions all the
time. Hence the assert.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42720 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 18c631fd
...@@ -226,19 +226,19 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject): ...@@ -226,19 +226,19 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
for t_id in transition_list: for t_id in transition_list:
tdef = self.interactions[t_id] tdef = self.interactions[t_id]
if tdef.trigger_type == TRIGGER_WORKFLOW_METHOD: assert tdef.trigger_type == TRIGGER_WORKFLOW_METHOD
if (tdef.portal_type_filter is None or \ if (tdef.portal_type_filter is None or \
ob.getPortalType() in tdef.portal_type_filter) and \ ob.getPortalType() in tdef.portal_type_filter) and \
self._checkTransitionGuard(tdef, ob, **kw): self._checkTransitionGuard(tdef, ob, **kw):
filtered_transition_list.append(tdef.id) filtered_transition_list.append(tdef.id)
former_status = self._getStatusOf(ob) former_status = self._getStatusOf(ob)
# Execute the "before" script. # Execute the "before" script.
for script_name in tdef.script_name: for script_name in tdef.script_name:
script = self.scripts[script_name] script = self.scripts[script_name]
# Pass lots of info to the script in a single parameter. # Pass lots of info to the script in a single parameter.
sci = StateChangeInfo( sci = StateChangeInfo(
ob, self, former_status, tdef, None, None, kwargs=kw) ob, self, former_status, tdef, None, None, kwargs=kw)
script(sci) # May throw an exception script(sci) # May throw an exception
return filtered_transition_list return filtered_transition_list
...@@ -256,62 +256,62 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject): ...@@ -256,62 +256,62 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
for t_id in transition_list: for t_id in transition_list:
tdef = self.interactions[t_id] tdef = self.interactions[t_id]
if tdef.trigger_type == TRIGGER_WORKFLOW_METHOD: assert tdef.trigger_type == TRIGGER_WORKFLOW_METHOD
if (tdef.portal_type_filter is None or \ if (tdef.portal_type_filter is None or \
ob.getPortalType() in tdef.portal_type_filter): ob.getPortalType() in tdef.portal_type_filter):
# Initialize variables # Initialize variables
former_status = self._getStatusOf(ob) former_status = self._getStatusOf(ob)
econtext = None econtext = None
sci = None sci = None
# Update variables. # Update variables.
tdef_exprs = tdef.var_exprs tdef_exprs = tdef.var_exprs
if tdef_exprs is None: tdef_exprs = {} if tdef_exprs is None: tdef_exprs = {}
status = {} status = {}
for id, vdef in self.variables.items(): for id, vdef in self.variables.items():
if not vdef.for_status: if not vdef.for_status:
continue continue
expr = None expr = None
if tdef_exprs.has_key(id): if tdef_exprs.has_key(id):
expr = tdef_exprs[id] expr = tdef_exprs[id]
elif not vdef.update_always and former_status.has_key(id): elif not vdef.update_always and former_status.has_key(id):
# Preserve former value # Preserve former value
value = former_status[id] value = former_status[id]
else:
if vdef.default_expr is not None:
expr = vdef.default_expr
else: else:
if vdef.default_expr is not None: value = vdef.default_value
expr = vdef.default_expr if expr is not None:
else: # Evaluate an expression.
value = vdef.default_value if econtext is None:
if expr is not None: # Lazily create the expression context.
# Evaluate an expression. if sci is None:
if econtext is None: sci = StateChangeInfo(
# Lazily create the expression context. ob, self, former_status, tdef,
if sci is None: None, None, None)
sci = StateChangeInfo( econtext = createExprContext(sci)
ob, self, former_status, tdef, value = expr(econtext)
None, None, None) status[id] = value
econtext = createExprContext(sci)
value = expr(econtext) sci = StateChangeInfo(
status[id] = value ob, self, former_status, tdef, None, None, kwargs=kw)
# Execute the "after" script.
sci = StateChangeInfo( for script_name in tdef.after_script_name:
ob, self, former_status, tdef, None, None, kwargs=kw) script = self.scripts[script_name]
# Execute the "after" script. # Pass lots of info to the script in a single parameter.
for script_name in tdef.after_script_name: script(sci) # May throw an exception
script = self.scripts[script_name]
# Pass lots of info to the script in a single parameter. # Execute Before Commit
script(sci) # May throw an exception for script_name in tdef.before_commit_script_name:
transaction.get().addBeforeCommitHook(self._before_commit,
# Execute Before Commit (sci, script_name))
for script_name in tdef.before_commit_script_name:
transaction.get().addBeforeCommitHook(self._before_commit, # Execute "activity" scripts
(sci, script_name)) for script_name in tdef.activate_script_name:
self.activate(activity='SQLQueue')\
# Execute "activity" scripts .activeScript(script_name, ob.getRelativeUrl(),
for script_name in tdef.activate_script_name: status, tdef.id)
self.activate(activity='SQLQueue')\
.activeScript(script_name, ob.getRelativeUrl(),
status, tdef.id)
def _before_commit(self, sci, script_name): def _before_commit(self, sci, script_name):
# check the object still exists before calling the script # check the object still exists before calling the script
......
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