1

I'm trying to invoke hook_user_delete and for some reason it isn't getting called. I have essentially the same function in hook_user_cancel and that gets called correctly. Basically, I go into the user edit form, then down to the bottom to "Cancel Account". From the next page, if I click "Disable the account and keep its content.", the hook_user_cancel function gets called, but if I pick "Delete the account and its content.", neither the hook_user_cancel or the hook_user_delete functions get called. I checked this by placing a dpm at the beginning of each function. My code looks like the following:

function carrier_pigeon_user_delete($account){
$num_deleted = 0;

if(is_numeric($account->uid)) {
  $num_deleted = db_delete('carrier_pigeon_subscription')
      ->condition('uid',account->uid)
      ->execute();
}
dpm($num_deleted);
}

function carrier_pigeon_user_cancel($edit, $account, $method) {
$num_deleted = 0;

if(is_numeric($account->uid)) {
    $num_deleted = db_delete('carrier_pigeon_subscription')
            ->condition('uid', $account->uid)
            ->execute();
}   
dpm($num_deleted);
}

Sorry about the formatting. Is there something I'm doing wrong here? My impression is that I need both of these to cover my bases, but I can't seem to get the first one to get called.

  • Welcome to Drupal Answers! Apart the call to dpm(), is there anything else that tells you the hooks are not called? – kiamlaluno May 9 '14 at 18:51
  • Well, my db_delete does not run as the record is still in the database. There isn't anything in watchdog other than the actual notifications that the account is getting deleted. – A.J. May 9 '14 at 19:46
1

I followed below steps and it is working when I cancel account by "delete user and its content"

/**
 * Implements hook_user_delete().
 */
function MYMODULE_user_delete($account) {
  watchdog('MYMODULE', 'hello, user: !username, user id: !uid, has been deleted', array(
    '!username' => $account->name,
    '!uid' => $account->uid
  ));
}

Go to admin/reports/dblog check if the message displayed there. Mine is showing.

| improve this answer | |
0

I have just fixed the problem. Your code works, however I had to disable and enable the module in order to Drupal calls my user_delete hook.

I hope this helps others with the same problem.

| improve this answer | |
  • Usually a cache clear/rebuild is what you want to do. Disabling and enabling a module should force a cache rebuild of hooks so it also works, but is a bit long winded. – Beebee May 26 '17 at 10:40

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.