Commit 61e1fd78 authored by dww's avatar dww

#144695: move user generation code into devel_generate.inc and fix

some minor bugs (missing table prefixing, for() off-by-1 error,
missing format_plural(), unnecessary update to {sequences}, etc).
parent 9c1a38ce
......@@ -5,6 +5,33 @@ if (!ini_get('safe_mode')) {
set_time_limit(240);
}
/**
* Generate some random users.
*
* @param $num
* Number of users to generate.
* @param $kill
* Boolean that indicates if existing users should be removed first.
*/
function devel_create_users($num, $kill) {
$url = parse_url($GLOBALS['base_url']);
if ($kill) {
db_query('DELETE FROM {users} WHERE uid > 1');
drupal_set_message(t('Users deleted.'));
}
for ($i = 0; $i < $num; $i++) {
$uid = db_next_id('{users}_uid');
$length = rand(4, 12);
$name = devel_generate_word($length);
$pass = md5(user_password());
$mail = $name .'@'. $url['host'];
$now = time();
db_query("INSERT INTO {users} (uid, name, pass, mail, status, created, access) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $uid, $name, $pass, $mail, 1, $now, $now);
}
drupal_set_message(t('!num_users created.', array('!num_users' => format_plural($num, '1 user', '@count users'))));
}
function devel_create_nodes($records, $users, $title_length = 8) {
$possible_types = array("story", "blog", "forum", "page");
......
......@@ -64,27 +64,8 @@ function devel_generate_users_form() {
}
function devel_generate_users_form_submit($form_id, $form_values) {
$url = parse_url($GLOBALS['base_url']);
$num = $form_values['num'];
// If not in 'safe mode', increase the maximum execution time:
if (!ini_get('safe_mode')) {
set_time_limit(240);
}
if ($form_values['kill_users']) {
db_query('DELETE FROM {users} WHERE uid > 1');
drupal_set_message(t('Users deleted.'));
}
for ($i = 2; $i <= $num; $i++) {
$uid = db_next_id('{users_uid}');
$length = rand(4, 12);
$name = devel_generate_word($length);
$pass = md5(user_password());
$mail = $name .'@'. $url['host'];
$status = 1;
db_query("INSERT INTO {users} (uid, name, pass, mail, status, created, access) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $uid, $name, $pass, $mail, $status, time(), time());
}
db_query("UPDATE {sequences} SET id = %d WHERE name = 'users_uid'", $uid);
drupal_set_message(t('%num users created.', array('%num' => $num)));
require_once('devel_generate.inc');
devel_create_users($form_values['num'], $form_values['kill_users']);
}
function devel_generate_word($length){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment