You are here

function _user_delete_cancel in User Delete 6.2

Last batch processing step for cancelling a user account.

Since batch and session API require a valid user account, the actual cancellation of a user account needs to happen last.

See also

user_cancel()

1 string reference to '_user_delete_cancel'
user_delete_cancel in ./user_delete.module
Cancel a user account. This function is the Drupal 6 version of user_cancel

File

./user_delete.module, line 363
Provide account cancellation methods and API to provide the same functionalty as Drupal 7 for cancelling accounts.

Code

function _user_delete_cancel($edit, $account, $method) {
  global $user;
  switch ($method) {
    case 'user_cancel_block':
    case 'user_cancel_block_unpublish':
    default:

      // Send account blocked notification if option was checked.
      if (!empty($edit['user_cancel_notify'])) {
        _user_mail_notify('status_blocked', $account);
      }
      user_save($account, array(
        'status' => 0,
      ));
      drupal_set_message(t('%name has been disabled.', array(
        '%name' => $account->name,
      )));
      watchdog('user', 'Blocked user: %name %email.', array(
        '%name' => $account->name,
        '%email' => '<' . $account->mail . '>',
      ), WATCHDOG_NOTICE);
      break;

    // This is default's Drupal 6 behavior, but comments are not really
    // anonymized, they are marked as not confirmed, so this needs some
    // tweaks..
    case 'user_cancel_reassign':
    case 'user_cancel_delete':

      // Send account canceled notification if option was checked.
      if (!empty($edit['user_cancel_notify'])) {
        _user_mail_notify('status_canceled', $account);
      }
      user_delete(array(), $account->uid);
      drupal_set_message(t('%name has been deleted.', array(
        '%name' => $account->name,
      )));
      watchdog('user', 'Deleted user: %name %email.', array(
        '%name' => $account->name,
        '%email' => '<' . $account->mail . '>',
      ), WATCHDOG_NOTICE);
      break;
  }

  // After cancelling account, ensure that user is logged out.
  if ($account->uid == $user->uid) {

    // Destroy the current session, and reset $user to the anonymous user.
    session_destroy();
  }

  // Clear the cache for anonymous users.
  cache_clear_all();
}