2

In this scenario, user's can post 1 node of a specific content type every 30 days (interval changes depending on user role). We are using node_limit to accomplish this; it's doesn't play with rules.

So, the idea is to schedule an email that will remind the user 30 days later to post a new article AND update a field in the user's account to display the last time the user posted. Once the node is saved, the rule should update the user field with the node's post date.

BUT I'm unable to correctly configure the set a data value.

The rule I have created is as follows:

Fetch entity by property Parameter: Entity type: User, Property: press_update_last_posted, Value: [node:created] Provides variables: Date (entity_fetched_pressupdatelastposted)

Set a data value Parameter: Data: [entity-fetched] ..., Value: [entity-fetched] ...

And then of course it would fire up the scheduled email and display a message on the site.

Any suggestions?

1 Answer 1

2

Use the Rules module together with Rules Scheduler (a sub-module of it), as explained in the 3 steps below. These steps are based on these assumptions:

  • content type = article.
  • interval 30 days.

In this case, a date field is added to the user profile, so that for each user you can indicate an appropriate date for the "next article".

Step 1: Create a field to store the "next article" date

Add a field to the "user" entity with machine name (say) field_next_article. Allow only 1 date (to store when the "next" article is allowed).

Step 2: Create a Rules "Component"

Here is the Rules Component to be created (in Rules export format, just import it in your own environment via copy-paste):

{ "rules_send_email_notification" : {
    "LABEL" : "Send eMail notification",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "user_to_notify" : { "label" : "User to be notified", "type" : "user" } },
    "ACTION SET" : [
      { "mail" : {
          "to" : [ "user-to-notify:mail" ],
          "subject" : "Friendly reminder about your next article",
          "message" : "This is a reminder about your next article on [user-to-notify:field_next_article] ...",
          "from" : "[site:mail]",
          "language" : [ "" ]
        }
      }
    ]
  }
}

Obviously, the Subject and Content of the eMail may need review / tuning, while you might also want to use some other From eMail ID.

Step 3: Create a "Rule" using the Rules Component

Here is the Rule to be created, in Rules export format (just import it in your own environment via copy-paste):

{ "rules_user_reminder_after_30_days" : {
"LABEL" : "User Reminder After 30 Days",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_scheduler" ],
"ON" : { "user_login" : [], "node_insert--article" : { "bundle" : "article" } },
"IF" : [
  { "entity_has_field" : { "entity" : [ "account" ], "field" : "field_next_article" } }
],
"DO" : [
  { "schedule_delete" : {
      "component" : "rules_send_email_notification",
      "task" : "[account:name]"
    }
  },
  { "data_set" : { "data" : [ "account:field-next-article" ], "value" : "+30 day" } },
  { "schedule" : {
      "component" : "rules_send_email_notification",
      "date" : {
        "select" : "account:field-next-article",
        "date_offset" : { "value" : 2592000 }
      },
      "identifier" : "[account:name]",
      "param_user_to_notify" : [ "account" ]
    }
  }
]

} }

Note that the above rule refers to the Rules Component from the previous step.

The schedule_delete that is part of this rule is to ensure that previously "scheduled" reminders will get removed when updating the data field (so that it only triggers 1 reminder, and with the most recent date).

Your Answer

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

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