Copying an entire usergroup to another usergroup

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Suggested Hosts
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
Smog
Registered User
Posts: 103
Joined: Sun May 13, 2007 8:06 am
Contact:

Copying an entire usergroup to another usergroup

Post by Smog »

phpBB v3

I need to copy all members of an usergroup (Pre-defined groups, Registered users) to another usergroup.

Any idea how to perform such mass action. member by member is not a good idea, xxxx members......

TIA,

Smog
Last edited by ameeck on Thu Dec 25, 2008 11:30 pm, edited 1 time in total.
Reason: Topic icon changed
ameeck
Former Team Member
Posts: 6559
Joined: Mon Mar 21, 2005 6:57 pm

Re: Copying an entire usergroup to another usergroup

Post by ameeck »

Why do you need to do this? Are you trying to achieve something else with this?
Smog
Registered User
Posts: 103
Joined: Sun May 13, 2007 8:06 am
Contact:

Re: Copying an entire usergroup to another usergroup

Post by Smog »

I have made a Newsletter Group, all existing registered members have to be be added to that group. Will be a so called "open group type". In that way, afterwards all members are able to make a choice for a stay in that new group, and unscribe/subscribe themself (join/resign selected procedure).
ameeck
Former Team Member
Posts: 6559
Joined: Mon Mar 21, 2005 6:57 pm

Re: Copying an entire usergroup to another usergroup

Post by ameeck »

You can choose wheter you want to recieve mass e-mails in your UCP.

UCP :: Board preferences :: Administrators can e-mail me information
Smog
Registered User
Posts: 103
Joined: Sun May 13, 2007 8:06 am
Contact:

Re: Copying an entire usergroup to another usergroup

Post by Smog »

I know. However not where I am looking for. For my board it is absolute necessary to have all newsletter subscribers in a separate user group. So remain the question: how-to perform such mass copy action?
ameeck
Former Team Member
Posts: 6559
Joined: Mon Mar 21, 2005 6:57 pm

Re: Copying an entire usergroup to another usergroup

Post by ameeck »

Here is a small script that should handle it, edit $group_id (registered users group ID) and $new_group_id (the newsletter group id), save it as add_group.php and upload to your website. Then run it through your browser, delete it after use.

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$group_id = 2;
$new_group_id = 7;
$user_array = array();

$sql = 'SELECT u.user_id FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug WHERE u.user_id = ug.user_id AND ug.group_id = ' . $group_id;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)){
    $user_array[] = $row['user_id'];
}
$db->sql_freeresult();
$result = group_user_add($new_group_id, $user_array);

if ($result === false)
{
    echo 'OK!';
}
else
{
    trigger_error($result, E_USER_ERROR);
}

?>
Smog
Registered User
Posts: 103
Joined: Sun May 13, 2007 8:06 am
Contact:

Re: Copying an entire usergroup to another usergroup

Post by Smog »

Well ameeck, i am deeply impressed by your fast support!

Your script performed exact the action i needed, no errors and a 1 second job. Txs a lot! :D

Happy Holidays, :)

Smog
stainless_steelrat
Registered User
Posts: 39
Joined: Mon Jun 19, 2006 5:17 pm

Re: Copying an entire usergroup to another usergroup

Post by stainless_steelrat »

I'm trying to "borrow" this to do an update for some users that I have... I've modified the where clause to include another field value on the users table, but when I run the add_user.php page, it just gives me a relatively generic error about "The requested user does not exist."

Code: Select all

ug WHERE u.user_contrib = 1 AND u.user_id = ug.user_id AND ug.group_id =
Never mind.... I found the source of the issue:

Code: Select all

ug WHERE u.user_contrib = "1" AND u.user_id = ug.user_id AND ug.group_id =
Needed quotes around the "1" to get it to work.... if you put '1' it closed the string improperly... and it wasn't reading the value without quotes around it.
Thanks....
Locked

Return to “[3.0.x] Support Forum”