Hi,
in workflow_execute_transition():
// Notify modules that transition has occurred. Actions should take place
// in response to this callback, not the previous one.
module_invoke_all('workflow', 'transition post', $old_sid, $sid, $node);
// Clear any references in the scheduled listing.
db_query('DELETE FROM {workflow_scheduled_transition} WHERE nid = %d', $node->nid);
This means that the hook is run before the transitions are deleted from the table. Result - i can't respond to a state transition in the hook by scheduling another transition, because the code will delete it immediatelly.
It should be fairly simple to just switch both lines...
| Comment | File | Size | Author |
|---|---|---|---|
| workflow_transition.patch | 1.25 KB | meba |
Comments
Comment #1
meba commentedAdding a tag
Comment #2
meba commentedIs anybody interested in this issue?
Comment #3
donquixote commentedI am not directly affected by this issue, just found it via google, but it immediately makes sense to me.
Comment #4
q0rban commentedCan you elaborate on this for me? Give me a good example of what you might be trying to do. To me, it makes sense for the hook to run before the action is taken, so that the implementer may query any data beforehand.
Also, moving this to 2.x.
Comment #5
donquixote commentedAs the topic starter said,
Now the newly scheduled transition will be deleted before it can be executed.
Alternative:
- Query SELECT existing transitions for the respective node nid, and store them in a $deleted_transitions array. Maybe with a few JOIN LEFT to fetch state names etc.
- Delete existing transitions for the node nid.
- module_invoke_all('workflow', 'transition post', $old_sid, $sid, $node, $deleted_transitions), with the deleted transitions as an argument.
Comment #6
meba commentedAs previous responder stated - the issue is that you cannot schedule a transition INSIDE a workflow function, because the delete will remove it.
I would personally say it's a bug, therefore belongs to 1.x? (We run workflow 1.x and therefore need to have a patched version). The alternative approach makes sense and I will make a patch if you say you will be able to commit it to 1.x (that's what everybody uses anyway)
Comment #7
donquixote commentedI guess it has to go to 2.0 first and then will be backported, as with most projects. Just don't forget the backport..
Comment #8
q0rban commentedOh, ok I understand the problem. Thank you for re-iterating it for me, for some reason on the first read through it didn't quite register. :) I'll move this back to 1.x.
Comment #9
meba commentedWhat solution do you prefer? The easy patch I made or something alternative that records deletes first, performs the hook and then does the deletion?
Comment #10
Bastlynn commentedSince this request is over a year old, I'm going to assume a solution was found or you've moved on. If not, please get updated to the latest versions of all modules and make a request for it against Drupal 7 and I'll be glad to take a look at it.