If users are allowed to change their user name in Drupal, the connection to vBulletin through DrupalvB will break. To avoid this problem, make the following changes in your code:

Step 1) Find the following line in drupal_vb.module (around line 620):

_drupalvb_update_vb_user($edit_user->name, md5($edit['pass']), $edit['mail'], $userinfo['salt']);

And change it to this:

_drupalvb_update_vb_user($edit_user->name, $edit['name'], $edit['pass'], $edit['mail'], $userinfo['salt']);

By making this change you are passing both the existing user information ($edit_user) and the new user information ($edit) to the _drupalvb_update_vb_user function. I also have removed the md5 from the function call above since I seemed to have some problems with it, and have read on other posts to remove it. Not sure what the current developers think.

Step 2) Find the following line in drupalvb.inc.php (around line 196):

function _drupalvb_update_vb_user($username, $password, $email, $salt) {

And change it to this:

function _drupalvb_update_vb_user($orig_username, $username, $password, $email, $salt){

$orig_username is the original username that we are passing over to this function as reference.

Step 3) Find the following line in drupalvb.inc.php (around line 208):

db_query(_drupalvb_prefix("UPDATE {user} SET password = '%s', passworddate = '%s', salt = '%s', email = '%s', lastactivity = '%s' WHERE username = '%s'"), $passhash, $passdate, $salt, $email, $lastdate, $username);

And change it to this:

db_query(_drupalvb_prefix("UPDATE {user} SET username = '%s', password = '%s', passworddate = '%s', salt = '%s', email='%s', lastactivity = '%s' WHERE username = '%s'"), $username, $passhash, $passdate, $salt, $email, $lastdate, $orig_username);

So this code updates the user name in vBulletin in the case where we find a match for the $orig_username and $username <> $orig_username.

Step 4) Find the following line in drupalvb.inc.php (around line 211):

db_query(_drupalvb_prefix("UPDATE {user} SET email = '%s', lastactivity = '%s' WHERE username = '%s'"), $email, $lastdate, $username);

And change it to this:

db_query(_drupalvb_prefix("UPDATE {user} SET username = '%s', email = '%s', lastactivity = '%s' WHERE username = '%s'"), $username, $email, $lastdate, $orig_username);

This ensures username is updated if there is a difference between $orig_username and $username. Let me know if there are any questions.

Comments

sun’s picture

Status: Needs review » Needs work

Could you please create a real patch? See http://drupal.org/patch/create
Also, since 5.x-2.x has been completely re-written and a first release candidate is about to be released, it would be more helpful if this patch was against 5.x-2.x.

sgdev’s picture

I'd like to help you out, but I'm actually the executive of a company and not a developer. I don't have any tools on my machine other than the ability to review code. Feel free to use it as you like.

stevenpatz’s picture

Version: 5.x-1.2 » 5.x-2.x-dev
Assigned: Unassigned » stevenpatz
Status: Needs work » Needs review
StatusFileSize
new987 bytes
new1.59 KB

here are two patches.

sun’s picture

Status: Needs review » Needs work

Always create patches with diff -up, please. You should also consider to create patches against CVS, so above patches would be just in one file. See http://drupal.org/patch/create for further information. Since you're working on Windows, I recommend using TortoiseCVS to perform CVS checkouts. You do not need a CVS account to checkout from CVS.

To the patch: vB's help mentions:

If you are editing the username of an existing member, you should update your counters afterwards.
...
Update User Names:
This will update user names everywhere they occur on your forums. This may need to be done after changing a user's name in the Admin CP.

So I think we need an additional query after changing a username.

sgdev’s picture

Maybe the md5() should stay in the db_disconnect_02.patch patch? I'm not sure of the designer's intent.

sun’s picture

StatusFileSize
new2.43 KB

Nope, that's correct, since drupalvb_update_user() already generates the password hash.

Re-rolled the patch against latest DRUPAL-5--2.

sun’s picture

Assigned: stevenpatz » sun
Status: Needs work » Needs review
StatusFileSize
new4.98 KB

#142368: Login error if default language is not English has been marked duplicate of this issue.

We need more flexibility for user account updates to support altering of additional values. Attached patch implements this, needs review + testing.

sun’s picture

Version: 5.x-2.x-dev » 5.x-2.0-beta1
Status: Needs review » Fixed

I've committed the last patch now. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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