function flag_user_account_removal in Flag 7.3
Same name and namespace in other branches
- 7.2 flag.module \flag_user_account_removal()
Shared helper for user account cancellation or deletion.
2 calls to flag_user_account_removal()
- flag_user_cancel in ./
flag.module - Implements hook_user_cancel().
- flag_user_delete in ./
flag.module - Implements hook_user_delete().
File
- ./
flag.module, line 1190 - The Flag module.
Code
function flag_user_account_removal($account) {
// Remove flags by this user.
$query = db_select('flagging', 'fc');
$query
->leftJoin('flag_counts', 'c', 'fc.entity_id = c.entity_id AND fc.entity_type = c.entity_type AND fc.fid = c.fid');
$result = $query
->fields('fc', array(
'fid',
'entity_id',
))
->fields('c', array(
'count',
))
->condition('fc.uid', $account->uid)
->execute();
foreach ($result as $flag_data) {
// Only decrement the flag count table if it's greater than 1.
if ($flag_data->count > 0) {
$flag_data->count--;
db_update('flag_counts')
->fields(array(
'count' => $flag_data->count,
))
->condition('fid', $flag_data->fid)
->condition('entity_id', $flag_data->entity_id)
->execute();
}
elseif ($flag_data->count == 0) {
db_delete('flag_counts')
->condition('fid', $flag_data->fid)
->condition('entity_id', $flag_data->entity_id)
->execute();
}
}
db_delete('flagging')
->condition('uid', $account->uid)
->execute();
// Remove flags that have been done to this user.
_flag_entity_delete('user', $account->uid);
}