The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Making mass changes to users based on secondary usergroups?
My short question is -- is there any way to mass-move or otherwise mass-alter users based on the secondary usergroups that they belong to?
I've looked around in both 'Move Users' and 'Promotions', but both of these only list users or make changes to users based on their primary user group, which doesn't help me. Basically, we have several publicly joinable usergroups (set up as secondary usergroups) which allow our users to access various different parts of the forum when they join them. They are all secondary so that our users can choose to join more than one without affecting their basic forum usage. However due to lack of activity in some of them, we'd like to "merge" them into other, more active usergroups. Since I can't find any nice simple "merge usergroups" option (and if there is one, thwap me and point me towards it!) I figured a mass-move of the users from the inactive usergroups to the active usergroups was my next best choice... but I simple can't find anything which allows me to select them all based off the secondary usergroups. :/ Everything seems to run off primary usergroups only. Is there any way at all to do this, or any mod that I've overlooked that might help me? Or is my only choice going to be to alter someone else's mod to better suit my needs? (I'd prefer not to if I can avoid it -- I'm just a hack when it comes to backend stuff... but I don't consider the idea of manually editing hundreds of user accounts as a viable alternative.) Thanks in advance for any advice! |
#2
|
|||
|
|||
I'm not an expert on doing things through the ACP so there could be a way that I don't know about. But looking at the code, it looks like to add someone to a secondary group you'd just have to add the new groupid to the membergroupid field for that user in the 'user' database table. (membergroupid is a text field that's a comma-separated list of secondary groups).
So what you could do is add everyone who's in one secondary group to another secondary group by doing a mysql query like this: Code:
UPDATE user SET membergroupids = CONCAT(membergroupids, ',10') WHERE FIND_IN_SET(9, membergroupids) AND NOT FIND_IN_SET(10, membergroupids) // added this - see below Then when that's done you can just delete the old group in the ACP. I've tried this on a test site, but of course it might be a good idea to have a database backup before doing this, just in case. Also if you wanted you could try it first with one or a few users by adding " AND userid IN(1, 2, 3)" to the end of the query (putting the userids you want in place of 1,2,3 of course ). ...and of course you can't delete the old group before you've run the query for all users. ETA: I added "AND NOT FIND_IN_SET(10, membergroupids)" to the above code to avoid listing the same group twice in case a user is already in the second group. But if you've already done it I'm pretty sure it's OK because when it checks if a user is in a group it doesn't matter if it's there twice, and when it removes the user from a group it seems to handle the possibility of it being listed more than once. |
#3
|
|||
|
|||
kh99, thank you SO MUCH! You're fantastic. That's exactly what I wanted to do and I've tested it out on my forum as well (using a couple of test users) and it worked like a charm.
Thank you again, so much, you've saved me a lot of hassle!! I'm just not familiar at all with working directly with the SQL so the idea didn't occur to me. Thank you!!! |
#4
|
|||
|
|||
I know it is frowned upon to wake old threads at vb.com, but the above code was very helpful for what I am trying to do - add member to secondary usergroups systemically.
To take it a step further, does anyone know how you would remove a specific secondary usergoup for a member systemically? I want to be able to add and remove members from specific secondary usergroups based on being a paying subscriber. The above codes helps me set them when they subscribe. When they cancel they need to be removed from that usergroup systemically. Any ideas? Thanks. |
#5
|
|||
|
|||
As long-winded as that above post is, I didn't mention the fact that there are some things which might need to be updated when the groups change, so if you want to do it in code the best way is to use the datamanager. And when removing a group, the way the vb code does it is to get an array of current ids in membergroupids, remove the one being deleted, and set that field to the new array.
So, if you're doing this as part of a vbulletin script (as a plugin or a "vbulletin powered" page), you'd want to do something like: Code:
// $userinfo has user's info, like is returned by fetch_userinfo(), then $membergroups = fetch_membergroupids_array($userinfo); // make adjustments to $membergroups here, then... // init user data manager $userdata =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT); $userdata->set_existing($userinfo); $userdata->set('membergroupids', $membergroups); $userdata->pre_save(); if (empty($userdata->errors)) { $userdata->save(); } else { // error messages in $userdata->errors } If you're not using a vbulletin script, then you could still read the membergroupids field, build a new list, and update it, but be aware that some things might not get updated correctly (I'm not sure offhand what they are - you'd need to study includes/class_dm_user.php and see what happens when usergroups are changed). |
#6
|
|||
|
|||
OK, thanks for your help. It would be for a non-VB php script so I'll do some hunting around for possible issues in other vb modules.
|
#7
|
|||
|
|||
OK. A couple of functions with code that might help (if you're interested in copying it instead of rewriting it): in includes/functions.php, function fetch_membergroupids_array() takes the string from the membergroupids field and turns it in to an array (optionally adding in the main groupid, which you wouldn't want to do if you're only updating the secondary groups). Also, in includes/class_dm.php, part of function verify_list() does the opposite - takes the array and makes a comma-separated list.
|
#8
|
|||
|
|||
Quote:
Thanks again. |
#9
|
|||
|
|||
Right. http://us2.php.net/manual/en/function.implode.php
Edit: And by the way, I happened to have a reason to be looking at includes/class_dm_user.php this morning, and if you look at function pre_save() in that file, you can see what's done if any usergroups are changed. It looks like the only things to worry about are if you add or delete the "displaygroup", or if the changes would affect the user's ranks. |
#10
|
|||
|
|||
If anyone is interested, I found this on removing from sets. Seems to work...
UPDATE user SET membergroupids= TRIM(BOTH ',' FROM REPLACE(CONCAT(',', membergroupids, ','), CONCAT(',', 'value', ','), ',')) WHERE username = .... |
Благодарность от: | ||
kh99 |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|