Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-04-2011, 01:43 AM
abjds.com abjds.com is offline
 
Join Date: Aug 2007
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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!
Reply With Quote
  #2  
Old 02-04-2011, 11:33 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
where 9 is the group you want to inactivate and 10 is the group you want to merge in to. (Also, if you have a database prefix defined you'd need to add that before 'user' on the first line).

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.
Reply With Quote
  #3  
Old 02-06-2011, 12:55 AM
abjds.com abjds.com is offline
 
Join Date: Aug 2007
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!!!
Reply With Quote
  #4  
Old 12-06-2012, 06:11 PM
tsptom tsptom is offline
 
Join Date: Jan 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 12-06-2012, 06:31 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Reply With Quote
  #6  
Old 12-06-2012, 08:42 PM
tsptom tsptom is offline
 
Join Date: Jan 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 12-06-2012, 09:14 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 12-07-2012, 04:27 PM
tsptom tsptom is offline
 
Join Date: Jan 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Also, in includes/class_dm.php, part of function verify_list() does the opposite - takes the array and makes a comma-separated list.
Is that what the "implode" does?

Thanks again.
Reply With Quote
  #9  
Old 12-07-2012, 04:29 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #10  
Old 12-08-2012, 08:11 PM
tsptom tsptom is offline
 
Join Date: Jan 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 = ....
Reply With Quote
Благодарность от:
kh99
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:59 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.09022 seconds
  • Memory Usage 2,263KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete