PDA

View Full Version : Username change via external system?


mypcb
08-29-2012, 09:08 PM
We've got vbulletin pretty much integrated into our existing member portal, but I have a quick question re: username changes. When you change an existing user's username via admincp, does it simply update the username field in the user table, or is there more to it?

We have a "change username" function built-in to our existing member portal and we want to update it so that when someone wants to change their username they can just do it there without having to also request that we manually change their vbulletin username ...

I know it's recommended to "update your counters" after changing a username (I assume this refers to the "Update Post Counts" function), which we can initiate programmatically, I'm just wondering if there's anything else we need to or should do besides simply updating the username in the user table?

I assume everything is handled internally based on the user's ID and the username is simply for show next to their posts, etc. so I'm hoping the username isn't found in any of the other 150+ tables that I'm not familiar with. :)

Scanu
08-29-2012, 10:18 PM
I don't remember where, but i see a mod here that does this

mypcb
08-29-2012, 10:44 PM
I've seen a mod that allows users to change their own username, but that's not what we want to do. We want to change the username programatically via our existing systems by simply issuing one or more mysql queries to update the necessary table(s).

kh99
08-30-2012, 01:27 PM
If you look in file includes/class_dm_user.php around line 2363, there's a function update_username() that makes changes to a number of database tables in the event that a username is changed. It's also possible to use the user datamanager (i.e. call that funciton instead of copying the code), but unless your external code is including vbulletin's global.php, it's probably more trouble than it would be worth.

mypcb
08-30-2012, 11:26 PM
Thanks for the reply. Looks like it does update quite a few tables! What would you say is the "best practice" in terms of doing what we want to do? Is it better to call the change_username function, or could we simply do something like this and achieve the same thing? Or would doing this simply update the username in the user table and that's it?

...
$userdm->set_existing($userinfo);
$userdm->set('username', $newusername);
$changeuser = $userdm->save();

And if it's better to call the update_username function, would it just be something like this??

...
$userdm->set_existing($userinfo);
$userdm->update_username($userid, $newusername);
$changeuser = $userdm->save();

kh99
08-31-2012, 06:02 AM
You should follow your first example. I only pointed out update_username() because I thought you might need to change the database directly instead of using the vb datamanager.

mypcb
08-31-2012, 01:13 PM
We can do either, and it looks like using the datamanager will be a little simpler than re-coding 10-15 mysql queries so we'll try that route. Thanks!