Well.. I'm following the code here in order to explain it
Easiest case is to explain it is using scheduled transitions when executed by cron.
So let's say we have a scheduled transition and it's the proper time for it to be executed:
First of all, in hook_cron, scheduled transitions are set to be forced, but a $forced variable is not set in workflow_execute_transition.
$scheduled_transition->force(TRUE);
workflow_execute_transition($entity_type, $entity, $field_name, $scheduled_transition);
In workflow_execute_transition function if "force" is not set as variable it's considered false:
function workflow_execute_transition($entity_type, $entity, $field_name, $transition, $force = FALSE)
In workflow_execute_transition if force is set to TRUE, transition is set to true as well, but if not nothing happens (that's the first point where transitions force variable could have been taken into account)
if ($force) {
$transition->force($force);
}
$new_sid = $transition->execute($force = TRUE);
Now, following the code, I see the same pattern in "execute" function:
public function execute($force = FALSE) {
....
if ($force) {
$this->force($force);
}
But the rest of the execution considers "$force" as the transition force variable and completely ignores is transition is otherwise set to be forced.
Proposed Solution:
1.
Maybe in hook cron, the line should change from
workflow_execute_transition($entity_type, $entity, $field_name, $scheduled_transition);
to:
workflow_execute_transition($entity_type, $entity, $field_name, $scheduled_transition,TRUE);
(so the $force variable would pass as TRUE until execution).
2.
Another option (and possibly better in my opinion is than in execute function transition's force variable should be taken into account by adding this line after (possibly) setting the force variable in transition:
$force = $this->isForced();
3. Both the above.. Maybe because they could be 2 different cases where this might matter.
Comment | File | Size | Author |
---|---|---|---|
#2 | workflow-set-force-properly-2805217-2.patch | 1.12 KB | Zekvyrin |
Comments
Comment #2
Zekvyrin CreditAttribution: Zekvyrin commentedAnd here is a patch containing both the proposed solutions.
Comment #3
Zekvyrin CreditAttribution: Zekvyrin commentedComment #4
johnvBelow issues are related:
#2805217: Transition's "force" property is not taken into account when executed.
#2724199: workflow_execute_transition() does not respect FORCE parameter
Comment #6
johnvThanks. See also the other issue.
Comment #7
johnvComment #8
johnvLet's check if this is needed in D8 version.
Comment #10
johnvOK, fixed over there, too.