Great module, but i have big trouble to realize this scenario with Rules:

  1. User logs in
  2. Rules looks at all event-nodes created by the user
  3. Rules reads the date field attached to the event-nodes
  4. and if the date is today (site date)
  5. Rules should do something (display a message: today is an event)

There's a content type of 'event' that has a date field and the nodes are created by the user.
Now on log in, there should be a message that the date of today is the same as in the event-node(s).

What's the best way to do this with Rules?

Thanks a lot.

Comments

TR’s picture

Status: Active » Closed (outdated)

A task like this is all about the data model you choose to set up on your site. While Rules can do exactly what you describe in the order you describe, it is IMO a terrible way to approach the problem. You are saying that when a user logs in you want to:

  • Search through all nodes on the site (could be millions!) looking for just those nodes created by the user.
  • Search through all the nodes selected by 1) to find those that have a date = 'today' (whatever that means - what do you do about time zones, and do you want to remind the user when the event has already happened earlier in the day?)
  • Display a message (what happens if the user doesn't log in on that day?)

Now think of what happens when you have a large site with many nodes and many users logging on/off all the time. You will bring the database to its knees.

Instead, you should think about what needs to be done and try to do it once, not hundreds or thousands of times. For instance, bottom line is you want to notify a user on certain days. So instead of huge searches, just add those dates to the User account in the form of a date field (in the profile, for instance). When the user adds an event, add the event date to the user's profile. When the user logs in, just check the few dates in the profile. Better yet, when the event is created, use the rules_scheduler to schedule the notification task - the rules_scheduler will then run the notification task once and only once, on the proper day. The notification task can consist of setting a Flag on the user's profile, then you can have another Rule which checks the flag when a user logs in and displays a message.

The point is that you have all the information you need at the moment the user creates the event node. You should save what you need and use it once on the event date, rather than looping through all the content on your site (even old events) every time the user logs in.

Closing this as outdated because I doubt you still need to do this after all these years, but