The bug happens when cancel user account from Home > Administration > People > Update user account : "Cancel the selected user accounts", if select cancellation options unpublishing or deleting the account content, but account does not have any content.

When cancelling these accounts

  • Disable the account and unpublish its content.
  • Delete the account and make its content belong to the Ivushka user.
  • Delete the account and its content.

It posts the error message:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /drupal/batch?render=overlay&id=619&op=do StatusText: Service unavailable (with message) ResponseText: Recoverable fatal error: Argument 2 passed to db_query() must be an array, null given, called in /sites/all/modules/tokenauth/tokenauth.module on line 186 and defined in db_query() (line 2313 of /includes/database/database.inc).

The bug is caused by empty content, returning NULL pointer in the tokenauth.module on line 186:

/**
 * Implements hook_user_delete().
 */
function tokenauth_user_delete(&$edit, &$account, $category = NULL) {
  $sql = 'DELETE FROM {tokenauth_tokens} WHERE uid = %d';
   db_query($sql, $account->uid);
}

It is fixed by adding the condition operator:

/**
 * Implements hook_user_delete().
 */
function tokenauth_user_delete(&$edit, &$account, $category = NULL) {
  $sql = 'DELETE FROM {tokenauth_tokens} WHERE uid = %d';
  if ( $account->uid != NULL)
     db_query($sql, $account->uid);
}
CommentFileSizeAuthor
#8 1744844_tokenauth_user_delete_8.patch588 bytesdalin

Comments

elBradford’s picture

This worked for me. A .patch would be nice, but this is such a simple fix I think the maintainer can roll this in the new dev.

andrewbenkard’s picture

Worked for me too. Thanks sergeytru.

Grayside’s picture

Status: Active » Reviewed & tested by the community
Issue tags: +ajax http 500 error

Actually, this is an upgrade path problem, and in either case the code is not doing anything except failing whenever it is run. See hook_user_delete().

Our fix should instead be:

/**
 * Implements hook_user_delete().
 */
function tokenauth_user_delete($account) {
  $sql = 'DELETE FROM {tokenauth_tokens} WHERE uid = %d';
  db_query($sql, $account->uid);
}

Checking whether a hook has indeed passed the object it has deleted is a warning sign. What could you possibly do in an implementation of the hook if that data were missing? I'll attempt to get this into -dev later tonight.

Grayside’s picture

Status: Reviewed & tested by the community » Fixed
justdave’s picture

Must not have been included in a release yet, since I just tripped this bug and my update report says I'm up-to-date. Applied the patch manually and can verify it works though.

David4514’s picture

Status: Fixed » Needs work

Still failing after the patch. However, instead of null, I'm failing because argument 2 is a string. Argument 2 of db_query must be an array.

Recoverable fatal error: Argument 2 passed to db_query() must be an array, string given, called in /var/www/taiwv2/www/Secure_Server/sites/all/modules/contrib/tokenauth/tokenauth.module on line 186 and defined in db_query() (line 2313 of /var/www/taiwv2/www/Secure_Server/includes/database/database.inc).

The preferred method is to use named placeholders with db_query. Argument 2 of db_query should be an associative array in this case.

/**
 * Implements hook_user_delete().
 */
function tokenauth_user_delete($account) {
  $sql = 'DELETE FROM {tokenauth_tokens} WHERE uid = :uid';
  db_query($sql, array(':uid'=>$account->uid));
}

While named placeholders are not required, the second argument of db_query must always be an array.

Grayside’s picture

Status: Needs work » Needs review

Thanks @David4514! That makes sense but I will have to circle back another time to confirm it works.

dalin’s picture

StatusFileSize
new588 bytes

Patch attached to make the change proposed by David4514.

Offlein’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

Grayside’s picture

Status: Reviewed & tested by the community » Fixed

Automatically closed -- issue fixed for 2 weeks with no activity.

rrirower’s picture

I recently ran into this same problem. I can attest that the patch does work.