Is there any way to cancel user votes (if there are any) when I completely delete a user account?


Thanks kiamlaluno for the first guide. I'm really lost about writing even a mini-module.

Here's the code for what i was needing:

// Cancel / subtract user vote from 'poll_choice' table, when user account is cancelled.
// The code (db_update) which subtract users vote is a copy from poll.module
function MODULE_NAME_user_delete($account) {
    $uid = $account->uid;
    $votes_id = db_query("SELECT chid FROM {poll_vote} WHERE uid = :account_id", array(':account_id' => $uid))->fetchAll();
    foreach ($votes_id as $vote_id) {
        ->expression('chvotes', 'chvotes - 1')
        ->condition('chid', $vote_id->chid)

This is for MODULE_NAME.install. We need it to make sure poll_vote table is not update before this module function is executed.

function MODULE_NAME_install(){
    ->fields(array('weight' => -1))
    ->condition('name', 'MODULE_NAME', '=')
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.