Bulk add users to group
Permalink 1 user found helpful
I need to add several hundred users to a specific group - any way to do this without having to click into each user and manually add them to the new group?
I had a similar issue today and thought I would post to help others searching the forums and expand on guythomas' post.
I needed to import all unassigned users to a specific group. I found out the usergroup id (uID) from the Groups table and then ran the following insert SQL query:
Please note the field 'ugEntered' is hardcoded date. You may want to set this to today's date to keep things accurate. Type was blank for all other records so I added a blank value i.e. ''
I needed to import all unassigned users to a specific group. I found out the usergroup id (uID) from the Groups table and then ran the following insert SQL query:
Insert into `UserGroups` (uID, gID, ugEntered, type) SELECT uID, 4, '2011-01-26 23:57:12', '' FROM `Users` WHERE `Users`.`uID` != 1 AND `Users`.`uID` != 2 AND `Users`.`uID` != 5 AND `Users`.`uID` NOT IN (SELECT `uID` FROM (`UserGroups`))
Please note the field 'ugEntered' is hardcoded date. You may want to set this to today's date to keep things accurate. Type was blank for all other records so I added a blank value i.e. ''
Just wanted to let anyone looking for a way to bulk remove users from a group, doing it through mysql is also pretty painless. Here's the statement I used to remove a hundred or so users from a particular group:
Make sure you backup your database before you execute any of these statements just in case.
DELETE FROM UserGroups WHERE gID = 23 AND uID IN (510,509,507,499,498,494,493,492,489,483,481,457,427,420,419,408,402,399,395,391,384,383,377,368,350,345,341,337,336,335,333,330,319,316,315,313,307,304,301,300,297,293,278,275,274,272,271,270,269,265,262,258,253,248,246,241,229,219,211,210,202,200,199,195,193,189,188,187,185,184,182,179,177,173,171,170,162,159,155,146,143,138,136,128,125,121,111,98,94,88,87,85,73,60,57,50,48,45,40,33,32,14);
Make sure you backup your database before you execute any of these statements just in case.
Access your database with phpMyAdmin (should be installed by your host already). Within the Concrete5 database there are three tables that handle this info.
Table #1 is titled "Users" . This lists all your users. You need to take note of their "uID"
Table #2 is titled "Groups". This lists all of your groups. Take note of the "gID" of the group you want to add these users to.
Finally, the table that makes it all happen is the "UserGroups" table This table contains entries assign various users "uID" to various Groups "gID".
You can add records to this table with the INSERT statement, for instance..
The above statement would put users 101-103 into group 5.
I know it isn't the easiest, but it may save you some time over doing it through the dashboard.