Hello, I would like some guidance on this as it worked in D5 (via workflow-ng) but I can't get it to work in D6. (See code snippet below)
Versions:
Drupal: 6.17
Rules: 6.x-1.2
Rules Administration UI: 6.x-1.2
Rules Scheduler: 6.x-1.2
Scheduler: 6.x-1.7
Node Import: 6.x-1.0-rc4
Objective: Import nodes from a CSV file that includes fields (adstartdate, adenddate) containing the dates to Publish and Unpublish the nodes. (Publish at 00:00:01, Unpublish at 23:59:59 on the given day).
I keep getting:
"The 'publish on' value does not match the expected format of 2010-07-20 22:46:09"
"The 'unpublish on' value does not match the expected format of 2010-07-20 22:46:09"
Note that to get this to work in D6, I have tried assigning mktime(...) to $node->publish_on AND tried date('Y-m-d H:i:s', mktime(...)) and get the same error.
What am I doing wrong?
Here is the sample snippet (forgive all the "debug" code in there; I have been doing all sorts of testing to figure out the issue):
//
$default_duration = 180; // # Default number of days to stay active if no unpublish date given
$tempsmm = trim("[node:field_adstartdate-mm]");
$tempsdd = trim("[node:field_adstartdate-dd]");
$tempsyyyy = trim("[node:field_adstartdate-yyyy]");
$tempemm = trim("[node:field_adenddate-mm]");
$tempedd = trim("[node:field_adenddate-dd]");
$tempeyyyy = trim("[node:field_adenddate-yyyy]");
//
if ( ($tempsmm !== "") && ($tempsdd !== "") && ($tempsyyyy !== "") ) {
//echo "Start Date is NOT blank\n";
$node->publish_on = mktime(0, 0, 1,$tempsmm,$tempsdd,$tempsyyyy) ;
}
else {
//echo "Start Date is BLANK!\n";
$node->publish_on = mktime(0, 0, 1, date("m"), date("d"), date("Y")) ;
}
//echo "PUBLISH = " . $node->publish_on . "\n\n";
if (($tempemm !== "") && ($tempedd !== "") && ($tempeyyyy !== "")) {
//echo "End Date is NOT blank.\n";
$node->unpublish_on = mktime(23,59,59,$tempemm,$tempedd,$tempeyyyy) ;
}
else {
//echo "End Date is BLANK!\n";
$node->unpublish_on = mktime(22,59,59,date("m"),date("d")+$default_duration,date("Y")) ;
}
//echo "UNPUBLISH = " . $node->unpublish_on . "\n\n";
//
// Save the Node
//
return array("node" => $node);
Comments
Array missing
I haven't tried manipulating the scheduler fields directly, but looking at them with Devel I notice that they are collected in an array. You should be manipulating
$node->scheduler['publish_on']and$node->scheduler['unpublish_on'](and not$node->publish_on).I also noticed that there are four there are actually four scheduler values -- if the lines above don't do the trick maybe you'll have to reach into the
publishedandunpublishedstrings as well.Good luck!
//Johan Falk, NodeOne, Sweden
PS: If you use the Scheduler module probably don't need Rules Scheduler -- at least for publishing and unpublishing. Or am I missing something here?
Rules Scheduler seems to be necessary but is unhelpful
I'm just beginning to work on this but it seems as if Rules Scheduler would be what I would use in this scenario:
I tried to use Rules Scheduler to create a rule to check to see if the
$node->scheduler['unpublish_on']was populated and, if not, unpublish one month from the date in$node->scheduler['publish_on']. This is apparently impossible, since the only available fields seem to be CCK fields. I'm not sure how to do this otherwise.Thanks
Thanks to both of you for your responses -- I didn't know there were responses to my post until now.
@ Itangalo: OK, I have to go back and re-read the intent of the Rules Scheduler vs Scheduler then.
I am just trying to manipulate Publish on and UnPublish on Date based on imported fields -- I have no allegiance to any module and just want to get it working; whichever gets me to the finish line first is OK by me.
What is frustrating is this was working in D5 and (for me) is 1 of about 3 major functionalities that "broke" in the D6 upgrade. This in particular is critical to proper functionality because I need to Import Dates (another thing that's been a bit "iffy" since D6 upgrade) and then cause the publishing/unpublishing based on those dates.
I any case, I will try your suggestion and install Devel (just done) and see if manipulating as an array works any better. Thank you
@mjstone323: I can get to the values using PHP in the rule definition ... but you know I seem to remember a post in a Drupal Group that alluded to the tokens not being reliable for some reason. Let me see if I can find that post.
In fact, IIRC itangalo was a respondent in that thread.
MasterOfCheap.com
RescueMeUSB.com
FemaleTreasures.com
OK, some findings:
"The 'publish on' value does not match the expected format of 2010-08-27 05:14:09"
(Which is not necessarily a bad thing in that it is descriptive enough to give some key clues. When I printed out adstartdate CCK field, it looks like this: 2010-08-25T00:00:00)
1) $node->field_adstartdate[0]['value'] (CCK field) is in ISO Date format
2) $node->publish_on and $node->unpublish_on (Scheduler module) are looking for Datetime format
3) But PHP mktime() function (that I am using to add time to the "adenddate") produces dates in Datestamp (Unix Timestamp) format (references: http://php.net/manual/en/function.mktime.php and http://www.w3schools.com/php/func_date_mktime.asp)
I will investigate further and confirm my results.
BTW, I am using Rules + Scheduler modules ... not Rules Scheduler
MasterOfCheap.com
RescueMeUSB.com
FemaleTreasures.com
SOLVED!
Here is the test code that is working (not pretty-ed up or anything, but you get the idea):
$default_duration = '+180 days'; // # Default number of days to stay active if no unpublish date given$tempS = $node->field_adstartdate[0]['value']; // Start Date
$tempE = $node->field_adendate[0]['value']; // End Date
// Debug stuff
echo "Saving New Content\n\n\n\n\n\n\n";
echo "Start Date: " . $tempS . "\n";
echo "End Date: " . $tempE . "\n";
echo "Default Duration: " . $default_duration . "\n";
//
if ( is_null($tempS) )
{ $node->publish_on = strtotime('now'); }
else
{ $node->publish_on = strtotime($tempS); }
if ( is_null($tempE) )
{ $node->unpublish_on = strtotime($default_duration); // # Keep published for default duration from right now }
else
{ $node->unpublish_on = strtotime($tempE); }
return array("node" => $node);
MasterOfCheap.com
RescueMeUSB.com
FemaleTreasures.com
awesome!
I will give this a try - thank you so much!
You're welcome
FWIW, I imported (via Node Import) about a 1000 records today from various sources with dates in Y-m-d and m/d/Y format and this code worked ... so FINALLY, I have gotten over a big D6 upgrade hump!
Also, one little change since some of my dates were spaces (i.e., not null and not empty) and trim() didn't work properly on them since they are not strings, I changed it to be like this (again disclaimer that this code is not pretty and I may not do things in the most efficient as I am trying to get up to speed on PHP ... but it worked perfectly for what I needed):
$debugflag = 0;$default_duration = ' +3 months'; // # of days an Ad should stay live by default
$tempS = $node->field_adstartdate[0]['value'];
$tempE = $node->field_adenddate[0]['value'];
//
if ($debugflag > 0) {
echo "Saving New Content\n\n\n\n\n\n\n";
echo "Start Date: " . $tempS . "\n";
echo "End Date: " . $tempE . "\n";
echo "Default Duration: " . $default_duration . "\n";
}
if ( is_null($tempS) or ($tempS =='') ) {
// Using "==" comparator on purpose, will evaluate as TRUE if variable is zero or the empty string.
$node->publish_on = strtotime('now');
}
else { $node->publish_on = strtotime($tempS); }
//
if ( is_null($tempE) or ($tempE =='') ) {
if ($debugflag > 0) { echo "End Date is NULL!";}
$node->unpublish_on = strtotime($default_duration);
}
else
{
if ($debugflag > 0) { echo "End Date is NOT NULL!"; }
$node->unpublish_on = strtotime($tempE);
}
return array("node" => $node);
MasterOfCheap.com
RescueMeUSB.com
FemaleTreasures.com
Where does this code take place ?
Hello
I am a real newbie to Drupal and your topic seems to be one way to solve my problem.
I would like to test it but I can't figure out where your code snippet takes place.
Thanks for your help