You are here

function devel_create_users in Devel 5

Same name and namespace in other branches
  1. 6 devel_generate.inc \devel_create_users()
  2. 7 devel_generate/devel_generate.inc \devel_create_users()

Generate some random users.

Parameters

$num: Number of users to generate.

$kill: Boolean that indicates if existing users should be removed first.

1 call to devel_create_users()
devel_generate_users_form_submit in ./devel_generate.module

File

./devel_generate.inc, line 15

Code

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