The Rules Monitor module, currently in sandbox, aims to allow you to create rules which react to site states.

Documentation

  • The README.txt file contains basic instructions. It is considered canonical.
  • This book page contains information from the README.txt file. In case of discrepancy between the book page and this README.txt file, the latter is considered canonical.
  • The project home page contains links to the documentation, news, issues, the roadmap, and other resources.

Description

Allows you to use Rules (drupal.org/project/rules) to check your site's state every day, and fire an action if a state is TRUE, but never more than once daily. Consider the following example.

Let's say you want to email all users of the role "comment moderator" if there are one or more unmoderated comments on your site; and you want this to happen once per day.

  • (1) download rules_monitor and views as you would any other module. Enable rules_monitor_views, views_ui, rules_admin (Rules UI) and dependencies;
  • (2) (admin/people/permissions) configure permissions if you are not user 1;
  • (3) (admin/people/permissions/roles) make sure you have a role named "comment moderator" on your site;
  • (4) create a view which displays unmoderated comments, making it accessible to trusted users only (Using views is outside the scope of this document);
  • (5) go to config > workflow > rules.
  • (6) create a rule to be triggered on the event "Cron maintenance tasks are performed".
  • (7) select the condition: "Rules Monitor: View is not empty", and select, as a parameter, the name of the view you created.
  • (8) select a second condition: "Rules Monitor: Minimum interval of one day".
  • (9) set the action to "Send mail to all users of a role". As parameters, select the role "comment moderator", set the email text and subject, and save.

Now, daily (or on cron runs, whichever is least frequent), any user with the role "comment moderator" will receive an email only if the "unmoderated comments" view is not empty.

Note that you do *not* want to notify users *every time* there is a new comment -- Rules on its own works fine for that -- but rather to check your site daily to see if there are one or more unmoderated comments. Concretely, this means that the following scenario is possible:

  • (1) Noon on Jan. 1st: site is checked for unmoderated comments, there are none.
  • (2) 6 p.m. on Jan. 1st: a new comment is posted.
  • (3) 7 p.m. a comment moderator processes the new comment, either publishing or deleting it.
  • (4) Noon on Jan. 2nd: site is checked for unmoderated comments, there are none.

In the above scenario, the action associated with the Rules Monitor rule is not called.

Inner workings: overview

Rules works by reacting to events, checking for conditions and firing an action if the conditions are TRUE. In the example above, the event is the cron job, and the conditions are that a view not be empty, and that at least a day has passed since this was last checked.

Thus, all Rules Monitor really does is to define those conditions.

For Developers: Extending Rules Monitor

  • - Get familiar with the Rules API and online documentation.
  • - Site states are defined in exactly the same way as rules conditions.
  • - To learn by example, look at the included rules_monitor_views module, and run the included Simpletests and look at the resulting verbose messages.