2

I have written a migration script that migrates data from Drupal 4.7 to Drupal 6. It is highly customized for my purposes. I am able to create new nodes with no problem. However, after I save the nodes I am noticing that the user that created it is showing up as "Anonymous" and in the database it has a uid of 0. Yet, when I wrote my code I have set it to 1 when the migrated user id has not been found. I have even double-checked to make sure that it is setting the uid to 1.

Why would this be setting it to uid = 0 when I specifically set it to 1?

  $node = new stdClass();
  $node->type = 'opinion_article';
  $node->title = $blog->title;
  $node->body = $blog->body;
  $node->teaser = $blog->teaser;

  //We need to associate the content to the user that created it.
  $node->uid = 1;
  $node->name = $account->name;
  $node->status = $blog->status;
  $node->comment = $blog->comment;
  $node->promote = $blog->promote;

  //Set a default topic of Migration Data.
  $node->field_topics[] = array('nid' => 820); ###### Remember to update this node ID to reflect the topic nid on dev once created. It is nid 916 on the dev server.  ################

  //Set the parent group
  $node->og_parent = $parent_nid;

  //Create the node
  $node = node_submit($node);
  node_save($node);
4

The problem is that node_submit() contains the following code.

  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;
    }
  }

When it's not able to load the user object having $node->name as username, it sets the user ID to zero. As you have already set the values for the node object, it is useless to pass the node to node_submit(); it would be better to just pass it to node_save().

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.