You are here

function delete_all_users_delete in Delete all 7

2 calls to delete_all_users_delete()
delete_all_drush_delete in ./delete_all.drush.inc
Drush callback to delete content
delete_all_users_submit in ./delete_all.module

File

./delete_all.module, line 496
Delete all 7.x module

Code

function delete_all_users_delete($roles = NULL) {
  $count = 0;
  if (!$roles) {
    $result = db_query('SELECT uid FROM {users} WHERE uid > 1');
    foreach ($result as $data) {
      user_delete($data->uid);
      $count++;
    }

    // Delete the URL aliases
    db_query("DELETE FROM {url_alias} WHERE source LIKE 'user/%%'");
  }
  else {
    if (is_array($roles)) {
      $result = array();
      foreach ($roles as $role) {
        $rid = db_select('role', 'r')
          ->fields('r', array(
          'rid',
        ))
          ->condition('name', $role, '=')
          ->execute()
          ->fetchField();
        $result = array_merge($result, db_select('users_roles', 'ur')
          ->fields('ur', array(
          'uid',
        ))
          ->condition('rid', $rid, '=')
          ->execute()
          ->fetchCol('uid'));
      }
    }
    else {
      $rid = db_select('role', 'r')
        ->fields('r', array(
        'rid',
      ))
        ->condition('name', $roles, '=')
        ->execute()
        ->fetchField();
      $result = db_select('users_roles', 'ur')
        ->fields('ur', array(
        'uid',
      ))
        ->condition('rid', $rid, '=')
        ->execute()
        ->fetchCol('uid');
    }
    foreach ($result as $data) {
      user_delete($data);
      $count++;
    }

    // @TODO Delete individual aliases
  }
  return $count;
}