1

I use the rules scheduler module (D7). So far all fine.

What I use it for:

  • a user registers with username and email
  • this users then gets 4 emails over the next four weeks, sent by the scheduler

BUT: In case a user wants to unsubscribe from these scheduled emails? How can I achieve it?

It is true that one can delete particular sort of scheduled tasks with the according action (Delete scheduled tasks). But I don't know how to indicate it shall only delete the tasks that are related to a particular?

When I list the schedule with ... /admin/config/workflow/rules/schedule

... there is one column called "USER PROVIDED IDENTIFIER" - maybe it would help to do it with such an identifier. But I don't know how?

UPDATE TO THE QUESTION:

I tried to import with the suggested changes, this is how my rule looks like now:

{ "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" } },
"DO" : [
  { "schedule_delete" : {
      "component" : "rules_send_email_notification",
      "task" : "[account:name]"
    }
  },
  { "schedule" : {
      "component" : "rules_send_email_notification",
      "identifier" : "[account:name]",
      "param_user_to_notify" : [ "account" ]
    }
  }
]
}
}

But now I got this error:

Integrity check for the imported configuration failed. Error message: Missing configuration for parameter date

12
  • Can you refine your question to explain the "In case a user wants to unsubscribe from these scheduled emails?" part of it: what is a user supposed to do for such unsubscribe? Commented Dec 28, 2015 at 14:36
  • I thought of an unsubscribe-link in the email sent with the scheduler, containing the email or username. If clicked on that link, all scheduled tasks of this user being deleted.
    – Selim
    Commented Dec 28, 2015 at 14:41
  • OK, using such unsubscribe link could probably work to actually trigger a rule (related to Rules Event "Content is viewed"?). That trigger rule could then perform the delete of the scheduled tasks as detailed in my answer. Probably your only (minor) challenge left would be how the complete URL of such unsubscribe-link should look like (but that's another issue of course, if needed create a new question for that later on). Commented Dec 28, 2015 at 14:59
  • Hi Pierre, The event trigger "Content is viewed" is the one I use. But what is the "action" of the rule, so that I achieve the deletion of scheduled tasks, assigned to the username (or email)? Honestly I am quite new to rules and I have no experience with the "Rules export format". I don't know how I shall adjust that to my needs. Any other suggestions? Many thanks!
    – Selim
    Commented Dec 28, 2015 at 15:30
  • I'm not sure (yet), but I think you mean "condition", not "action". Because the "action" is as in my sample rule, and with the "condition" you can impose other criteria that must be true. If you extend your question with the current version of your rule (in rules export format, using the "export" link in the rules UI), it may be easier to help you refine whatever rule you already have in place (which might not work yet, but that's not a problem). Also, using a "unsubscribe" link may not be the easiest "implementation" (to get it to work with rules). Are you open for an alternative "to start"? Commented Dec 28, 2015 at 15:56

1 Answer 1

0

Have a look at my answer to "Rule to store user's last post date and scheduled rule based 30 day reminder" for an illustration about how to delete scheduled tasks, using the "schedule_delete". As explain in that answer: 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).

To make this work (that you actually indicate the exact scheduled task to be deleted), you need to specify an appropriate "identifier", like "[account:name]" in my example. To understand how I know what in my case the identifier is of the task to be deleted, look at the way I specified my (new) scheduled task to be created: it is "identifier" : "[account:name]", which is what I used as my identifier to schedule a task.

In your case, I think "[account:name]" would be a pretty good choice for such identifier. But your questions states "... users then gets 4 emails over the next four weeks, sent by the scheduler ...". So if the 2nd email only gets scheduled after the first email (and not schedule all 4 emails upfront together), and similar for the 3rd and 4th email, then you should be fine using this identifier also.

Note: Specifying an "identifier" like "[account:name]" is what you'd do in your Rules Action (similar to my "step 3" in the above sample). While you'd probably want to create a Rules component similar to my "step 2" in the above sample to actually send an eMail.

Update: The "integrity check" problem shown near the end of the updated question, is probably because in your rule, as shown in the updated question, does not specify the date to schedule your component. Have a look again at my answer I mentioned above: the rule there specifies a date via this part of it:

  "date" : {
    "select" : "account:field-next-article",
    "date_offset" : { "value" : 2592000 }
  },
4
  • How can I specify an "identifier" like "[account:name] and where? I mean do I have to specify it in the component?
    – Selim
    Commented Dec 28, 2015 at 14:45
  • Refer to the Note I added to my answer, does that help? Commented Dec 28, 2015 at 14:55
  • First of all: thank you very much for your help. I tried to import your rule, but got this error: "Integrity check for the imported configuration failed. Error message: Data selector account:field-next-article for parameter data is invalid.."
    – Selim
    Commented Dec 28, 2015 at 18:25
  • OK, great, I mean: painful (that error), but you're making progress ... After you pasted the rule on your import screen (but before save), try to delete everything about that "field" (which YOU don't seem to have in your site, that's the "integrity check" problem in your case). So the "If" part (= is a rules condition, you don't have any so far) and then also delete the entire line with "data_set". Then try to save the imported rule again. Let me know if you get other import errors then. Commented Dec 28, 2015 at 18:30

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.