1
votes

I am trying to achieve email notification . The condition is , it should go by end of the day with the current day published content list.

For the same I have tried couple of things using Rules, but stuck in between.

Any help?

I tried using rules, and I created a rule like so:

  • Events:

    1. After updating existing content of type(content type name)
    2. Cron maintenance tasks are performed
  • Condition: Data to compare: [node:field-img-status], Data value: Approve

When I am trying to add second condition to check if the node is published within 24hrs, I am unable to achieve it. When I add strtotime("-1 day"), I get an error like:

Wrong date format. Specify the date in the format 2017-05-10 08:17:18.

I tried date('Y-m-d h:i:s',strtotime("-1 day")) but I did not succeed.

Now I am trying one more method to achieve it using Views Rules which is suggested in this answer to the question about 'How to create a Drupal rule to check (on cron) a date field and if passed set field "status" to "ended"?'.

2

2 Answers

0
votes

Below is a blueprint of how I'd get this to work ...

Step 1: Create a single eMail for each node that was published

  • Create a view (using Views) of all the nodes that were published the last 24 hours. Make sure to include a column in that view for the various data you want to be included about each node in your eMail later on.

  • Use Rules to create a rule with a Rules Action that consists of a "Rules Loop", in which its "list items" are actually the list of nodes that you want to be included in your eMail later on. To create this Rules Loop, use the Views Rules combined with a Views display type of "Views Rules", for the view that you created. Refer to my answer to "How to pass arguments to a view from Rules?" for way more details on how to use the Views Rules module.

  • For each list item in the Rules Loop of the previous step, you have access to all data for each column in the View you created. By using these data you could add an additional Rules Action (within the same Rules Loop) to send an appropriate eMail about the node being processed.

Step 2: Group all eMails in a single eMail

Obviously, the previous step creates a single eMail for each node that was published in the last 24 hours. If you only have a few nodes that may not be a real issue to worry about. But if you have dozens (or more?) of such nodes then you might want to consider consolidating all such eMails in a single eMail, which contains (in its eMail body) the complete list of nodes.

A possible solution to implement such consolidation, is similar to what is shown in 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 your case, you could make it work like so:

  1. Add some new Rules variable that will be used later on as part of the eMail body, before the start of your loop. Say you name the variable nodes_list_var_for_email_body.
  2. Within your loop, for each iteration, prepend or append the value for each "list item" to that variable nodes_list_var_for_email_body.
  3. Move the Rules Action to send an eMail outside your loop, and after the loop completed. And finetune the details (configuration) of your (new) "send an eMail" Rules Action. When doing so, you'll be able to select the token for nodes_list_var_for_email_body to include anywhere in your eMail body.

Step 3: Schedule the daily execution of your rule

Use the Rules Once per Day to schedule the daily execution of your rule. Refer to my answer to "How to limit the execution of a rule for sending an email to only run once in a day?" for way more details about this module.

Voilà, that's it ...

0
votes

This is how I would achieve this:

  1. Make some view which would list all nodes created today.

  2. Make some end-point (from my module, check out: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x) It would call this view, and grab that node list (i.e. with views_get_view_result : https://api.drupal.org/api/views/views.module/function/views_get_view_result/7.x-3.x ), loop through the list, compose the email and send it.

  3. Then I would set cron job to call that end-point at end of every day.