Download & Extend

hook_workflow - delete before execute (Not possible to schedule another transition)

Project:Workflow
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (won't fix)
Issue tags:workflow

Issue Summary

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...

AttachmentSize
workflow_transition.patch1.25 KB

Comments

#1

Adding a tag

#2

Is anybody interested in this issue?

#3

I am not directly affected by this issue, just found it via google, but it immediately makes sense to me.

#4

Version:6.x-1.x-dev» 6.x-2.x-dev
Status:needs review» postponed (maintainer needs more info)

Can 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.

#5

As the topic starter said,

<?php
function mymodule_workflow($op, $old_sid, $sid, $node) {
 
// don't know the exact name of the function that would schedule a transition
 
_mymodule_schedule_transition($node->nid, ..);
}
?>

Now the newly scheduled transition will be deleted before it can be executed.

To me, it makes sense for the hook to run before the action is taken, so that the implementer may query any data beforehand.

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.

#6

Status:postponed (maintainer needs more info)» active

As 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)

#7

I guess it has to go to 2.0 first and then will be backported, as with most projects. Just don't forget the backport..

#8

Version:6.x-2.x-dev» 6.x-1.x-dev

Oh, 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.

#9

What solution do you prefer? The easy patch I made or something alternative that records deletes first, performs the hook and then does the deletion?

#10

Status:active» closed (won't fix)

Since 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.

nobody click here