Currently, node_export sets the author of an imported node to be the user doing the import.
This causes problems with drush, and furthermore, would it not be more desirable behaviour to attempt to preserve the uid of the incoming node?

CommentFileSizeAuthor
#6 node_export_uids.patch1.33 KBsandfurz

Comments

danielb’s picture

Status: Active » Closed (fixed)

This doesn't make sense. A uid is a meaningless piece of data that could lead to false user matches. This is why it is removed.

joachim’s picture

It depends on the case, surely?

danielb’s picture

I don't see how. The uid is specific to the site you exported from, you can't guarantee they will have the same ID on the new site, or that they will even exist. The only way to guarantee this is if you have somehow exported users as well, such as by copying the database - which begs the question; why aren't you using the same technique for nodes?

Additionally, this isn't just a limitation of node_export, it's a limitation of drupal.

Observe the source of this function: http://api.drupal.org/api/function/node_save/6

  if ($node->is_new) {
    _node_save_revision($node, $user->uid);
    drupal_write_record('node', $node);
    db_query('UPDATE {node_revisions} SET nid = %d WHERE vid = %d', $node->nid, $node->vid);
    $op = 'insert';
  }

The call to _node_save_revision() forces the currently logged in user to be the author of the node.

The only option to change this is to write a custom version of node_save(), which is possible, but without being extremely clever with it you will wind up assigning nodes to the wrong user because they happen to have the right ID.

joachim’s picture

Ah, fair enough. I guess that means with drush we import as uid 1, or provide an option.

joachim’s picture

Oh hang on, there *would* be a way to spoof that -- before node_save is called, do:

global $user;
$current_user = $user;
$user = user_load(someone else);

node_save();

// restore the user
$user = $current_user;

But there are most likely some hairy security implications, so best left alone!

sandfurz’s picture

Component: Code » Node Export
StatusFileSize
new1.33 KB

If someone is still interested, try this patch (6.x-2.21).
Make sure to trigger the new checkbox "retain original author's user id ... " on admin/settings/node_export.

... recently, I had to migrate some users along with their corresponding nodes (content profile) by just dumping the users-table. So it was very, very useful to retain their original user id. :-)

alexku’s picture

Patch worked for me, thanks.

This feature is useful if you need to move content_profile nodes with users.

hedac’s picture

Component: Node Export » Node export

thank you sandfurz.
It makes sense to me to maintain author... when working on copies of the same site where you know users are the same. developement and live versions for example.

aubjr_drupal’s picture

I'm working in a system of sites where there's a single sign on authentication across all the sites. As a result, the user 'name' is forced to be unique across all sites connecting to the auth system. That means that the $node->name is unique, from Site A to Site B, but the uids vary between A and B, as they are generated individually, at different times. (It's not the best system, but it's what we have.)

Therefore, the ability in site B to check $node->'name' from nodes being imported from site A, and update the $node->uid to the uid assigned to the matching name in B, would be really helpful.

This patch above lays the foundation for a good way to do it, with a tweak to the db_fetch_object and the logic to test $_users for the $node->'name'.

I realize that my user name/authentication situation is probably not the norm, but would it be possible to add this ability to the module (I'm using 6.x-3.2), as long as an admin could turn off the feature (and have it off by default)?

bcobin’s picture

Running into this issue now - any hope for a D7 version? Thanks...

vcrkid’s picture

#6 can be used with 6.x-3.4 by doing the following:

1) The first part of the patch goes into node_export.pages.inc.
2) The second part gos into node_export.module.
3) Select the new checkbox "retain original author's user id ... " on admin/settings/node_export

Thanks to sandfurz (for the original patch) and to bisonbleu (for tips on adapting it)!!!

That's what I call open-source teamwork!

vcrkid’s picture