I need help either with cron-based Rules using tokens, or with Rule sets.

I'm 95% of the way to getting Rules to work for expiring job or classifieds nodes without lots of complicated steps for the user. The missing piece is an elegant method for unpublishing nodes on the expiration date.

Requirements:

* Users in some role can post job listings. They can specify an expiration date, or leave the field blank and it will default to 60 days from now.
* When the job expires, it's unpublished, so it doesn't show up in search results.
* The employer can end a listing early by unpublishing it, or re-post an expired job.
* If they re-post an expired job, it's set to expire on the date they enter, or 60 days from now.

Here is my "almost-there" solution:

* CCK date field for expiration date. No default date set, and it's not a required field. (see: keystr0k's notes in http://groups.drupal.org/node/21377 )
* A "node is about to be saved" Rule that sets the date field to today + 60 days if the date is < = now, using a PHP snippet. (Also keystr0k's notes.) This addresses the case where the user skips the expiration date field.
* The module Publish Content, to place a publish/unpublish tab that the employer can use to manually end a listing.
* A job board View to show all jobs with expiration date > now.
* A "node is about to be viewed" Rule that unpublishes a job node if the CCK date field value is <= now. (Modified version of keystr0k's PHP snippet as a condition, that just compares the dates and returns true or false, and "unpublish the node" as the action.)

This mostly works: Employers can post jobs and enter a specific expiration date. If they enter a date prior to now, or skip the field, the date is set to now + 60 days. They can end the job any time by clicking the unpublish tab. They can re-post an expired job by clicking Publish, and it re-sets the expiration date for another 60 days. Only unexpired jobs are displayed in the job board View.

The catch: Nodes aren't automatically unpublished on the day the expiration date hits. Someone has to stumble across it (say, in a site search) and try to view it.

Here are things I tried, but didn't quite work:

1. Node_expire module: mostly works, but not quite. First, the expiration date field shows up at the top of the node edit form (for non-admin users) and I don't want it there; and I don't want to mess with custom templates. Second, it yells at the user if they skip the expiration date field or choose some date prior to tomorrow. Third, the workflow for re-posting a job is that you have to edit the node, enter a new expiration date, save it, and click "publish." This is too many hoops for non-technical site users.

2. Rule Set. I can't figure out how to use Rule Sets. I understand the concept, but all I can find for docs is people saying, "use a Rule set," and other people saying, "I can't figure out how to set up a Rule set."

3. Cron-based Rule, that compares CCK date value to now, and unpublishes the node if the expiration date is < now. This would be perfect. I tried both "numerical comparison" and "textual comparison," but can't figure out how to get the tokens right. I tried:
(a) one token in each field (CCK date field - is less than - system date field). No-go. No combinations work. Presumably the shape of the data that the tokens return is not the same.
(b) three tokens in each field: yyyy, mm, and dd, for CCK in the one field and system in the other. No go. Always returns that the values are the same, no matter what date is entered in the CCK date field. Maybe multiple tokens don't work?

The "right" solution would be a Rule that runs on cron, or a Rule set. Has anyone done this, and gotten it to work?

Comments

fago’s picture

Have a look at the scheduling tutorials: http://drupal.org/node/298482

toddwoof’s picture

Status: Active » Closed (fixed)

Scheduling is a feasible option, although the workflow I have to use for my particular requirements isn't pretty. See further discussion here: http://groups.drupal.org/node/21377 (and I'll mark this closed). Thanks!