Drupal 6 to drupal 7 user migration
Posted April 23, 2011
on:- In: Drupal
- 4 Comments
Here is the codes to migrate user & password from drupal 6 to drupal 7. It works fine for me.
// connect with mysql server
$mysql_server = $server; // Server name
$mysql_userName = DATABASE_USER_NAME;
$mysql_password = DATABASE_PASSWORD;
$connection = mysql_connect($mysql_server,$mysql_userName,$mysql_password);
// query
$query = “SELECT * FROM users”;
$count = 0;
$result = mysql_db_query(DATABASE_NAME, $query) or die(mysql_error() . “<br />” . $query);
while($row = mysql_fetch_array($result))
{
//if($count++ > 10) break;
if($row[uid] == 0 || $row[uid] == 1) continue;
//require_once DRUPAL_ROOT . ‘/’ . variable_get(‘password_inc’, ‘includes/password.inc’);
$new_password_hash = user_hash_password($row[pass], 11);
if($new_password_hash){
$new_password_hash = ‘U’.$new_password_hash;
}
$data = array(
‘uid’ => $row[uid],//db_next_id(db_query(‘SELECT MAX(uid) FROM {users}’)->fetchField()),
‘name’ => $row[name],
‘pass’ => $new_password_hash,
‘mail’ => $row[mail],
‘theme’ => $row[theme],
‘signature’ => $row[signature],
‘signature_format’ => $row[signature_format],
‘created’ => $row[created],
‘access’ => $row[access],
‘login’ => $row[login],
‘status’ => $row[status],
‘timezone’ => $row[timezone],
‘language’ => $row[language],
‘picture’ => !empty($row[picture])?1:0,
‘init’ => $row[init],
‘data’ => $row[data],
);
drupal_write_record(‘users’, $data);
}
4 Responses to "Drupal 6 to drupal 7 user migration"
Do you have this as a module that one can download and install?
1 | Mark K
December 22, 2011 at 1:20 pm
Hello.
How do I run this code? Do I run in Dev, create a module or mySQL?
alimozzaman
December 23, 2011 at 2:24 am
You can write a module for this.