1

In a nutshell, I'm trying to stop my users from getting e-mailed more than once per day.

  • I have some rules set up that will e-mail users when content particular to them is updated.
  • I have added a Boolean field to user profiles that starts off 'checked' (1) - indicating they have not (yet) been emailed today.

Any rules that e-mail users will first check this user profile value and proceed only if they haven't been e-mailed (field value is 1), but then set this Boolean value to 0 using set a data value in Actions - thus they won't get e-mailed again until the value is changed.

What's the best/easiest way to 'reset' that field in ALL user profiles periodically? (probably once a day)

i.e. at 10:00PM set the boolean field "field_user_not_emailed_today" for ALL users to 1. (checked)

I've seen VBO recommendations for this sort of thing, but seems unnecesary given the ALL users thing. Is there perhaps a PHP snippet I could call in Rules that would do the trick?

Thanks!

0

The Rules Once per Day module provides a 'Once per day' rules event that you can use to trigger your boolean flag update.

For bulk updating a list of users, if you have an action that loads a list of users you can then loop through and act on those users with rules.

There are a number of ways you can load a list of users in rules. Some of them are:

  1. The Views Bulk Operations module provides some actions including 'Load a list of entity objects from a VBO view'
  2. The Views Rules module provides the 'Collect view result rows' action.
  3. The Rules Bonus Pack module provides a number of actions, including 'Load a user list with Views'.
  4. You can create a custom action of your own via a custom module. See the rules developer documentation and various blog posts for more details.

I'm not sure of any easier way to loop through all users in the system, but the views approach is fairly straight forward and low maintenance anyway.

Also, you might not always want to loop through all users. for example you might want to exclude administrators or only loop through users where your boolean field is set to 1, to avoid unnecessary processing in the case that not all users have been set to 1 for whatever reason.

The action you use to load the users will create a new variable (eg. 'entity-list') that will be available in future actions. You can then use the 'Add loop' option in the rules actions section to loop through that new variable. That loop will create another new variable for the current item (eg. 'list-item') your are looping over and then you can add actions that act on that variable (eg. data set on list-item:field-user-not-emailed-today).

  • Thanks Rooby - the once per day is probably a better option than triggering a rule on cron which I was planning, but I'm still unsure as to the best way to iterate through all the user accounts from within the rule to change the actual flag update (which is more the part I could use some help with.) – Thumbs Feb 4 '18 at 16:41
  • Which method are you using to get the users inside the rule? Once you have the list of users, you just loop it and set the data field. – Niall Murphy Feb 5 '18 at 4:37
  • I have used all 4 of those options at one time or another on different websites. In a lot of cases any option will suffice. Generally I choose based on what modules are already installed on the site for other purposes (for example VBO is already installed on almost all sites I work on). If the list I am gathering requires more complex logic I would go with the custom action, although in your case it would be a fairly small amount of custom code to go that route. If you use the admin_views module you could even use its VBO view for all users. I also aded a little more to the end of the answer. – rooby Feb 5 '18 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.