Reset users


/**
 * Delete all users except uid 0 and 1.
 * Reset auto increment on users table.
 */
function _MY_MODULE_delete_users() {
  drupal_set_time_limit(0);
	
  // Delete.
  $uids = db_select('users', 'u')
  ->fields('u', array('uid'))
  ->condition('uid', array(0, 1), 'NOT IN')
  ->execute()->fetchCol();

  user_delete_multiple($uids);

  // Reset auto increment.
  db_query("ALTER TABLE users AUTO_INCREMENT = 1"); 
  // Users table doesn't use AI, reset uid sequence.
  db_query("UPDATE sequences SET value = 1");
  db_query("ALTER TABLE sequences AUTO_INCREMENT = 1");
  
  return 'User_delete_multiple is void, check for success manually';
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.