diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-03-12 15:56:30 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-03-12 15:56:30 +0000 |
commit | 2c3c1a93030bf62ccc2d4a3386b756f01b672d94 (patch) | |
tree | a491665a772f1f99b23f1766f1b3ae749be91641 | |
parent | 160b42812c2ec0a32fcdcd02f32d3f86e549fac7 (diff) | |
download | brdo-2c3c1a93030bf62ccc2d4a3386b756f01b672d94.tar.gz brdo-2c3c1a93030bf62ccc2d4a3386b756f01b672d94.tar.bz2 |
- Patch #705306 by moshe weitzman: user_cancel_delete() method calls into a 'standard' user_delete_multiple() API.
-rw-r--r-- | modules/comment/comment.module | 14 | ||||
-rw-r--r-- | modules/node/node.module | 41 | ||||
-rw-r--r-- | modules/poll/poll.module | 15 | ||||
-rw-r--r-- | modules/profile/profile.module | 12 | ||||
-rw-r--r-- | modules/statistics/statistics.module | 15 | ||||
-rw-r--r-- | modules/trigger/trigger.module | 9 | ||||
-rw-r--r-- | modules/user/user.api.php | 42 | ||||
-rw-r--r-- | modules/user/user.module | 56 |
8 files changed, 129 insertions, 75 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 56fe0982c..6fdb9867e 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1312,16 +1312,18 @@ function comment_user_cancel($edit, $account, $method) { ->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. * diff --git a/modules/node/node.module b/modules/node/node.module index 6d5cdc85e..60cff49a8 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1671,27 +1671,30 @@ function node_user_cancel($edit, $account, $method) { ->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(); } /** diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 88564424c..f056d7237 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -923,16 +923,19 @@ function poll_user_cancel($edit, $account, $method) { ->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() { diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 39101fd6d..d55c0572c 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -233,15 +233,22 @@ function profile_user_insert(&$edit, $account, $category) { 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 @@ function _profile_get_fields($category, $register = FALSE) { ->orderBy('weight', 'ASC') ->execute(); } - diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index d2d0a9738..be3802fd3 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -208,16 +208,19 @@ function statistics_user_cancel($edit, $account, $method) { ->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() { diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index 2bdfec24d..db017a24a 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -514,13 +514,19 @@ function trigger_user_update(&$edit, $account, $category) { 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 @@ function _trigger_get_all_info() { return $triggers; } - diff --git a/modules/user/user.api.php b/modules/user/user.api.php index 6f818688d..07f28611c 100644 --- a/modules/user/user.api.php +++ b/modules/user/user.api.php @@ -32,11 +32,29 @@ function hook_user_load($users) { } /** + * 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 @@ function hook_user_cancel($edit, $account, $method) { ->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; } } diff --git a/modules/user/user.module b/modules/user/user.module index 0c17eaa45..510c9c261 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -2144,8 +2144,11 @@ function user_cancel($edit, $uid, $method) { ); 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 @@ function _user_cancel($edit, $account, $method) { 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 @@ function _user_cancel($edit, $account, $method) { } /** + * 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) { |