I need some help with Drupal Commons (7.x-3.46), Trusted Contacts (one of its modules), and Rules. I need to create a rule so that whenever a user is approved as a trusted contact, the user is also flagged. It turns out this is not so simple.
In my attempts so far, however, the user ends up flagging him/herself.
Also, it should not depend on the user being logged in, as they might be approved while they're not logged-in. Or flagged twice if both users are logged in at the same time! In other words the approver should flag the approved, regardless of who is logged in at the time.
The rule thus far is
{ "og_og_member_subscribe2" : {
"LABEL" : "OG member subscribe2",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "og" ],
"ON" : { "og_user_approved" : [] },
"IF" : [
{ "data_is" : { "data" : [ "og-membership:state" ], "value" : "1" } },
{ "entity_has_field" : {
"entity" : [ "og-membership:entity" ],
"field" : "user_trusted_contacts"
}
},
{ "entity_is_of_type" : { "entity" : [ "og-membership:entity" ],
"type" : "user" } }
],
"DO" : [
{ "drupal_message" : { "message" : "fired2" } },
{ "variable_add" : {
"USING" : { "type" : "user", "value" : [ "og-membership:entity" ]
},
"PROVIDE" : { "variable_added" : { "user_added" : "Added variable"
} }
}
},
{ "drupal_message" : { "message" : "uid [user-added:uid] trusted
contacts are [account:user-trusted-contacts]\r\n\r\n" } }
]
}
}
When the user (= te st
) confirms JeffNoyes
as a trusted contact, this is the message that returns:
fired2
uid 3 trusted contacts are Jeff Noyes, Drew Robertson, Lisa Rex, Katelyn
Fogarty, te st
fired2
uid 1 trusted contacts are te st, Jeff Noyes
fired2
uid 3 trusted contacts are Jeff Noyes, Drew Robertson, Lisa Rex, Katelyn
Fogarty, te st
It's not quite clear to me why it fires 3 times.. It fires first for the approved, uid3 Jeff Noyes. Then a 2nd time for the approver, uid1, te st. And then a 3rd time, once again for uid3.. And Every user is the first user in his/her trusted contacts list, and the last in the list is the one just approved. I can't seem to fetch and limit it to the user who did the approving, or to their list of trusted contacts.
this is the Rules debug information:
" Reacting on event User membership has been approved.
0 ms Reacting on event User membership has been approved.
11.459 ms Evaluating conditions of rule OG member subscribe2. [edit]
13.223 ms The condition data_is evaluated to TRUE [edit]
14.958 ms The condition entity_has_field evaluated to TRUE [edit]
15.209 ms The condition entity_is_of_type evaluated to TRUE [edit]
15.23 ms AND evaluated to TRUE.
" Rule OG member subscribe2 fires. [edit]
0 ms Rule OG member subscribe2 fires.
0.201 ms Evaluating the action drupal_message. [edit]
1.275 ms Evaluating the action variable_add. [edit]
1.488 ms Added the provided variable user_added of type user [edit]
109.832 ms Evaluating the action drupal_message. [edit]
110.099 ms Rule OG member subscribe2 has fired.
125.403 ms Finished reacting on event User membership has been approved.
" Reacting on event User membership has been approved.
0 ms Reacting on event User membership has been approved.
0.687 ms Evaluating conditions of rule OG member subscribe2. [edit]
1.389 ms The condition data_is evaluated to TRUE [edit]
2.329 ms The condition entity_has_field evaluated to TRUE [edit]
2.716 ms The condition entity_is_of_type evaluated to TRUE [edit]
2.767 ms AND evaluated to TRUE.
" Rule OG member subscribe2 fires. [edit]
0 ms Rule OG member subscribe2 fires.
0.356 ms Evaluating the action drupal_message. [edit]
1.104 ms Evaluating the action variable_add. [edit]
1.551 ms Added the provided variable user_added of type user [edit]
15.337 ms Evaluating the action drupal_message. [edit]
15.866 ms Rule OG member subscribe2 has fired.
18.793 ms Finished reacting on event User membership has been approved.
" Reacting on event User membership has been approved.
0 ms Reacting on event User membership has been approved.
0.309 ms Evaluating conditions of rule OG member subscribe2. [edit]
0.628 ms The condition data_is evaluated to TRUE [edit]
1.056 ms The condition entity_has_field evaluated to TRUE [edit]
1.22 ms The condition entity_is_of_type evaluated to TRUE [edit]
1.241 ms AND evaluated to TRUE.
" Rule OG member subscribe2 fires. [edit]
0 ms Rule OG member subscribe2 fires.
0.146 ms Evaluating the action drupal_message. [edit]
0.501 ms Evaluating the action variable_add. [edit]
0.693 ms Added the provided variable user_added of type user [edit]
6.823 ms Evaluating the action drupal_message. [edit]
7.075 ms Rule OG member subscribe2 has fired.
8.385 ms Finished reacting on event User membership has been approved.