I'm creating a subscription site where a user is given a role dependent on the status of their subscription. When their role is set to 'Expired', I would like the nodes that they have authored to be unpublished.

The main rule:

  • EVENT - After updating an existing user account
  • CONDITION - User has role(s): Expired
  • ACTION - ??? (somehow unpublish all nodes authored by that user)

I would love to know the best approach; below is my attempted approach (please ignore if there is a better way):

  • I've been using this discussion as a reference (https://groups.drupal.org/node/94379), which uses VBO, but since the 'Execute a VBO programmatically on user' action no longer exists, I'm not sure how to continue (I'm not even sure VBO is necessary any longer if I can simply get the list of nodes from a view and perform the unpublish operation in Rules). Either way, my roadblock in that approach is figuring out how to pass the UID of the user being updated (in the event above) as the contextual filter of the VBO view creating the list of nodes to be unpublished. How would this be accomplished?

Thanks for any help!

Comments

TR’s picture

Issue summary: View changes
Status: Active » Fixed

You can use a "Fetch entity by property" action with the "Author" property to find all the nodes that were authored by that user. Then you can loop over them and unpublish them one at a time. Or you could use the "Load a list of entity objects from a VBO view" action, after creating a view of nodes with an exposed filter of uid and a VBO operation of unpublish.

If you're still need help doing this, post what you have so far and we'll see if we can help.

TR’s picture

Status: Fixed » Closed (fixed)