Use Rules to Unpublish content based on Author's role

Events happening in the community are now at Drupal community events on www.drupal.org.
hovikzakian's picture

I've been trying to find a way to use the Rules module to unpublish all of an author's nodes if his/her role is changed to a non-author role. But I'm having trouble finding the right variables in the rules module.

Anyone have any advice on how to go about getting this set up?

Thanks.

Comments

Rules + Views Bulk Operations

itangalo's picture

What you want to do can be done with Rules in combination with Views Bulk Operations. Views Bulk Operations is a module that lets you carry out actions on objects that Views lists – which in this case then would be nodes that should be unpublished.

The configuration would look like this:

  1. Build a view that, when given a user ID as input, lists all the nodes that that user has posted.
  2. Use view style bulk operations, and select the action unpublish node.
  3. Set up a rule that triggers on user updates. (Is there one? I'm not sure...) As condition, compare the roles before and after user save to see if anything should be unpublished. As an action, let it call the view from 2.

The tricky parts are:
1. Use the UID as an argument in the view – that would make it quite easy to get the list that you want.
3a. Find a suitable trigger. I don't know that I've seen one acting on user save, but let's hope for that.
3b. If the VBO action does not yet work as it should in Rules, you can call the VBO by an explicit PHP function instead. Here's a blog that explains how to call VBO – check out the comments as well.

Good luck!
//Johan Falk, NodeOne, Sweden

http://nodeone.se - You are

mailfox's picture

http://nodeone.se - You are not authorized to access this page.

I have the same issue,when a

user654's picture

I have the same issue,when a user is assigned a role,all nodes he has created to get unpublished.
I have created the view with view bulk operations and loaded these nodes on the rule.
Should I next unpublish the nodes?How can I do that?The VBO action ,just loads the nodes.There is no Execute VBO,only Load VBO.
thanks

jasonawant's picture

Hi,

I've been hunting down a solution for a similar scenario as the original poster. Perhaps I missing something, but when creating a rule triggered on 'user account details have been updated' only the 'Execute a VBO programmatically on user' is available, not Execute VBO on node.

I'm not sure it's possible to create a rule that triggers on User object, and then acts on node objects. Any other thoughts here?

jwant

"User" is the object used by Rules, not VBO

itangalo's picture

The 'Execute a VBO programmatically on user' action means that you will use information from a user object to run a VBO – for example for sending in any arguments to the view. The VBO itself can still act on nodes.

The action's name should really be 'Use a user object to run a VBO'.

Good luck!
//Johan Falk
**
Check out NodeOne's Drupal Learning Library! 190+ screencasts and exercises, for Drupal introduction, advanced configuration, and coding. Creative Commons license!

Ahah

jasonawant's picture

Hi,

Ok, I'll try that. I found the following screencast to be helpful: http://nodeone.se/blogg/nodeone-talks-drupal-rules-vbo-revisited.

Using the example from the screencast, I used 'return array($object->uid);' as the argument to pass to a vbo that uses the UID as an argument to selected the user's authored nodes. It worked! It called the vbo and then executed the selected vbo action.

However, the selected vbo action is a rule set with a rule action to 'modify node taxonomy terms', but it does not change the nodes' taxonomy terms.

I've tried configuring the rule action 'modify node taxonomy terms' to 'Replace terms within same vocabulary', and selecting the desired term within the specific vocabulary, but this does not change the node's taxonomy term. My rule set is only using content as an argument. Do I need to use taxonomy term or taxonomy vocabulary as rule set arguments?

I can successfully change a node's taxonomy term by using the default VBO action 'modify node taxonomy terms', so I feel I have an issue with my rule set. I'm also using TAC module, and perhaps this is affecting the execution of the rule action. How are rule actions executed, as Admin, Anonymous or as the user role of the acting user? I'm currently executing the rule set and action as Admin (UID = 1). I disabled TAC module, but the taxonomy term still not change.

I've found the following issues that discuss the problems with changing a nodes taxonomy terms via rules. Any help would be appreciated. Also, let me know if I need to move this to an issue queue, Rules, VBO or otherwise. Thanks, jwant.

http://drupal.org/node/887982 - Seems to point to a known issue, "Modify node taxonomy terms failing when action is triggered via a rule"

http://drupal.org/node/917476 - An old issue, which does not seem relevant now that there is a action to to 'modify node taxonomy terms'.
http://drupal.org/node/895310 - An old issue too, but perhaps this is the method I need to follow....it seems like work-around.

Ooo!!! Yes!!! Ahah this code

mailfox's picture

Ooo!!! Yes!!! Ahah this code good 'return array($object->uid);'

I have the same issue. I made

designcontext's picture

I have the same issue. I made a view for VBO and a component in rules which loads the VBO and set the nodes to unpublished. This worked when I execute the component manually. But I didn't get the conditions right. I have this rule:
{ "rules_premiuminhalte_ausblenden" : {
"LABEL" : "Bei Rollenwechsel Premiuminhalte ausblenden",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "user_update" ],
"IF" : [
{ "data_is" : {
"data" : [ "account-unchanged:roles" ],
"value" : { "value" : { "7" : "7" } }
}
},
{ "data_is" : { "data" : [ "account:roles" ], "value" : { "value" : { "4" : "4" } } } }
],
"DO" : [
{ "component_rules_premiuminhalte_unveroeffentlicht" : { "account" : [ "account" ] } }
]
}
}

I check for the unchanged role which should be "Musiker Premium" and the changed role which should be "Musiker Basis". But everytime I switch the role I get the debugmessage:

0 ms Reacting on event Nach der Aktualisierung eines bestehenden Benutzerkontos.
6.031 ms Evaluating rule Bei Rollenwechsel Premiuminhalte ausblenden.
7.468 ms The condition data_is evaluated to FALSE
7.477 ms AND evaluated to FALSE.
7.492 ms Finished reacting on event Nach der Aktualisierung eines bestehenden Benutzerkontos.

So there must be something wrong, but I don't understand it...

Found the answer: I used Data

designcontext's picture

Found the answer: I used Data comparison for the condition but it works with Item is in list

Or, execute custom PHP

jasonawant's picture

Hi,

Glad to hear you found a solution.

Ultimately, we used the execute custom php action to change the taxonomy terms of the node.

jwant

In conjunction with D7 Drupal Commerce?

RKS's picture

Don't know if everyone is talking D6 or D7 but what are your thoughts on getting this to work with Drupal Commerce instead of role-based changes? Still VBO? for example, stock level goes to zero and then node is unpublished. Stock is raised above zero and the node is published again.

It seems like that would be inline with what everyone has stated thus far but without a uid to put into a contextual filter.

Role Watchdog

anavarre's picture

Just found this thread. For a slightly different approach, you might also be interested in Role Watchdog to react on event System log entry is created.

and using uc_role assignment?

josefajardo's picture

using uc recurring payment and role assignment by way grant roles
can this fit with rules?

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: