我沒有足夠的積分,添加評論,但我做了一些改進,以hross'的答案(並提交了更新草案)。
這裏的文檔和指定非默認的用戶表對於那些手工做的Drupal 6〜7個合併的能力改進腳本。它還包含jpb的檢查。
<?php
/**
* Use this script to update Drupal 6 users password hashes to Drupal 7 specs.
*
* Ensure you BACKUP YOUR USERS TABLE before using this script! If not your whole site!
* Name this file update_users.php and place in your Drupal root, same place as update.php
*
* - If you've manually inserted a new table into your database, change the $databasename below.
* - If this does not run, ensure you are logged into your site as admin.
* - If this does not run, check your drupal watchdog and/or PHP logs
* - If you see this error "PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'pass' at row 1:"
* you need to update your table's structure so that pass is a varchar(128).
*
* BACKUP, THIS MAY BREAK YOUR SITE AND EAT YOUR DATA!
*/
echo "Starting. \r\n";
// Change this if you've made a custom table
$databasename = "users";
// Update this many users
$count = 1000;
// bootstrap stuff
define('DRUPAL_ROOT', getcwd());
include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
// Lower than DRUPAL_HASH_COUNT to make the update run at a reasonable speed.
$hash_count_log2 = 11;
// Hash again all current hashed passwords.
$has_rows = FALSE;
$result = db_query_range("SELECT uid, pass FROM {" . $databasename . "} WHERE uid > 10 ORDER BY uid", 0, $count);
foreach ($result as $account) {
$has_rows = TRUE;
if (substr($account->pass, 0, 1) != 'U') {
echo "updating account: " . $account->uid . " \r\n";
$new_hash = user_hash_password($account->pass, $hash_count_log2);
if ($new_hash) {
// Indicate an updated password.
$new_hash = 'U' . $new_hash;
db_update($databasename)
->fields(array('pass' => $new_hash))
->condition('uid', $account->uid)
->execute();
}
}
}
echo "Done.";
?>
完美工作,謝謝!我需要編輯的一件事就是第19行的SQL ...如果其他人使用此uid應該大於1以避免重新刷新管理員密碼。 – 2011-06-01 19:34:05
好點=)。更新。 – hross 2011-06-01 19:56:26
我覺得你的意思user_update_7000,不user_update_7200 – aaronbauman 2016-06-23 16:37:15