1

I have a content type with comments activated and would like to have a rule that triggers a component when there is no new comments posted after a week. The component works as designed with rules scheduler, but I am having problems with creating a rule.

I have tried to create a rule that reacts on the event "After saving new comment". However, without proper conditions every comment will be scheduled to trigger the component one week after is is posted. The rule needs to overwrite existing scheduled actions if a new comment is posted on the same node. How can I achieve this?

1
  • You could also accomplish this by creating a views_bulk_operations view of nodes with week old comments and a cron job to execute a rule as VBO views are exposed to rules. I can add more details of Pierre's answer doesn't work for you.
    – lukedekker
    Commented Oct 2, 2019 at 18:17

2 Answers 2

2

To my knowledge, there is nothing in Rules to "overwrite existing scheduled actions" (as in your question). However, by every time attempting to perform an appropriate delete of an already scheduled rule, prior to scheduling a new rule, you achieve a similar result. And such attempt just gets ignored if there was no scheduled rule yet. Read on for more details ...

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 using the node's ID as part of the identifier would be a pretty good choice for such identifier.

0
2

The rule needs to overwrite existing scheduled actions if a new comment is posted on the same node.

Yes, you can do this! And you don't have to delete any scheduled tasks. The key here is to use the scheduler action's identifier parameter correctly. There can only be one scheduled component per identifier, so if your identifiers are all the same (for example, a static string) you will only ever have one scheduled at a time. If your identifies uses the comment id (I think this is what you do now?) then each new comment will schedule a distinct new task. But if you make your identifiers contain the node id of the node that's being commented on, then each node can and will have at most one scheduled component. By using "identifier" : "Reminder - [node:nid] has not had any comments for one week" you will have at most one scheduled reminder component per node. If another comment is posted on that node within the week that will trigger the rule again and the newly-scheduled component will take the place of / overwrite the previously scheduled component for that node because it will have the same identifier.

Thus, every time a new comment is created it will trigger your rule which will schedule your reminder component for +7 days from now. If another comment is added to that same node, it will again trigger your rule and will schedule the reminder task with the same identifier so it overwrites the old reminder and resets the time to +7 days from the second comment. The reminder component will then only be executed if there has not been any new comments on that node for seven days.

Disclosure: I'm the Rules maintainer.

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.