Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Drupal Rules How-to

You're reading from  Drupal Rules How-to

Product type Book
Published in Nov 2012
Publisher Packt
ISBN-13 9781849519984
Pages 74 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Robert Varkonyi Robert Varkonyi
Profile icon Robert Varkonyi

Using the Rules Scheduler (Must know)


In this recipe we create a rule configuration that sends a reminder e-mail to a user that hasn't logged in to the website for a week.

Getting ready

We need to make sure that the Rules Scheduler module is enabled.

How to do it...

  1. Create a new Action set component and provide a user object as a parameter.

  2. Add a new Action, System | Send mail and configure the various fields, set the To field to [user:mail], enter a subject and fill in the MESSAGE field with something such as Hey, you haven't logged in to our site for a week now....

  3. Add a new rule configuration and set the Event to User | User has logged in.

  4. Add an Action, Rules scheduler | Schedule component evaluation.

  5. Select the component which we created in step 1.

  6. Click on Switch to direct input mode and enter +7 days.

  7. Set a unique identifier to this scheduled component.

  8. Provide the account object to the component.

How it works...

In this example we wanted to send reminder e-mails to individual users, who haven't logged in to the website for a week. For that we've created a component (that executes the Send mail Action), which we use in our rule configuration as a scheduled component. In the rule configuration, we set the Event to User has logged in because we want to set the scheduled date to a week from the user's last login. Please note that you'll need cron running for the scheduler to work.

There's more...

Additionally, we would probably want to add an Action Delete scheduled tasks, using the same identifier we've used for the scheduled component and place it before the Schedule component evaluation Action.

This way we make sure that the scheduled date always gets updated when the user logs in and new reminders get scheduled.

Schedule UI

Rules Scheduler provides a user interface through the Views module which can be found at Configuration | Workflow | Rules | Schedule. This interface can be very useful as it displays all the components that are scheduled for execution. It is also a very useful tool for debugging scheduled components.

arrow left Previous Chapter
You have been reading a chapter from
Drupal Rules How-to
Published in: Nov 2012 Publisher: Packt ISBN-13: 9781849519984
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}