I am trying to figure out a way to unpublish or delete content based on the cck date field generated by the Date API 'date' sub-module. The content is basically a standard page type designated for the description of a public event. Without a way to automatically unpublish or delete the ( content / page / node ) the site will end up cluttered with out-of-date information. I could use the Scheduler or Event module and trust my users to enter the appropriate end date - but I don't trust my users (ie the general public)!!! Also the volume (and numerous other conditions) prohibits having a calendar associated with the content.
I have found that the ability to automatically unpublish or delete content based on various conditions is one of the most discussed issues on Drupal.org. I've spent at least 5 hours trying different search strings and reading posts related to this issue; forum posts, issues, book pages. Unfortunately all the discussions I've seen are tail-chasing: "this module should handle that" or "try out this link", with never an actual posted solution.
So far the only way to accomplish this seems to be with the Rules module. (So far I cannot find any access to the vaunted Rules Scheduler (yes, I enabled it). The vanishing Scheduler issue is documented in the rules module discussion group, but no solution is posted that I can find; I searched through the issue queue for all statuses and don't even find it listed.)
I'm using Drupal 6.12 and the latest recommended versions of CCK, Date API and Rules. I get as far as creating an 'action' in Rules to "Unpublish created content". When I "Add a condition" I choose 'field has value', then the cck date field I created, then: stumped! 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 PHP format expected is this:
" Advanced usage only: PHP code that returns the value to set. Should not include 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):
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([node:field_event_date-timestamp] => [node:field_event_date-value]),
return array(
0 => array(Date => [node:field_event_date-value]);
1 => array(Time => [node:field_event_date-datetime]);
return array(
1 => array(Date => [node:field_event_date-value]),
2 => array(Time => [node:field_event_date-datetime]);
I've stopped getting the red "You have to return the default value in the expected format." error, but I still get the "Field Date and Time is required." error.
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 to documentation team.
Comments
Also interested in this
I'm in the same boat. I can't get past the "You have to return the default value in the expected format." issue you describe. Can you explain this to me while we wait on the full response to your request?
Thanks!
Thomas
RE: Also interested in this
Hi Thomas,
Apparently the rules engine knows if the basic commands are wrong and returns the error you are seeing. I just tried to follow the recommended format (see my original post and/or the instructions on the Rules page itself). I tried entering a number of substitute values in the "custom PHP" window, this is an example:
return array(
0 => array([node:field_event_date-date] => [node:field_event_date-time]),
While that stopped the "You have to return the default value in the expected format." error, it isn't the correct code needed and cannot work as it uses "Token replacement patterns". I have since discovered that Rules does not recognize the "Token replacement patterns" that are outlined on the rules page, not sure why they are there. Maybe as signposts for the people upgrading from the "Workflow_NG" module.
I keep thinking there is an answer to this already posted. I know the question has been posted countless times, but never a solution to go with it. It seems to be an ability that a large percentage of Drupal users want to have on their site. If we do get this solved, I will definitely write a beginners-level, step-by-step tutorial and submit it to the document team for inclusion in the handbook.
I have tried to glean enough from a couple of PHP tutorials to create the code that can replace the CCK date and time fields values, but I cannot get it right. We need someone with solid PHP skills to respond to this. (hint, hint - nudge, nudge) :)
I too am having an issue
I too am having an issue similar to this. I have posted to the Date Issues forum as well as to the main forum.
http://drupal.org/node/520712
You mentioned the token values do not work in the triggered rules section. Not true as I use them a lot in other fields that are not Date fields. So the problem lies with the date field.
The problem here is that the date field you are trying to update or read seems to pass a filter on the input before it evaluates it and when it sees tokens, it doesn't evaluate them, it claims they are the incorrect format.
So working around tokens, I also tried to use the Custom php window and also just tried to use plain php with the php evaluator but once again, the format is not in a date format, so it doesn't even evaluate the php code!!
I also have searched and posted on this topic but there doesn't seem to be any posts on it. The way I look at it.. it's a bug. The window really should be able to accept php code THEN convert that output and THEN recognize it as the correct format and the work with it.
Maybe you should also post this to the issue que in Project Date, as that seems to be where the problem lies. Feel free to reference my post above as well.
_
Have you seen:
http://drupal.org/project/rules -> Read Documentation -> Rules: Rule Based Action Execution (Drupal 6) -> 3. Tutorials / Getting started... -> Tutorial 3: Publish content based on a CCK date field (it's hot off the presses!) ?
Here's a quick tutorial on
Here's a quick tutorial on how to do it with CCK date and cron:
http://www.examiner.com/x-8158-Open-Source-Examiner~y2010m4d16-Drupal-Ho...
Do you know of a way to
Do you know of a way to something similar to this using Drupal 5
_
For d5 the rules module was called workflow_ng -- try that.
Node Expire + CCK Date Field
I am having the same problem. I am trying to automatically unpublish nodes based on CCK date field.
I am using CCK and Date modules. In my project users fill the start and expiry date using calendar. Now, I need to unpublish the nodes automatically when the date is expired.
I think node expire can be a great module if cck date field's value can be passed to node expire's 'Expiration Date' field. Is there anyone who can help me????????