Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Trying to upgrade from version 7.x-1.4 to 7.x-3.0. I notice my rule that is using "Content's current moderation state" seems to have stopped working.
The trigger for the rule is "After moderation transition"
while debugging the following code:
function workbench_moderation_rules_condition_contents_current_state($node, $moderation_state) {
if (!is_object($node)) {
return FALSE;
}
$state = (!empty($node->workbench_moderation)) ? $node->workbench_moderation['current']->state : $node->workbench_moderation_state_current;Change to rules after upgrade to 7.x-3.0
if ($state != $moderation_state) {
return FALSE;
}
return TRUE;
}
I get these results:
7.x-3.0: $state = "draft", so when publishing the node this function returns false
7.x-1.4: with the same setup: $state = "published"
Comments
Comment #2
kcolwell CreditAttribution: kcolwell commentedI experienced the same problem and basically had to switch my rules backwards to get them to work.
Comment #3
wsantell CreditAttribution: wsantell commentedIt appears that the condition "Content's current moderation state" is reporting the last moderation state.
For example, say I have a notification email that gets sent to a different role at each state change. In 7.x-1.4, this worked similar to this:
In 7.x-3.0, this is what is happening now:
In reality there are many more states and if, for example, a node went from state 2 to state 7 to state 8, the email associated with moving from 2 to 7 will be sent when moving from 7 to 8. In summary, it reports last state, not (current state - 1).
Comment #4
ecoluke CreditAttribution: ecoluke commentedI am also now experiencing this issue.
When the event "after moderation transition" fires the moderation state that it thinks the node is now in is actually the state that it was previously in.
So if I save a node and update it from Draft -> Published it thinks I just set it to Draft.
If I then set it from Published->Draft it thinks it is in Published.
As noted above, this is highly problematic if there are more than 2 states, which in my use case there are.
EDIT - If I set up rules like this:
Event: create new content, update existing content
Condition: workflow state = foo
Then those rules are also not triggered.
Comment #5
Anskelt CreditAttribution: Anskelt at Lund University commentedDon't know about if this solves all the issues. But for me, my problem was solved with specifically setting current revision with the correct states. This code was in 1.4, but not in 3.0.
was made from 3.0 tag since its the one we are using.
I hope it will solve the issue in the end.
Comment #6
wsantell CreditAttribution: wsantell commentedThanks Anskelt, that patch works for me.
Comment #7
rliYep this is where we should set the current state, so the node object will carry the real current state. Working for me now.
Comment #8
rliComment #11
Anskelt CreditAttribution: Anskelt at Lund University commentedI tried to run the tests locally, I get the same error for a clean version of workbench moderation as with the patch.
Comment #12
gluebox CreditAttribution: gluebox as a volunteer commented#5 was a life saving quick fix. Big Thanks Anskelt.
Comment #13
cmah CreditAttribution: cmah commented#5 worked for me as well. Thank you.
Comment #14
joncjordan CreditAttribution: joncjordan commented#5 worked for me too, thanks!
Comment #15
gunzip CreditAttribution: gunzip commented#5 works for me
Comment #16
bpadaria CreditAttribution: bpadaria commentedThanks Anskelt, Given patch worked for me as well
Comment #17
das-peter CreditAttribution: das-peter at Cando commentedComment #18
mstrelan CreditAttribution: mstrelan commentedIs this related to #1568272: Rules conditions for moderation states should compare my_revision? The patch in #5 works for me too.
Comment #19
wylbur CreditAttribution: wylbur as a volunteer commentedComment #20
nubeli CreditAttribution: nubeli commentedI'm testing patch #5 and added a message to output the moderation state tokens in the Rules action. Going from "Draft" to "Needs review" states, before applying the patch the tokens are:
[previous-state:value]: draft
[new-state:value]: needs_review
After the patch:
[previous-state:value]: needs_review
[new-state:value]: needs_review
Oddly the tokens don't seem to agree with the Rules conditions. As others have pointed out above the "Content's current moderation state" condition shows the previous state (in 3.x) even though the [new-state:value] token shows the actual current state. It looks like the patch then messes up the [previous-state:value] -- likely inherits the value from this patch and shows the new state rather than the previous.
Comment #21
allenthehusband CreditAttribution: allenthehusband commented#5 did the trick for us as well.
Comment #22
leducvin CreditAttribution: leducvin commentedYep, patch in #5 seems to work well.
Comment #24
elly CreditAttribution: elly commentedHi,
I was having the same problem with rules not evaluating the current moderation state properly and the patch in #5 solved the problem. However I noticed after applying this patch, workbench emails (provided by workbench_email module) are no longer being sent. I haven't dug into exactly why but wanted to note it here in case anyone else runs into the same issue with this patch.
Comment #25
matt.mendonca CreditAttribution: matt.mendonca commentedTL;DR the line $node->workbench_moderation['my_revision'] = $new_revision; in patch #5 seems to break workbench email without doing anything to fix the rules integration and can be removed based on initial debugging.
-----------------
Even though patch in #5 fixes the rules integration for me I'm also seeing the workbench email issue (#24).
The email issues seems to be caused by the old and new states being the same (#20). Since the email reacts on transitions from different states, it never fires. Taking a look at the patched code:
$node->workbench_moderation['my_revision'] and $node->workbench_moderation_state_new are effectively set to the same value (the new revision). The problem is that those two variables are passed into the moderation transition hook as the old and new state respectively. This is incorrect according to the hook defintion (http://cgit.drupalcode.org/workbench_moderation/tree/workbench_moderatio...) and also the workbench email code:
On the other hand, the patch fixes the Rules current moderation state because Rules only cares about $node->workbench_moderation['current']:
By removing the line $node->workbench_moderation['my_revision'] = $new_revision;, Rules integration seems to be fixed without breaking workbench email. New patch and diff attached.
Comment #26
herved CreditAttribution: herved commentedThe analysis from matt.mendonca makes sense to me.
Here's an updated patch with minors coding standards fixes and whitespace fix.
Switching to needs review: let's see the simpletest results.
Comment #27
sleahcc CreditAttribution: sleahcc commentedJust tested the patch from #26 on Drupal core 7.56 with Workbench Moderation 7.x-3.0. Patch applies cleanly and appears to fix the problem.
Comment #28
santiwww CreditAttribution: santiwww as a volunteer commented#26 tested also with Drupal 7.56 and Workbench Moderation 7.x-3.0 and works ok as well.
Comment #29
brayfe CreditAttribution: brayfe commentedThe patch in #26 worked for me! Finally, rules that make sense again!
Drupal: 7.56
Workbench Moderation: 7.x-3.0
Rules: 7.x-2.10
Comment #30
dshields CreditAttribution: dshields commentedIn case anyone is interested, this patch also fixes https://www.drupal.org/project/workbench_notifier which (without this) only notifies users or the second-most recent transition.
Comment #31
delacosta456 CreditAttribution: delacosta456 commentedhi @dshields
Many thanks for this infos
Comment #32
NicholasSPatch #26 also worked for me. THANK YOU!
Comment #33
teknikqaI have been using this patch in production for many months. Would be great to have this committed.
Comment #34
Delphine Lepers CreditAttribution: Delphine Lepers at Trasys for European Commission and European Union Institutions, Agencies and Bodies commentedInstead of pushing the revision content into the current like done in the patches suggested, think it makes more sense to change the rule and test the new revision state, just like it's done in the module invoke:
module_invoke_all('workbench_moderation_transition', $node, $node->workbench_moderation['my_revision']->state, $node->workbench_moderation_state_new);
Therefore i would test the new current state on workbench_moderation_state_new instead, this way you can still access the information from the current-before-save version, which i do need in my case.
Comment #35
MingsongThanks Delphine Lepers,
I tested patch #34 for my sites via following cases, it did work for me.
patch #34 makes more sense to me.
Good work.
Comment #36
Delphine Lepers CreditAttribution: Delphine Lepers at Trasys for European Commission and European Union Institutions, Agencies and Bodies commentedTo be complete, the previous state should be fixed as well.
I am attaching a new version
Comment #37
jlancaster CreditAttribution: jlancaster commentedThere seem to be two equally viable approaches in this thread. If for some reason the first method of addressing the issue within workbench_moderation_save() is not acceptable, I think that patch #36 needs a tweak in order to not return true when you're not looking at the current version ($node->is_current). Patch attached.
Without this additional logic, a user would see unexpected triggering of a rule when checking a specific state (on existing content) since the previous state matched and was also evaluated in the workbench_moderation_rules_condition_contents_current_state() function.
Comment #39
jlancaster CreditAttribution: jlancaster commentedMy last file upload failed validation due to no line at end of file. Fixed patch attached.
Comment #40
jyraya CreditAttribution: jyraya at European Commission and European Union Institutions, Agencies and Bodies commentedIndeed, we have 2 approaches to fix this issue.
At first sight, I am in favour of the "workbench_moderation_save()" approach because it is more central and respects the chronology of the events as called in implementations of the "hook_node_insert" and "hook_node_update" called in "node_save"; I.E.:
"Rules" triggers also node related rules between the node save and the node save transaction commit; I.E. but through implementations of hook_entity_update or hook_entity_insert instead of implementations of hook_node_update or hook_node_insert.
I added "virtually" in the 2nd point because the transaction where the node is saved is not committed yet; which means the newly saved data are not available for other queries.
It is when all hook_node_update and hook_entity_update, or hook_node_insert and hook_entity_insert + the cache reset, that the transaction will be committed and the node data will be effectively persisted (see doc of hook_node_update, hook_node_insert and node_save).
But if we choose this approach, should we be consistent and passing the state set in the "current" item in the "workbench_moderation_transition" invocations like in the example below?:
module_invoke_all('workbench_moderation_transition', $node, $node->workbench_moderation['my_revision']->state, $node->workbench_moderation['current']->state);
Comment #41
Delphine Lepers CreditAttribution: Delphine Lepers at Trasys for European Commission and European Union Institutions, Agencies and Bodies commentedThe same kind of fix as #36 was suggested on issue 1568272 long ago https://www.drupal.org/project/workbench_moderation/issues/1568272
I agree with the comment that if patch #26 is chosen, they the invoke_all function should be adapted
@jlancaster #39 did not pass the tests.
Comment #42
jyraya CreditAttribution: jyraya at European Commission and European Union Institutions, Agencies and Bodies commentedAfter further tests, I change my mind about the way to fix this ticket.
On the paper, the fix in "workbench_moderation_save" is great because it allows to fix multiple issues at once but my last tests show that it does not fix the issue when we define a rule on the "Before saving content" event.
Indeed, this kind of rules is triggered in a hook_node_presave while the "workbench_moderation_save" function is called after the node saving.
Then, the fix has no effect on the rule behaviour in this case while the patch based on an modification in the functions "workbench_moderation_rules_condition_contents_current_state" and "workbench_moderation_rules_condition_contents_previous_state", works.
I provide a new patch because the #38 patch raised a PHP notices with a rule on a rule on the "Before saving content" event:
Then, the "workbench_moderation_rules_condition_contents_previous_state" function does not work in this case.
Then, I propose a new "workbench_moderation_node_is_current_revision" function that check if the tested node review is the current one whatever the case.
This function is different from "workbench_moderation_node_is_current" because this one is focused on the live node revision which it is not what we want here.
Comment #43
jyraya CreditAttribution: jyraya at European Commission and European Union Institutions, Agencies and Bodies commentedComment #44
yemoko CreditAttribution: yemoko commentedHi all,
I tested the patch #42, it's working in my configuration.
@Anskelt, did you had time to review it?
K.R
Comment #45
richardcanoe CreditAttribution: richardcanoe commentedTested #42
All working as expected
Comment #46
jyraya CreditAttribution: jyraya at European Commission and European Union Institutions, Agencies and Bodies commentedDuring further tests, my team discovered that the patch #42 generates the following PHP notice when we define a rules applied to any content type; even those that are not moderated:
I corrected my patch in consequence. I posted also the interdiff.
Comment #47
myersca CreditAttribution: myersca commentedI have tested the #46 patch and it works.
Comment #48
jyraya CreditAttribution: jyraya at European Commission and European Union Institutions, Agencies and Bodies commentedCould we consider it as RTBC?
Comment #49
Anskelt CreditAttribution: Anskelt at Lund University commented#46 seems to have done the trick, works fine for me as well, good job @jyraya
Comment #50
alansaviolobo CreditAttribution: alansaviolobo commented+1 for patch in #46
Comment #51
alansaviolobo CreditAttribution: alansaviolobo commented+1 for patch in #46
Comment #52
smuthu CreditAttribution: smuthu commented+1 for patch in #46
Comment #53
undersound3 CreditAttribution: undersound3 commentedCreated a patch against 7.x-3.0
Comment #54
alex.skrypnykRe-roll of #53 for 7.x-3.0