Well, I am not quite sure if it belongs to Rules issue queue or Integration queue, but anyway. Hopefully it will help someone to solve their issues using Rules and Tokens modules. I decided to post it here mostly because I was able to solve (workaround) my problem completely on Rules module side.
I have CCK, CCK Comment, Token and Rules modules installed.
I allowed some CCK fields to be changed with comments (that is what CCK Comment module is for).
Then I created a rule "After publishing a comment" to e-mail some users with changed CCK field values.
But users were receiving OLD unchanged values instead of NEW ones all the time!
Okay, I have checked modules' weights and played with them a bit to no avail.
I also tried to add an action to my rule to Load the Node by ID (the commented node ID, of course) before sending out e-mail. Nothing has changed.
Then I decided to move this action (Load Node by ID) to separate rule and I have set this new rule weight so it should be evaluated before e-mail rule. And it solved my problem!
The fault of Rules module (as I see it) is sorting actions by their weights achieved nothing, but separating these actions into different rules and setting rules' weights allowed me to solve the problem.
Am I correct in thinking Action weights do not work the way they are supposed to?
Comments
Comment #1
jsm174 commentedHello. I just ran into this same issue.
I have a node with a cck date field and an approved flag. When an admin sets the approved flag, we send out an email to the user.
Sometimes the admin will update the cck date field and check the approved flag in one step.
When this happens an email gets sent with the old cck date field value.
I didn't see Load Node by ID, but rather Load Content by ID. I used the token [node:nid].
Comment #2
Azol commentedCheck #212364: Update comment revision id for possible solution if you are using Comment CCK to update the fields.
P.S. To elaborate: go to the comment_cck.module and locate the
function comment_cck_comment(&$comment, $op)line.Add the
node_load($comment['nid'], NULL, TRUE);line at the very end ofcase 'update':andcase 'insert':blocks (right before the closing }).Voila.
Comment #3
fagoWell token has a caching mechanism. Rules deals with that thus it won't apply as long as you use tokens in rules only, but if other modules are using tokens too you might get version cached when the other module requested the token.
Comment #4
Azol commentedThe main issue here: the Load content (a node) should be able to refresh the cached version of node tokens...
Maybe we should add a "Clear cache" action to available Rules actions? There are many issues Tokens vs. Rules and most of them will be solved simply by adding this action.
If this sounds unreasonable, another way is, of course, to patch other modules (like the Comment CCK patch here) to play correctly with Rules. Then we should probably mark this issue as "By design" and close it.
Ideas?
Comment #5
fagoI think a "Clear token cache" action would make sense - best roll a patch for the token module.
Comment #6
Azol commentedToken already offers cache control functionality - see #12 in #262360: Expose control of token caching to functions that call token_replace
We also have control over node cache in node_load function: http://api.drupal.org/api/function/node_load
Comment #7
anrikun commentedRelated issue here: #1167328: Rules integration: [node_unchanged:field_XXXXX] returns updated node content
Please review the provided patch to see if it fixes your issues.
I suggest this issue is marked as Closed (won't fix) as it is a Token issue.
Comment #8
itangalo commentedFor information: The Rules Bonus Pack module has an action for getting CCK field values directly from a loaded node object – bypassing tokens. (This action was made as a workaround to the very problem described here.)
Check out http://drupal.org/project/rb for more information.
Changing issue status to "won't fix", by suggestion of previous comment.
Comment #9
mitchell commentedUpdated component.