1

I am trying to migrate user data. There aer around 500 users that needs to be migrated. Problem is that these 500 users are registered in old site and i cant just insert these to new DB as new users are registered so uid of new user and these 500 users will collide , to avoid these i wrote a script to read all these data again and using user_save i am re inserting them , but the problem is

$new_user = array(
        'name'   => $row[name],
        'mail'   => $row[mail],
        'pass'   => $row[pass],
        'status' => $row[status],
        'init'   => $row[init]
    );

Here 'pass' is already md5 so when saving using $account = user_save('',$new_user); it is md5 hashed again ! Is there a better way to do this ?

1 Answer 1

2

I'm not sure if there is a drupal way of doing this that does not use md5.

My first thought is to save the user w/o a password. The user object should then have a uid which you can use in SQL to insert the existing hashed password into the user's password field.

db_query("UPDATE {users} SET pass ='%s' WHERE uid = %d", pass, $new_user->uid);
3
  • Ok i am doing this in next step to save profile values user_save((object) array('uid' => $account->uid),$profile_val); so can i alter this and add pass field with existing md5 hash pass next to uid in array ? Or a manual update sql query ?
    – user88975
    Commented Sep 8, 2011 at 10:01
  • I would do the manual update sql query shown above. But I'm curious as to why you are setting the uid. Drupal should set that for you when you run user_save()
    – decoy
    Commented Sep 8, 2011 at 10:09
  • I am doing it in 2 steps , creating user , then for that user adding profile values
    – user88975
    Commented Sep 9, 2011 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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