When trying to create a node using drupal_execute and providing the creating user's uid in the $form_values array, if the user has the "administer nodes" permission, uid is being reset if the username is not provided in the $form_values array.
This is the problem (line 1994 of node.module):
if (user_access('administer nodes')) {
// Populate the "authored by" field.
if ($account = user_load(array('name' => $node->name))) {
$node->uid = $account->uid;
}
else {
$node->uid = 0;
}
}
This is applicable for 5.x, 6.x and 7.x.
I've attached a proposed patch. If it causes trouble with editing existing nodes, an additional condition (if node is new) may be required.
Shai
| Comment | File | Size | Author |
|---|---|---|---|
| node_module_node_submit.patch | 698 bytes | electricmonk |
Comments
Comment #1
electricmonk commentedComment #3
advseb commentedsubscribe, I think I'm also experiencing this problem while creating nodes through drupal_execute. Here is my forum post about this issue:
http://drupal.org/node/440598
I hope this could be fixed, because it is an annoying bug.
Sebastian
Comment #4
Dave Cohen commentedRegarding patch in original issue... I find it does not work in D6. In node_submit, $node->uid == 0 even when you attempt to populate it in drupal_execute(). However $node->name might be set, so I've patched my D6 to honor $node->name.