A client wanted a workflow that included automated transitioning between states as content aged. For example Draft -> Live -> Expiring -> Archived where the last two transitions occur automatically after 6 and 1 months respectively.
I was suprised to find no Workflow rules action to schedule a transition. I found a few related issues and patches for earlier versions of Workflow but it seems that it never made it into 7.2.
I could get my automation done using scheduled rules but that seems so clunky when Workflow already has a transition scheduling mechanism. And what happens when manual intervention changes the content's current state such that the scheduled rule no longer applies?
Currently busy coding and testing a 'Schedule a Workflow transition' action myself. Patch to follow soon.
Comment | File | Size | Author |
---|---|---|---|
#15 | workflow-rules-action-and-condition-to-schedule-transaction-2217017-15.patch | 7.89 KB | rpsu |
#1 | workflow_rules-schedule_transition_action-2217017-1.patch | 3.39 KB | RogerB |
Comments
Comment #1
RogerBHere is the patch to add the 'Schedule a Workflow transition' to the available actions in workflow_rules.
Use it in conjuction with the 'Workflow state has changed' event to create a rule that will, on a particular state change, schedule a subsequent change.
Comment #2
johnvLooks good.
I'm not sure if it is useful for your use case, but workflow-extensions contains a token [node:workflow-state-age].
It needs to be ported to this module. See #2148933-8: Check compatibility of 'workflow extensions' with 'workflow' module, version 7.x-2.0 (where this token is not listed ...)
Comment #3
johnv(Using this as a dump for my thoughts)
The following feature request asks the same for the CaseTracker module:
#2220875: Rules integration for casetracker
Comment #4
johnvThe patch in 31 needs to be adapted for workflow_field, and tested on another entity_type, e.g, a taxonomy term.
Comment #5
RogerBPatch not working for 7.x-2.2
I applied the patch to version 7.x-2.2 and it no longer works. User recieved the notice of a future transition being scheduled but no row is created in the workflow_scheduled_transition database table.
Comment #6
RogerBLooking at a database log I see that the workflow_scheduled_transition row is actually inserted but then gets deleted again a bit later.
Not quite sure what is going on but it looks as if the workflow_state_changed event is triggered and the rules processed before the node and its new workflow state is itself saved. When the new state is saved there seems to be a clean-up of any existing scheduled transitions, which makes sense.
Investigating further.
Comment #7
johnvYes, in a recent commit the workflowtransition-execute() function was changed. I think removing the scheduled transition was moved up some lines. It was changed because with multiple workflows per node, too many scheduled transitions were deleted.
This is in 7.x-2.2+dev.
Comment #8
RogerBThis rule action will not work as currently implemented if the transaction that triggers it includes a workflow state transition. It seems that the rule always executes and creates the scheduled transition before the new transition is executed which then deletes the scheduled transition created by the rule. This occurs whatever event is chosen to trigger the rule.
I have implemented a work around for my client which defers the creation of the scheduled transition untill the request has completed and all database updates involved in the transaction has been written. In the action handler I cache the properties of the scheduled transaction and then process them later in a hook_exit().
The action handler:
The hoo_exit() function:
Comment #9
johnvIsn't the problem that your rule runs too early?
I think your rule is triggered while changing the state (i.e. the new state hasn't been saved, yet.)
I you choose the event "after node/entity save", it should be working.
With workflow_node you could also choose the event that is triggered by workflow-rules upon 'post transition'.
Your cruk_workflow_exit() shouldn't be necessary.
See also this project page using Rules to invoke actions after a period of inactivity
Comment #10
johnvComment #11
rpsuI added a new workflow scheduling rule which can be use to schedule transitions (which Workflow is taking care of after that). Leanign on patch in #1 and other comments.
This patch allows use of this Rule where date is taken from field field_state_dates (starting date) and workflow is update in field field_workflow_state:
Comment #12
rpsuI think this should refer to meta-task #486592: Schedule a following Fixed date transition (instead of pointing to @self as parent)
Comment #13
phillipclarke29 CreditAttribution: phillipclarke29 commentedI have successfully added the patch in #11 - but I cannot figure out how to write the rule. I am trying to automatically change the state of a node from "live" to "archived" 1 month after the node's state was changed to "live". Any help would be appreciated.
Comment #14
rpsuI see that you might have two different scenarios:
Either you have to track publishing date with perhaps a new date field and act on that date - when "Node is updated". On node update and with that field you should be able to schedule workflow state change.
Or maybe you have automated publishing based on alredy existing date field? If so, then you should be able to use the same date field for archiving, since rule "State change date (field)" has a (collapsed?) fieldset "Add offset" which includes and offset. You may set it to "+1 months" or similar in your case.
Comment #15
rpsuThis patch allows admin to
- ACTION to schedule workflow field state change based on node published et al. datestamp or a date field value (optionally with time offset)
- (added) CONDITION to verify that workflow field is at required state
With this admin can schedule for example "Published" nodes to change to "Locked" or "Archived" based on node publishing date or separate date field.
NOTE: patch #11 contains by mistake dpm() -calls so do not use that.
Comment #16
gstout CreditAttribution: gstout commentedI'm testing this patch in #15 now. I'll report back.
Comment #17
rpsuRe-assigning Needs review for testbot.
Comment #18
rpsuComment #19
g33kg1rl CreditAttribution: g33kg1rl commentedI need to automatically transition from one workflow state, 'Available' to another workflow state, 'Needs To Be Assigned', if the workflow state is not changed to, 'Claimed / Assigned', in 24 hours. Is that possible without the workflow extensions module (as mentioned above)?
Comment #20
johnvYou don't need that. Please apply and test patch 15 or before.
Comment #21
g33kg1rl CreditAttribution: g33kg1rl commentedDo we have to add a date field that stores the workflow transition date or can we use a token?
Comment #22
johnvWe have a token 'how long is the entity in this state'.
Comment #23
g33kg1rl CreditAttribution: g33kg1rl commentedHow do I get that token to be available?
Comment #24
g33kg1rl CreditAttribution: g33kg1rl commentedbump
Comment #25
johnvSome remarks for this request, and the patch #15
#2237125: Adopt tokens from workflow_extensions
Patch 15 adds a workflow_field_check_state. IMO this is not necessary, and is explicitly removed, (in comparison with workflow_node) since you can simply check the field value.
Comment #26
Neeraj420 CreditAttribution: Neeraj420 as a volunteer commentedI am getting following error message when adding a task Schedule a workflow state change with comment.
Unknown action workflowfield_field_schedule_state_change.
If I add a condition field has a workflow state I get the error message : Unknown condition workflow_field_check_state.
Rule is triggered and content is updated.
Comment #27
Neeraj420 CreditAttribution: Neeraj420 as a volunteer commentedIn my installation Cache was not enabled.
So I thought clearing the cache is not required. However after clearing the cache did the trick and it was working fine.
Is there any way of deleting the the schedule task?
Comment #28
johnvPlease check the src/Event directory in version 8.x for alternatives and example code.
Comment #29
johnv