![]() |
SQL query to delete secondary usergroup
Due to some recent changes in usergroups, some members inadvertently ended up with their PRIMARY and SECONDARY usergroups being duplicated.
This is causing issues when these members request for a new password and the systems throws them into a loop where they are unable to get their primary usergroup changed from Email Verification back to their normal usergroup as the system already has them tagged to the secondary usergroup. Anyway, i am looking for a SQL query to manually delete the secondary usergroup of the affected members (about 10K of our 130K members) which will be too much to do manually. Thanks! |
Anyone? Help? Please??
|
I don't know how to do it in SQL, but you could use this script:
PHP Code:
Next, create a new php file (like maybe removegroup.php) and put in the above code. Then change this line PHP Code:
to change X to the group id your want to remove. Then run the script (go to it with your browser). When you're done you'll probably want to remove it. BTW, this code comes from admincp/usergroup.php where it's used to remove users from a group when the group is being deleted. |
I was just about to start a script to do this but kh99 beat me to it.
One thing I would suggest is place that entire script inside a conditional so it runs for the admin only and then it can be a plugin in showthread start PHP Code:
|
Quote:
|
Thanks for the replies - not exactly what I was looking for and will have to discuss with the other SysAdmin who is a little more well-versed than I am with MySQL.
|
I have not tested this but you can try:
Code:
UPDATE user SET membergroupids = REPLACE(membergroupids,'2',''); Update all users, set their member group id (secondary usergroup) to "Blank" or '' where it currently is 2 i.e. Registered User/Member. Now go through and do this for all the secondary usergroups listed in the usergroup manager so if you have a custom usergroup none of us have lets call it Main VIP which is usergroupid #29 you simply use this now: Code:
UPDATE user SET membergroupids = REPLACE(membergroupids,'29',''); Edit: Ahh I had to install a staging site on my localhost tonight regardless so tested and it works ;). |
I'm not clear on something: Is "Email Verification" a custom usergroup or do you mean "Users Awaiting Email Confirmation" (group 3)? Are several usergroups duplicated in secondary usergroups?
|
Quote:
Also, I believe he only wanted to remove on secondary user group, where it duplicates the primary group. |
Quote:
|
Quote:
|
I think you would need
REPLACE(REPLACE(membergroupids, '2,', ''), ',2', '' ) First it gets rid of 2 everywhere but at the end, then catches it at the end. |
Yeah, I think that works. But you need a third REPLACE in case the field is only "2".
Pretty cool. |
Code:
REPLACE( |
You know, I just thought of something (and this applies to TheLastSuperman's solution as well) - you can't just replace all 2's because someone could have a usergroup 12, or 20 something. I think you'd need a regular expression to match ^2, and ,2$ and well as ,2,.
Edit: I guess what I should say is that I think it will work for a one-time removal of some secondary groups if there's no conflict as is mentioned above. For instance if you want to remove secondary group 9 and you have less than 19 usegroups, it'll work fine. |
If I were doing this I would select a batch and loop through it using php to manipulate the strings and then update one at a time in the loop. It would be slow but I'd rather have slow and predictable than fast and unpredictable. You could also check what's going on before running it with the update query and be sure you aren't messing up. If the whole process takes an hour to run, so be it.
--------------- Added [DATE]1321890191[/DATE] at [TIME]1321890191[/TIME] --------------- First I would use a SELECT That uses LIKE to match the membergroupid. I would use this php in a loop. If everything looks OK then replace the echo with an update PHP Code:
Here's the first thing I would do. Use this for a plugin in showthread_start. All it does is check that the string manipulation is working exactly as it should. You should have a white page with 10 lines each showing user name, primary usergroup, original secondary usergoup string and finally the modified secondary user group string. Edit in your userid in the first line where it says '1' PHP Code:
|
All times are GMT. The time now is 07:04 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|