Trying to automatically unpublish content based on CCK date field, Rules and PHP field values

wb54321's picture

I am building a web site using Drupal 6.12 (plus the most recent stable releases of token, CCK, Rules and views) and am trying to create a rule that automatically unpublishes content based on the cck date field (generated by the Date API 'date' sub-module).

I have created a Triggered Rule 'Unpublish created content'; then I Add a condition (CCK/has value, argument 'created content, field the CCK Date/time field.). I get to the last step in creating a rule and am stonewalled: I have to either enter a fixed date and time (which is not applicable) or chose "Advanced: Specify the fields value with PHP code". The date and time fields are formatted as follows:

Format: 06/15/2009
Format: 06:05PM

The PHP format expected is this:

"Advanced usage only: PHP code that returns the value to set. Should not include

<?php
 
?>
delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format:"

"return array(
0 => array('value' => value for value),
// You'll usually want to stop here. Provide more values
// if you want your 'default value' to be multi-valued:
1 => array('value' => value for value),
2 => ...
); "

I've tried the following strings and a few variations of them as well (the 'node:field_event_date-time' is a system-provided "tokenized" name for the date field and is listed on the input form):

return array(
0 => array([node:field_event_date-date] => [node:field_event_date-time]),

return array(
0 => array(value => [node:field_event_date-value],[node:field_event_date-datetime]),

return array(
0 => array(Date => [node:field_event_date-value]);
1 => array(Time => [node:field_event_date-datetime]);

Has anyone tried this successfully? If so can you post the correct PHP values I need? If a kindly PHP guru (I am not a PHP coder) reads this and spots the broken part of the code, please take a moment to post the fix. I would bet a lot of other Drupal users would also be interested, and if I am successful I will create step-by-step documentation and submit it to the Drupal documentation team.

Groups:
Login to post comments

Enclose your strings

joelstein - Thu, 2009-06-18 15:44

You need to enclose your strings in apostrophes or quotation marks. Like this:

return array(
  0 => array("Date" => "[token:value]"),
  1 => array("Time" => "[some-other-token-value]"),
);


RE: Enclose your strings

wb54321's picture
wb54321 - Sun, 2009-06-21 01:00

I thought I had tried that, but I went ahead and configured as above. After 3 hours of trying different strings, values, etc: I still haven't found anything that works. I know Rules claims it can do this, many people claim to have successfully, but it's not happening for me.

I tried every Token replacement pattern that even remotely applied, even tried plugging in the array values from the Devel Tab. I want to clarify that I didn't enter every element of the array; much of it does not apply. Here is what devel tells me:

field_event_date (Array, 1 element)
* 0 (Array, 4 elements)
o
value (String, 19 characters ) 2009-06-20 00:15:00
o
timezone (String, 16 characters ) America/New_York
o
timezone_db (String, 3 characters ) UTC
o
date_type (String, 8 characters ) datetime

I would think "field_event_date" (the CCK date field) should replace "Date and Time". I get a bit confused about there being a single CCK field (field_event_date) and the actual input field being split into separate date and time fields. I'm still stumped. Maybe I need to find out more about how to dissect the CCK date field down to it's component level. Also the content type is a standard page created for users to add events, it is not an "Event" added by the Event module.

All the other options I've seen allow the user to schedule the end date, which I am not comfortable with - people will then be able to extend the end date to get more exposure for themselves or their organization. I don't want to be the "event policeman" and start booting users who abuse the system. I want to be the "benevolent event dictator". :)


A tutorial for this

harris.ric - Mon, 2009-11-02 20:09

for anyone trying to do this there's a tutorial using Rules, Views & token modules. Just need to use an unpublish action instead.

http://drupal.org/node/520012