I've created a patch that allows the workflow_select_given_state action to schedule states transitions at a given time after the activation of the trigger (e.g. +1day, +2months). I use it for creating a publishing workflow, where documents are automatically scheduled for review 1 year after their creation, to ensure they are still current.

The only major change to the module is that the workflow_scheduled_transition table needs to be cleaned before the actions are triggered, otherwise the cleaning process will erase the scheduled transition. If anyone knows of a good reason why the cleanup must occur before the trigger, then I'll need to rethink how this could work.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

adaven’s picture

FileSize
6.85 KB

update: some tidying up and an addition form validation check to make sure transition time occurs in the future.

japanitrat’s picture

There is definitely something wrong with the timezone handling, either in workflow_schedule_transition, workflow_transition, or your action modification.

japanitrat’s picture

workflow_schedule_transition likes to have the scheduled date with user/site timezone already applied (which is then eliminated there), but the action is giving the raw scheduled time.

adaven’s picture

FileSize
6.46 KB

Good spot japanitrat. This patch should honour the user timezone properly.

Anonymous’s picture

I want to resurrect this patch and inquire about the possibility of modifying this patch, if you could, to accomodate the scheduling of the email actions as well, the tokenized one more importantly, for me... but I would image it would be roughly the same for both.

Is this something that could be done? I'm not that good at editing php and whatnot that looks this intricate.

Would be an awesome addition to the capabilities of workflow.

Infact, all actions should have a "schedule execution" field that is automated and defined via the action configuration itself, and now by the administrator/user having to trigger the move to another workflow... this makes things more automated, it seems.

Raff

sethcohn’s picture

Bump. Need this sort of functionality.

I was going to reinvent the wheel when I came across this. If it's not destined to be rolled into workflow,
can we (ok, if nobody else pipes up, I) make it a new contrib module adding an 'improved' version of workflow_select_given_state_action maybe called workflow_select_given_state_scheduled_action, (and perhaps an equiv for workflow_select_next_state_scheduled_action)?

Functionally, nothing else does this, and it's such a nifty idea.

Usage case: Add this action to trigger when a node is set to workflowstate1, to schedule after +X time, to transition to workflowstate2. Potentially, that might trigger a new action to schedule moving after +Y time to workflowstate3, etc.

This would allow automatic progression thru a workflow, so for example, write a draft, publish it (workflow1), and after 2 weeks, it'll change to 'older' (workflow2) (and maybe also turn off comments, for example, which is a trivial action to write as well), then after 1 month more, change to 'archive' (workflow3) and add a "behind pay wall" permission/access flag (for example)

Essentially automated, based purely on time after putting it into workflow1.

sethcohn’s picture

Status: Needs review » Needs work

Ok, I've turned the core idea here into a small contrib module, which I'd be glad to share... BUT....

One patch to workflow.module is needed, I believe, because of the ordering of events...
and it's in the above patch which never made it in (and is now pretty obsolete codewise)

function workflow_execute_transition($node, $sid, $comment = NULL, $force = FALSE) {
//snip

  // THIS CLEARING SHOULD BE DONE HERE -- BEFORE the actions will fire off... 

    // Clear any references in the scheduled listing.
  db_query('DELETE FROM {workflow_scheduled_transition} WHERE nid = %d', $node->nid);

  // 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);

  // THIS IS WHERE IT CURRENTLY HAPPENS -- Wiping out any scheduling that actions might have fired off...

    // Clear any references in the scheduled listing.
  db_query('DELETE FROM {workflow_scheduled_transition} WHERE nid = %d', $node->nid);

  // IF A RULE is used, and generates a scheduled change then that's fine, it's after the clearing... 
  // but not an _action_ (which is what Triggers uses for workflow) which is inconsistent!!!!

  // Rules integration
  if (module_exists('rules')) {
    rules_invoke_event('workflow_state_changed', $node, $old_sid, $sid);
  }

  return $sid;
}

Does anyone object to the above change??? (Moving the schedule clearing to BEFORE the "transition post" invocation?) There should be no difference between rules and actions, but here there is... and it's a showstopper for having any scheduling actions for workflow.

sethcohn’s picture

Title: allow workflow_select_given_state_action to schedule transitions » allow workflow actions to schedule transitions
Status: Needs work » Needs review

retitle for clarity, and hopefully fresh eyeballs on proposed minor change to order of calls in main module.

MilanT’s picture

Hello Seth,
The idea you have above is exactly what I am in dire need of. I am using my workflow to go through states and using these state changes to send out emails as notifications(using triggered rules). My workflow consists of states: pending, approved, 2 months till expiration, 1 month till expiration, 10 days till expiration, and expired.

I was curious if the code above is available somewhere for download, or am I to simply paste it into existing workflow module code. I am only a couple of months into using Drupal, so please excuse my ignorance.

Thanks in advance, and great job with this useful addition!!!

Regards,
Milan

q0rban’s picture

Seems like something like this could already be accomplished with Rules?

sethcohn’s picture

q0rban: yes, if you use Rules... but the point here is to fix workflow, not requiring replacing it with the rules module

Bastlynn’s picture

Status: Needs review » Closed (won't fix)

Rules can do this pretty handily.

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.

johnv’s picture

Just to be sure, adding this to the meta issue, as an example.

johnv’s picture