hook_user_cancel($edit, $account, $method)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, or anonymize content.
Expensive operations should be added to the global batch with batch_set().
@see hook_user_cancel_methods_alter()
$edit The array of form values submitted by the user.
$account The user object on which the operation is being performed.
$method The account cancellation method.
modules/user/user.api.php, line 71
<?php
function hook_user_cancel($edit, $account, $method) {
switch ($method) {
case 'user_cancel_block_unpublish':
// Unpublish nodes (current revisions).
module_load_include('inc', 'node', 'node.admin');
$nodes = db_select('node', 'n')
->fields('n', array('nid'))
->condition('uid', $account->uid)
->execute()
->fetchCol();
node_mass_update($nodes, array('status' => 0));
break;
case 'user_cancel_reassign':
// Anonymize nodes (current revisions).
module_load_include('inc', 'node', 'node.admin');
$nodes = db_select('node', 'n')
->fields('n', array('nid'))
->condition('uid', $account->uid)
->execute()
->fetchCol();
node_mass_update($nodes, array('uid' => 0));
// Anonymize old revisions.
db_update('node_revision')
->fields(array('uid' => 0))
->condition('uid', $account->uid)
->execute();
// Clean history.
db_delete('history')
->condition('uid', $account->uid)
->execute();
break;
}
}
?>