--- http://drupalcode.org/viewvc/drupal/drupal/modules/comment/comment.module 2010/03/07 23:14:20 1.852 +++ http://drupalcode.org/viewvc/drupal/drupal/modules/comment/comment.module 2010/03/12 15:56:29 1.853 @@ -1312,16 +1312,18 @@ ->condition('last_comment_uid', $account->uid) ->execute(); break; - - case 'user_cancel_delete': - module_load_include('inc', 'comment', 'comment.admin'); - $cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); - comment_delete_multiple($cids); - break; } } /** + * Implements hook_user_delete(). + */ +function comment_user_delete($account) { + $cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); + comment_delete_multiple($cids); +} + +/** * This is *not* a hook_access() implementation. This function is called * to determine whether the current user has access to a particular comment. * --- http://drupalcode.org/viewvc/drupal/drupal/modules/node/node.module 2010/03/08 02:41:46 1.1245 +++ http://drupalcode.org/viewvc/drupal/drupal/modules/node/node.module 2010/03/12 15:56:29 1.1246 @@ -1671,27 +1671,30 @@ ->condition('uid', $account->uid) ->execute(); break; + } +} - case 'user_cancel_delete': - // Delete nodes (current revisions). - // @todo Introduce node_mass_delete() or make node_mass_update() more flexible. - $nodes = db_select('node', 'n') - ->fields('n', array('nid')) - ->condition('uid', $account->uid) - ->execute() - ->fetchCol(); - node_delete_multiple($nodes); - // Delete old revisions. - $revisions = db_query('SELECT vid FROM {node_revision} WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); - foreach ($revisions as $revision) { - node_revision_delete($revision); - } - // Clean history. - db_delete('history') - ->condition('uid', $account->uid) - ->execute(); - break; +/** + * Implements hook_user_delete(). + */ +function node_user_delete($account) { + // Delete nodes (current revisions). + // @todo Introduce node_mass_delete() or make node_mass_update() more flexible. + $nodes = db_select('node', 'n') + ->fields('n', array('nid')) + ->condition('uid', $account->uid) + ->execute() + ->fetchCol(); + node_delete_multiple($nodes); + // Delete old revisions. + $revisions = db_query('SELECT vid FROM {node_revision} WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); + foreach ($revisions as $revision) { + node_revision_delete($revision); } + // Clean history. + db_delete('history') + ->condition('uid', $account->uid) + ->execute(); } /** --- http://drupalcode.org/viewvc/drupal/drupal/modules/poll/poll.module 2010/02/02 07:39:21 1.338 +++ http://drupalcode.org/viewvc/drupal/drupal/modules/poll/poll.module 2010/03/12 15:56:29 1.339 @@ -923,16 +923,19 @@ ->condition('uid', $account->uid) ->execute(); break; - - case 'user_cancel_delete': - db_delete('poll_vote') - ->condition('uid', $account->uid) - ->execute(); - break; } } /** + * Implements hook_user_delete(). + */ +function poll_user_delete($account) { + db_delete('poll_vote') + ->condition('uid', $account->uid) + ->execute(); +} + +/** * Implements hook_rdf_mapping(). */ function poll_rdf_mapping() { --- http://drupalcode.org/viewvc/drupal/drupal/modules/profile/profile.module 2010/01/13 14:01:34 1.287 +++ http://drupalcode.org/viewvc/drupal/drupal/modules/profile/profile.module 2010/03/12 15:56:29 1.288 @@ -233,15 +233,22 @@ function profile_user_cancel(&$edit, $account, $method) { switch ($method) { case 'user_cancel_reassign': - case 'user_cancel_delete': db_delete('profile_value') ->condition('uid', $account->uid) ->execute(); - break; } } /** + * Implements hook_user_delete(). + */ +function profile_user_delete($account) { + db_delete('profile_value') + ->condition('uid', $account->uid) + ->execute(); +} + +/** * Implements hook_user_load(). */ function profile_user_load($users) { @@ -621,4 +628,3 @@ ->orderBy('weight', 'ASC') ->execute(); } - --- http://drupalcode.org/viewvc/drupal/drupal/modules/statistics/statistics.module 2010/02/07 17:29:09 1.331 +++ http://drupalcode.org/viewvc/drupal/drupal/modules/statistics/statistics.module 2010/03/12 15:56:29 1.332 @@ -208,16 +208,19 @@ ->condition('uid', $account->uid) ->execute(); break; - - case 'user_cancel_delete': - db_delete('accesslog') - ->condition('uid', $account->uid) - ->execute(); - break; } } /** + * Implements hook_user_delete(). + */ +function statistics_user_delete($account) { + db_delete('accesslog') + ->condition('uid', $account->uid) + ->execute(); +} + +/** * Implements hook_cron(). */ function statistics_cron() { --- http://drupalcode.org/viewvc/drupal/drupal/modules/trigger/trigger.module 2010/03/07 07:22:42 1.59 +++ http://drupalcode.org/viewvc/drupal/drupal/modules/trigger/trigger.module 2010/03/12 15:56:30 1.60 @@ -514,13 +514,19 @@ function trigger_user_cancel($edit, $account, $method) { switch ($method) { case 'user_cancel_reassign': - case 'user_cancel_delete': _trigger_user('user_delete', $edit, $account, $method); break; } } /** + * Implements hook_user_delete(). + */ +function trigger_user_delete($account) { + _trigger_user('user_delete', $edit, $account, $method); +} + +/** * Implements hook_user_view(). */ function trigger_user_view($account) { @@ -618,4 +624,3 @@ return $triggers; } - --- http://drupalcode.org/viewvc/drupal/drupal/modules/user/user.api.php 2010/02/09 22:30:30 1.20 +++ http://drupalcode.org/viewvc/drupal/drupal/modules/user/user.api.php 2010/03/12 15:56:30 1.21 @@ -32,11 +32,29 @@ } /** + * Respond to user deletion. + * + * This hook is invoked from user_delete_multiple() after the account has been + * removed from the user tables in the database, and before + * field_attach_delete() is called. + * + * @param $account + * The account that is being deleted. + * + * @see user_delete_multiple() + */ +function hook_user_delete($account) { + db_delete('mytable') + ->condition('uid', $account->uid) + ->execute(); +} + +/** * Act on user account cancellations. * * The user account is being canceled. Depending on the account cancellation - * method, the module should either do nothing, unpublish content, anonymize - * content, or delete content and data belonging to the canceled user account. + * method, the module should either do nothing, unpublish content, or anonymize + * content. * * Expensive operations should be added to the global batch with batch_set(). * @@ -83,26 +101,6 @@ ->condition('uid', $account->uid) ->execute(); break; - - case 'user_cancel_delete': - // Delete nodes (current revisions). - $nodes = db_select('node', 'n') - ->fields('n', array('nid')) - ->condition('uid', $account->uid) - ->execute() - ->fetchCol(); - foreach ($nodes as $nid) { - node_delete($nid); - } - // Delete old revisions. - db_delete('node_revision') - ->condition('uid', $account->uid) - ->execute(); - // Clean history. - db_delete('history') - ->condition('uid', $account->uid) - ->execute(); - break; } } --- http://drupalcode.org/viewvc/drupal/drupal/modules/user/user.module 2010/03/12 05:20:29 1.1135 +++ http://drupalcode.org/viewvc/drupal/drupal/modules/user/user.module 2010/03/12 15:56:30 1.1136 @@ -2144,8 +2144,11 @@ ); batch_set($batch); - // Allow modules to add further sets to this batch. - module_invoke_all('user_cancel', $edit, $account, $method); + // Modules use hook_user_delete() to respond to deletion. + if ($method != 'user_cancel_delete') { + // Allow modules to add further sets to this batch. + module_invoke_all('user_cancel', $edit, $account, $method); + } // Finish the batch and actually cancel the account. $batch = array( @@ -2193,15 +2196,7 @@ if (!empty($edit['user_cancel_notify'])) { _user_mail_notify('status_canceled', $account); } - db_delete('users') - ->condition('uid', $account->uid) - ->execute(); - db_delete('users_roles') - ->condition('uid', $account->uid) - ->execute(); - db_delete('authmap') - ->condition('uid', $account->uid) - ->execute(); + user_delete($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; @@ -2221,6 +2216,45 @@ } /** + * Delete a user. + * + * @param $uid + * A user ID. + */ +function user_delete($uid) { + user_delete_multiple(array($uid)); +} + +/** + * Delete multiple user accounts. + * + * @param $uids + * An array of user IDs. + */ +function user_delete_multiple(array $uids) { + if (!empty($uids)) { + $accounts = user_load_multiple($uids, array()); + + foreach ($accounts as $uid => $account) { + module_invoke_all('user_delete', $account); + field_attach_delete('user', $account); + } + + 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(); + + entity_get_controller('user')->resetCache(); + } +} + +/** * Page callback wrapper for user_view(). */ function user_view_page($uid) {