أحاول ترحيل المستخدمين من Drupal 6 إلى Drupal 7. مشكلتي هي كيفية تغيير كلمة المرور من MD5 إلى علامة التجزئة (المستخدمة بواسطة D7).
هل لديك أي فكرة؟
لتحديث كلمة مرور md5 إلى كلمة المرور المجزأة التي احتاجها لاستخدام ser_hash_password () وربط "U". إليك النص الذي استخدمته لجعله يعمل.
<?php
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$res = db_query('select * from drupal.users');
if($res) {
foreach ($res as $result) {
$hashed_pass = user_hash_password($result->pass, 11);
if ($hashed_pass) {
$hashed_pass = 'U' . $hashed_pass;
db_update('users')->fields(array('pass' => $hashed_pass))->condition('uid', $result->uid)->execute();
}
}
}
ثم ركضت
drush scr <name_of_the_script_file>
وعملت.
هناك إجابة بسيطة للغاية على هذا:
<?php
$this->destination = new MigrateDestinationUser(array('md5_passwords' => TRUE));
...
$this->addFieldMapping('pass', 'source_password');
?>
المرجع: الحفاظ على كلمات مرور المستخدم
إذا احتاج شخص ما إلى نص مستقل PHP برنامج نصي لترحيل المستخدمين من Drupal 6 إلى Drupal 7 ، فإليك:
<?php
/*
Standalone PHP script to migrate users from Drupal 6 to Drupal 7 programatically.
Date: 9-4-2012
*/
// set HTTP_Host or drupal will refuse to bootstrap
$_SERVER['HTTP_Host'] = 'example.org';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
//root of Drupal 7 site
$DRUPAL7_ROOT="/var/www/ace";
define('DRUPAL_ROOT',$DRUPAL7_ROOT);
chdir($DRUPAL7_ROOT);
require_once "./includes/bootstrap.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once "./includes/password.inc";
//connect to Drupal 6 database
//syntax:mysqli(hostname,username,password,databasename);
$db= new mysqli('localhost','ace6','ace6','ace6');
if(mysqli_connect_errno()) {
echo "Conection error. Could not connect to Drupal 6 site!";
exit;
}
//get users from Drupal 6 database
$query="select * from users";
$result=$db->query($query);
//count number of users
$num_results=$result->num_rows;
for($i=0;$i<$num_results;$i++){
//fetch each row/user
$row=$result->fetch_assoc();
//migrate only active users
if($row['status']==1){
//convert password from Drupal 6 style to Drupal 7 style
$hashed_pass='U'.user_hash_password($row['pass'],11);
//check if user with same email address already exists in Drupal 7 database, if it does, do not migrate
if (!user_load_by_mail($row['mail'])) {
$account = new stdClass;
$account->is_new = TRUE;
$account->name = $row['name'];
$account->pass = $hashed_pass;
$account->mail = $row['mail'];
$account->init = $row['mail'];
$account->status = TRUE;
$account->roles = array(DRUPAL_AUTHENTICATED_RID => TRUE);
$account->timezone = variable_get('date_default_timezone', '');
//create user in Drupal 7 site
user_save($account);
//print message
echo "User acount ".$row['name']." has been created\n";
}
}
}
?>
حسنًا ، إذا الترقية تخرج بكلمات المرور الخاصة بك موافق. أعتقد أنه ربما يمكنك إلقاء نظرة على رمز الترقية لمعرفة كيف يفعلون ذلك.
ومع ذلك ، إذا كنت تقوم فقط بترحيل المستخدمين ، فربما يكون النهج الأكثر ترجيحًا هو إرسال روابط تسجيل دخول لمرة واحدة إلى الجميع وحثهم على إعادة تعيين كلمات المرور الخاصة بهم.
إذا قمت بتشغيل هذا من devel/php على موقع D7 ، فقد وجدت أنني بحاجة فقط:
require_once "./includes/password.inc";
//connect to Drupal 6 database
//syntax:mysqli(hostname,username,password,databasename);
$db= new mysqli('localhost','ace6','ace6','ace6');
if(mysqli_connect_errno()) {
echo "Conection error. Could not connect to Drupal 6 site!";
exit;
}
//get users from Drupal 6 database
$query="select * from users";
$result=$db->query($query);
//count number of users
$num_results=$result->num_rows;
for($i=0;$i<$num_results;$i++){
//fetch each row/user
$row=$result->fetch_assoc();
//migrate only active users
if($row['status']==1){
//convert password from Drupal 6 style to Drupal 7 style
$hashed_pass='U'.user_hash_password($row['pass'],11);
//check if user with same email address already exists in Drupal 7 database, if it does, do not migrate
if (!user_load_by_mail($row['mail'])) {
$account = new stdClass;
$account->is_new = TRUE;
$account->name = $row['name'];
$account->pass = $hashed_pass;
$account->mail = $row['mail'];
$account->init = $row['mail'];
$account->status = TRUE;
$account->roles = array(DRUPAL_AUTHENTICATED_RID => TRUE);
$account->timezone = variable_get('date_default_timezone', '');
//create user in Drupal 7 site
user_save($account);
//print message
echo "User acount ".$row['name']." has been created\n";
}
}
}
كلا الموقعين كانا على نفس خادم الويب.