You are here

function devel_create_users in Devel 6

Same name and namespace in other branches
  1. 5 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.

$age: The max age of each randomly-generated user, in seconds.

1 call to devel_create_users()
devel_generate_users_form_submit in ./devel_generate.module
FormAPI submission to generate users.
1 string reference to 'devel_create_users'
drush_devel_generate_generate_users in ./devel_generate.drush.inc
Command callback. Generate a number of users.

File

./devel_generate.inc, line 17

Code

function devel_create_users($num, $kill, $age = 0) {
  $url = parse_url($GLOBALS['base_url']);
  if ($kill) {
    db_query('DELETE FROM {users} WHERE uid > 1');
    drupal_set_message(t('Users deleted.'));
  }
  if ($num > 0) {
    $names = array();
    while (count($names) < $num) {
      $length = mt_rand(6, 12);
      $name = devel_generate_word($length);
      $names[$name] = '';
    }
    foreach ($names as $name => $value) {
      $pass = md5(user_password());
      $mail = $name . '@' . $url['host'];
      $now = time();
      $created = $age ? mt_rand($now - $age, $now) : $now - 1;
      $account = user_save(NULL, array(
        'name' => $name,
        'pass' => $pass,
        'mail' => $mail,
        'status' => '1',
        'created' => $created,
        'access' => $now,
        'devel_generate' => TRUE,
      ));
    }
    drupal_set_message(t('!num_users created.', array(
      '!num_users' => format_plural($num, '1 user', '@count users'),
    )));
  }
}