You are here

function cleantalk_user_delete in Anti Spam by CleanTalk 8

Same name and namespace in other branches
  1. 7 cleantalk.module \cleantalk_user_delete()
  2. 7.2 cleantalk.module \cleantalk_user_delete()

Implements hook_user_delete().

File

./cleantalk.module, line 534
Main CleanTalk integration module functions.

Code

function cleantalk_user_delete(\Drupal\user\UserInterface $account) {
  $result = db_select('cleantalk_uids', 'c')
    ->fields('c', array(
    'ct_request_id',
    'ct_result_comment',
  ))
    ->condition('uid', $account
    ->id(), '=')
    ->range(0, 1)
    ->execute();
  if ($result
    ->rowCount() > 0) {
    $ct_result = $result
      ->fetchObject();

    // If ct_result_comment is empty then user is approved by server.
    // But we delete it then user is not approved by admin.
    // We need to send negative feedback.
    _cleantalk_send_feedback($ct_result->ct_request_id, 0);
    db_delete('cleantalk_uids')
      ->condition('uid', $account
      ->id(), '=')
      ->execute();
  }
}