Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We were having issues with empty (un)publish dates returning "The 'publish on' value does not match the expected format of %time" errors when saving nodes programmatically.
The problem was that the values would come through as arrays, instead of strings, which would then get passed to the trim() function. This returned the string "array", instead of NULL, which would throw off _scheduler_strtotime(). It would return FALSE and throw the error, preventing a node save.
Just adding a check in _scheduler_strtotime() that the passed $str value was indeed a string fixed it. (patch attached)
Comment | File | Size | Author |
---|---|---|---|
scheduler_empty_dates_fix.patch | 456 bytes | breathingrock | |
Comments
Comment #1
jonathan1055 CreditAttribution: jonathan1055 commentedHello,
I've not replicated your error obviously because I do not have the custom code you are using to programatically save the nodes, but the change you suggest looks reasonable. In fact it may not actually require the plain
$str
test, justis_string($str) && trim($str) != ""
may be sufficient. Would we ever get the string '0' or 'NULL' passed in?This has to be fixed in the D7 version first, but the code lines are the same, so the patch should apply ok with an offset of ~30 lines. Do you have the means to test it in D7?
Jonathan
Comment #2
breathingrock CreditAttribution: breathingrock commentedSorry for the late reply.
I doubt I would be able to reproduce this behavior without porting a lot of our site to D7 first, which just isn't feasible.
But there's no doubt that that argument needs to be a string. I couldn't see the harm in making sure it is one.
Sorry I can't be of help.
Comment #3
szy CreditAttribution: szy commented6.x is the proper branch of the patch.
Szy.
Comment #4
jonathan1055 CreditAttribution: jonathan1055 commentedHi szy.
Yes the patch was made against the D6 scheduler but we have to correct the D7 version first. Only then, can we port the fix back to D6. Otherwise we risk the correction being lost when you upgrade to D7.
As per my comment, the patch should work in both versions.
Jonathan
Comment #5
szy CreditAttribution: szy commentedI've changed the version, because when searching issues
for 6.x with the word 'empty', this thread isn't shown.
Szy.
Comment #6
jonathan1055 CreditAttribution: jonathan1055 commentedHello,
This has been fixed in a slightly different way in #1319410: Fix "warning: trim() expects parameter 1 to be string" when entering date with no time - read from #15 onwards. The function scheduler_node_validate() will no longer call _scheduler_strtotime() if $node->publish_on is still an array. So your problem should be fixed in 7.x
You are welcome to re-open this issue if you are still having problems, or if you need that patch ported to 6.x
Jonathan