I'm unsure if this is a bug or not in drupal 5.8, so I want to get your opinions on this.

I am opening a node, making some changes, and then saving it. My process is this:

$node = node_load($this_product_name_id);
// ...do some stuff here
$node = node_submit($node);
if ($node->validated) {
  node_save($node);
}

I noticed that the "created" field of my node table was being changed here. Looking into it, node_submit has this line, which is causing my grief:
$node->created = !empty($node->date) ? strtotime($node->date) : time();

I don't understand why, but it seems that it's checking for $node->date, which is never set by node_load. Maybe it should be?

I then saw that node_validate does set this properly, so maybe I should be using the $node = node_validate($node) function, but I am not. When I used it, it tried making me a new nid, which I didn't like.

Instead, I am now doing this:

$node = node_load($this_product_name_id);
// do some stuff here
$node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O');
$node = node_submit($node);
if ($node->validated) {
  node_save($node);
}

Is my process wrong (ie I need to find a way to incorporate node_validate() into my sequence? Or is this a bug with one of the functions that node->date should be set?

Either way, now I'm worked around, but I'd like to know what's best.

Thanks!!
berto

Comments

BladeRider’s picture

We had exactly the same issue as yourself, when updating many nodes programmatically, and used virtually identical code to resolve the issue.

My own suspicion is that it may have something to do with an admin users ability to change the (created) datestamp on any node - the information found in the "Authoring" fieldset on node editing pages when viewed as admin.

Berto’s picture

Thanks BladeRider - At least if others have this same problem they can see the workaround here.

Cheers!