0

Somehow I've got 2 users in my users table with the same email address (mine!). I need to delete one of them. One is user ID #1, the other is user ID #144.

When I use the advuser module to search for my email address, only one user (#144) shows up. I select it and try to delete, but it's not successful - the confirmation screen says "No selections have been applied." I'm guessing it's trying carefully to not delete user #1.

Additionally, I can't seem to change any account details in my own (user #1) account, it complains that "The e-mail address me@foo.com is already taken."

Not sure what to do next - am I safe to just do DELETE FROM users WHERE uid=144;? Or will that create dangling references elsewhere?

I'm using D7, but I had this extra user before I upgraded from D6 too.

2

Why can't you delete it using admin account?

Drupal 7 people path : goto admin -> people [ here you can manage your users account]

  • Aha, that works - thanks, I didn't know this used a different mechanism. – Ken Williams Jul 31 '12 at 12:19
4

Instead of deleting the user and risking something going bad, why don't you try just to change his e-mail address in the SQL table? If you change #144's mail won't you then be able to edit, delete his account through the usual UI way?

  • That's a good idea too, why didn't I think of that? =) – Ken Williams Jul 31 '12 at 12:20
1

If you delete your extra user via an SQL statement, you may still have content in your database (nodes) that were created by that user. You could also try to track down all of those references and fix them up, if you wanted, or you could use drush user-cancel username to remove the extra user. This presumes that the two users who have the same email address have different user names; many of the drush user commands will allow you to specify the target by uid, but user-cancel requires a username. If the usernames are unique, then drush user-cancel will re-assign all content created by said user such that it will appear to have been created by uid 1.

See http://drupal.org/project/drush for Drush.

  • Thanks. For some reason I've been having problems when using drush lately, I'm getting some "out of memory" (or similar) errors with certain commands. – Ken Williams Jul 31 '12 at 12:21
  • Copy your webserver's php.ini file to ~/.drush/php.ini (a folder called "dot drush" in your home directory). – greg_1_anderson Jul 31 '12 at 13:17
0

With Drupal 7, you can delete a user account using user_delete_multiple(array($uid)). The function will take care of any reference to that user account; it also invokes the necessary hooks, to let other modules know the user account is being deleted.

This is the code executed from that function.

  if (!empty($uids)) {
    $accounts = user_load_multiple($uids, array());

    $transaction = db_transaction();
    try {
      foreach ($accounts as $uid => $account) {
        module_invoke_all('user_delete', $account);
        module_invoke_all('entity_delete', $account, 'user');
        field_attach_delete('user', $account);
        drupal_session_destroy_uid($account->uid);
      }

      db_delete('users')
        ->condition('uid', $uids, 'IN')
        ->execute();
      db_delete('users_roles')
        ->condition('uid', $uids, 'IN')
        ->execute();
      db_delete('authmap')
        ->condition('uid', $uids, 'IN')
        ->execute();
    }
    catch (Exception $e) {
      $transaction->rollback();
      watchdog_exception('user', $e);
      throw $e;
    }
    entity_get_controller('user')->resetCache();
  }

Between the implementations of hook_user_delete(), there is also node_user_delete(), which deletes the revisions of a node made using the user account being deleted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.