Best Practices

Events happening in the community are now at Drupal community events on www.drupal.org.
ultimike's picture

Hello, I'm in the process of building a site that sells tickets to events using ubercart. I'd like to be able to have a rule that automatically unpublishes the event node when the event date passes.

For the most part, I've been able to do this but there's still a question in my mind as to whether or not I've done it the best way. Here's a quick synopsis of what I did:

  1. Created an "event" content type (actually an ubercart product class).
  2. Added a date field to the "event" content type (field_dates).
  3. Created a rule that is run on cron.
  4. I did not include any conditions.
  5. For the rule's action, I wrote a snipped of PHP code that queries the node table or the published nodes of the "event" type that have a field_dates value in the past and unpublished any that it found.

Is this the best way of accomplishing this using the Rules module?

I've attached an export of the rule in case anyone is interested.

Thanks,
-mike

AttachmentSize
unpublish_events_rule.txt1.28 KB

Comments

use the built-in scheduling mechanism

fago's picture

Is this the best way of accomplishing this using the Rules module?
No.

Once the node is created/updated schedule a rule set to be executed on the given time. So then rules executes the given rule set on the given time for you. So you don't need any custom code. Probably this needs to be documented better, so if someone could do a tutorial for that ,that would be just awesome.

However currently the docs are broken :( http://drupal.org/node/376790

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: