I'm facing an odd bug. I noticed it while using together invite and buddylistinvite modules, but as far as I understand, it concerns specifically invite.

Here is how I noticed the bug : once the invitee has accepted the invitation and created his account, he is not inserted in the inviter's buddylist, but in the buddylist of another user (always the same, who has now a big buddylist but full of people he doesn't know....).

I spent a lot of time with this bug, and here is what 've found.

When the invitee creates his account, Drupal goes through the function

_invite_role_escalate($invitee)

(in invite.module, about line 544).

In this function, Drupal tries to find the invitee's inviter with :

    $inviter_uid = db_result(db_query("SELECT uid FROM {invite} WHERE mid = %d", $user->uid));

But $user is not defined there. We're inside the function and there's no "global $user" before - I traced this variable and indeed $user->uid is empty.

Thus, I don't know the meaning of the value we receive in $inviter_uid, but anyway it is not the uid of the inviter, but the uid of another user.

I tried to modify the query and replaced $user->uid with $invitee->uid, which seems more consistent (since $invitee is the variable passed to the function). In this case, the value of $invitee->uid is the invitee's uid... but now $inviter_uid is emtpy !

Comments

stucki@www.drupalfr.org’s picture

I found the solution.

First, in the _invite_role_escalate function, it is obvious that the line :

$inviter_uid = db_result(db_query("SELECT uid FROM {invite} WHERE mid = %d", $user->uid));

should be replaced by :

$inviter_uid = db_result(db_query("SELECT uid FROM {invite} WHERE mid = %d", $invitee->uid));

But this is not enough. Indeed, at the time this function is called, the record in table "invite" has not been updated to replac, in with the field "mid", 0 by the new user uid. This update is done by the _invite_set_timestamp function, which is called just after _invite_role_escalate :-)

So the second correction is, in function invite_user, to invert the order of this two functions. The line :

        _invite_set_timestamp($edit['mail'], $user->uid, $edit['invite_code']);

should be called before :

        _invite_role_escalate($user);

and not after.

I tested, and this works good.

PY.

csc4’s picture

Thanks for working this out - very helpful!!

Hopefully the change will get incorporated into the code.

smk-ka’s picture

Status: Active » Fixed

Committed to 5.x and 4.7.x branches. Thank you!
--
Stefan Kudwien
www.unleashedmind.com

Anonymous’s picture

Status: Fixed » Closed (fixed)