Commit 2c3c1a93 authored by Dries's avatar Dries

- Patch #705306 by moshe weitzman: user_cancel_delete() method calls into a...

- Patch #705306 by moshe weitzman: user_cancel_delete() method calls into a 'standard' user_delete_multiple() API.
parent 160b4281
......@@ -1312,15 +1312,17 @@ 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.
......
......@@ -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();
}
/**
......
......@@ -923,15 +923,18 @@ 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().
*/
......
......@@ -233,14 +233,21 @@ 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().
*/
......@@ -621,4 +628,3 @@ function _profile_get_fields($category, $register = FALSE) {
->orderBy('weight', 'ASC')
->execute();
}
......@@ -208,15 +208,18 @@ 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().
*/
......
......@@ -514,12 +514,18 @@ 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().
*/
......@@ -618,4 +624,3 @@ function _trigger_get_all_info() {
return $triggers;
}
......@@ -31,12 +31,30 @@ 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;
}
}
......
......@@ -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;
......@@ -2220,6 +2215,45 @@ function _user_cancel($edit, $account, $method) {
cache_clear_all();
}
/**
* 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().
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment