I am having the problem with the unchanged user having the same roles as the changed user referenced in workflow-ng issue #327781: unchanged user is getting changed roles
The workflow use-case is as follows:
When a new role is added to a user, send the user email about this.
To do this, I use 2 conditions: Updated User has a new role and Unchanged User does not have that role.
I thought I tested this and had it working under the release candidate 1 but shortly after installing release candidate 2 I have noticed this problem though according to the release notes this shouldn't be related.
I am running php5 on my server and this problem should have been fixed in rules 6.x-1.0-beta5:
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | RuleMainScreen.png | 57.42 KB | BenK |
| #12 | UnchangedUser.png | 55.7 KB | BenK |
| #12 | UpdatedUser.png | 55.12 KB | BenK |
| #12 | EmailAction.png | 48.72 KB | BenK |
| #11 | roles.txt | 2.51 KB | klausi |
Comments
Comment #1
deverman commentedno one else also has this problem in d6?
Comment #2
BenK commentedI am experiencing the same problem in D6. My use case is exactly the same: My rule states that Updated User has a new role and Unchanged User does not have that role. But apparently a bug exists in which the prior roles of the Unchanged User is not being evaluated. Any workarounds for this?
Comment #3
BenK commentedComment #4
alexgreyhead commentedJust encountered this myself today, Views 6.x-1.0. The first array is the $account, and the second is $account_unchanged after I removed one role (72 - "hidden and test accounts"). Note that exactly the same number of roles exist in both arrays (as far as I can tell):
$account->roles = Array
(
[2] => authenticated user
[3] => web developer
[4] => site administrator
[5] => web designer
[25] => website assistant - home area
[27] => comment moderator
[30] => website assistant - homepage editor
[31] => staff member
[33] => FAQs editor
[59] => AD: WebTeam
[61] => AD: ALL Temp Staff
[62] => AD: Printworks Users
[65] => AD: IT Support
[72] => hidden and test accounts
[114] => workflow - content creator
[138] => store administrator
[145] => website assistant - document warehouse curator
[154] => User Creator
[174] => website assistant - extranet (all pages)
[176] => debuggers (snigger)
[181] => prospectus editor
[182] => AD: KSS VPN Users
[185] => website assistant - webteam
[190] => website assistant - it support department
[196] => website assistant - system pages
[200] => workflow - approvers - presentation standards
[201] => workflow - approvers - departmental sign-off
[202] => workflow - approvers - proof-readers
[205] => AD: IT
[206] => AD: User and Computer Accounts
)
$account_unchanged->roles = Array
(
[61] => 61
[205] => 205
[65] => 65
[182] => 182
[62] => 62
[206] => 206
[59] => 59
[27] => 27
[176] => 176
[33] => 33
[72] => 72
[181] => 181
[4] => 4
[31] => 31
[138] => 138
[154] => 154
[5] => 5
[3] => 3
[145] => 145
[174] => 174
[25] => 25
[30] => 30
[190] => 190
[196] => 196
[185] => 185
[201] => 201
[200] => 200
[202] => 202
[114] => 114
[2] => authenticated user
)
Comment #5
BenK commentedAny ideas on how to fix this?
--Ben
Comment #6
klausiAre you using PHP 4?
Because Rules is using drupal_clone() for the user account, which actually does not clone on PHP 4, so the reference to the old account may be populated with the new stuff.
http://api.drupal.org/api/function/drupal_clone/6
Just a guess.
Comment #7
deverman commentedI am using php5
Comment #8
BenK commentedI'm also using php5 and experiencing the bug... so I don't think it's a php4 vs. php5 issue.
--Ben
Comment #9
klausiI justed tested this with the event "User account details have been updated" and compared $account_unchanged and $account. They work as expected, the unchanged account does not contain the role and the new account includes the new role.
Make sure that you get your conditions right.
Comment #10
BenK commentedHey klausi,
Thanks for the note. What version of Rules were you using to test? If it was the 6.x-1.x-dev version, from what date did you download?
Thanks,
Ben
P.S. How did you compare $account and $account_unchanged? I'll try to do my own test....
Comment #11
klausiI use the most recent CVS dev version of Rules. I installed the devel module to output the variables. The export of my test rule is attached.
Comment #12
BenK commentedklausi,
I've tried the latest dev version of Rules but I'm still getting the same problem. Is it possible the problem lies in the action and not in the trigger?
To double-check it's not a configuration error, I've attached screenshots of my Rule. I'm basically trying to notify users when they are upgraded from a regular authenticated user to a "Camp Participant" role.
So I've set up the rule to evaluate true when the unchanged user is NOT a "Camp Participant" and the changed user is a "Camp Participant." When this occurs, an email is supposed to fire to the user, but this is not occurring.
Please see the attached configuration screen shots....
Thanks a million,
Ben
Comment #13
BenK commentedComment #14
BenK commentedAny more ideas on this?
Thanks,
Ben
Comment #15
BenK commentedHey everyone,
I just tried the latest -dev version of Rules and I'm still getting this problem. I also tried the Rules export in #6 above and it didn't work either. Very frustrating.
Basically, when neither the unchanged or the updated user have the specified role everything works properly. Printing the debug message is see that:
0.47 ms Condition "User has role(s)" evaluated to FALSE.
0.737 ms Condition "User has role(s)" evaluated to FALSE.
But as soon as either the unchanged user or the updated user has the role, only one condition is checked. Here's the debug info:
0.519 ms Condition "User has role(s)" evaluated to TRUE.
It doesn't matter if the unchanged user has the role, the updated user has the role, or both have the role, the above statement will always display.
Is the unchanged user information still available in the "User account details have been updated" event? Or do we need a new "User account details is going to be updated" event to make this work properly.
--Ben
P.S. Someone else should try the export in #6 as a test... it didn't work for me at all and the problem persists.
Comment #16
robby.smith commentedsubscribing
Comment #17
fagoMaybe this depends on the situation the event is invoked to work or work not. So how do you update your user account and klausi how did you?
Comment #18
BenK commentedFago, thanks for the note.... I'm not doing anything particularly fancy with how the user account is updated. Basically, a site administrator comes to the user's account page, changes the role, and then clicks save.
But could there be a difference if an administrator is changing the role of the user, rather than the user changing the role himself (this is my use case)? Maybe klausi is just having the user changing his own role (assuming that the user is privileged)?
I'm not sure if that could be significant....
--Ben
Comment #19
YK85 commentedsubscribing
Comment #20
klausiI just tested it again and it works for me as expected. It works when the user changes her own roles and when an administrator changes the roles of a user. I debugged the variables $account_unchanged and $account and they contain the correct roles in both scenarios. Also the conditions "user has role(s)" do what they should do.
@BenK: I also built a rule with the same conditions as you did and it works fine for me.
Comment #21
Witch commentedusing the latest version of the rules module. i experienced the same bug.
Comment #22
sliph commentedJust throwing this out there, but I was having a problem where I couldn't get rules to trigger on a uc_roles role expiration. It turns out that uc_roles was changing the $account parameter being passed to user_save to have the same roles as the actual updated node.
So if you're having problems with unchanged / updated users having similar information, dig around in the code doing the user_save and make sure it's not touching the $account variable pre-save.
Comment #23
fagofixing title
Comment #24
webmasterkai commentedTry this. It fixed it for me.
rules/rules/modules/user.rules.inc line 191
before $user->roles[$rid] = $role_list[$rid];
after $roles[$rid] = $role_list[$rid];
rules/rules/modules/user.rules.inc line 194
before user_save($user, array('roles' => $user->roles), NULL);
after user_save($user, array('roles' => $roles), NULL);
Comment #25
robby.smith commentedComment #26
klausihttp://drupal.org/patch/create
Comment #27
mitchell commented