Alimozzaman

Drupal 6 to drupal 7 user migration

Posted on: April 23, 2011

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

About these ads

4 Responses to "Drupal 6 to drupal 7 user migration"

Hello.

How do I run this code? Do I run in Dev, create a module or mySQL?

You can write a module for this.

Do you have this as a module that one can download and install?

No!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: