1

When a node is being updated I have a trigger for this in the rules engine. I want a notification of this in the email.

The node is however updated several times in 5 minutes.

I only need 1 notification of this.

I first had the idea to compare the node:changedate with site:current-time with 300 seconds diff in a php rule, but then all email is not send as the first email is also within the 300 seconds.

Any suggestion how to solve this?

2
  • Which Drupal version?
    – sanzante
    Commented Jan 5, 2018 at 10:35
  • Sorry, forget to mention D7
    – Justme
    Commented Jan 10, 2018 at 10:18

2 Answers 2

3

Assuming your question is about D7, and that you can think of creating a view for such updated content for (say) "the last 5 mins", there is a solution to do what you're asking about. This solution uses the Rules, Views and Views Rules module, as further detailed below.

1. About the Views Rules module

The Views Rules module makes Views data available in Rules, enabling intuitive rule configuration for dynamic data. Some details from its project page:

... provides two types of elements in Rules, configured with a "Rules" view display:

  • Views loop: A views loop is similar to a regular Rules loop, but allows looping over rows of view results.

    enter image description here

  • Collect view result rows (action): This action collects each variable in all view result rows into list variables for use in Rules.

Tip: When selecting the data type for variables in the view, if the field is an entity identifier (e.g. Node ID), you can set the data type to the entity type (i.e. Node) to directly use the variable in Rules as an entity!

2. Create a view of display type 'Rules'

After you enable the Views Rules module, use Views to create a view of your "updated content for (say) the last 5 mins" (as in your question). Add of view of display type Rules (important, that's the key to make it work!). Here is how you can add such display:

enter image description here

Next configure the row variables, by using the link that says "edit field info", as shown here:

enter image description here

3. Create a Rule Component using the view of display type 'Rules'

Create a Rules Component, using these guidelines:

  • Add whatever Rules Conditions you might want (if any).
  • Some Rules Actions you'll need to create (add) for sure:
    • Create a variable, with no initial value, say you name it "eMail Summary" (machine name email_summary), which will be used in subsequent Rules Actions.
    • Add a Views loop (by using the link that says Add view loop), and select the "Rules" display created in the previous step. Configure the parameters and variable names. And for each views result contained in your Views loop (about some "flagged content / user", as in your question), perform a Rules Action like Set a data value, for the email_summary variable from the previous Rules Action. The actual value to be assigned, is the previous value of email_summary, to which you append the desired data about the Views result being processed. For this you can use the variables you configured at the end of the previous step (you may have to revisit the previous step to add more similar variables there if needed).
    • Add a Rules Action to Send an eMail to a selected role (as per your "periodic summary email that gets sent to a specific role"), whereas for the body of that eMail you simply use the value of the email_summary variable.

If you're not familiar enough with Rules to create and populate that email_summary variable, you may want to have a look at the Rules example included in my answer to "How to concatenate all token values of a list in a single field within a Rules loop?", in which a similar variable is used.

Try to execute your Rules Component "manually" (just to test), to unit-test if it works as desired. To do so, use the "execute" link to the right of the Rules Component (in the Rules UI).

4. Schedule the Rules Component for periodic execution

Make sure you have the "Rules scheduler" enabled (a sub-module of Rules).

Improve your Rules Component from the previous step, by adding a Rules Action (as the last action to be performed) to Schedule a Rules Component, whereas the actual Rules Component to be scheduled is the Rules Component itself. You want it to be scheduled in "5 mins from now" (to make it happen every 5 mins).

To execute this Rules Component the very first time, just execute your Rules Component "manually". To do so, use the "execute" link to the right of the Rules Component (in the Rules UI).

Assuming your QA-testing succeeded, and assuming your cron jobs are running also, the eMail should get created next time cron runs (after an amount of time, depending on the amount of time you configured in your Rules Component to get it rescheduled).

4
  • wunderfull solution. Thxs
    – Justme
    Commented Jan 10, 2018 at 10:20
  • @Justme Dank je wel ... May I say "had je iets anders verwacht" (of anders: "What else did you expect?") ... Commented Jan 10, 2018 at 13:06
  • Nop niet van jou :-)
    – Justme
    Commented Jan 16, 2018 at 19:18
  • Da's een goeie ...! Geen andere (rules?) vragen meer? Commented Jan 16, 2018 at 19:18
1

I think is easier of use custom code. If you don't care who edited the node and just want the email when a node is edited several times in 5 minutes (by the same or different users) you can:

  • Add a number field to nodes, defaulted to 0, removed from normal node edit and view.
  • Add a node presave hook (this is your custom code) that: if last edit date is less than 5 minutes add 1 to this field, else set it to 0.
  • Then you can set the Rule checking that field, or send th email directly from code.

May be you can avoid custom code using a rUle that adds 1 to that field, but I'm not sure if you can do it with Rules easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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