flush(); $group_perms = phorum_convert_getUserGroups($oldlink); $res = phorum_convert_selectUsers($oldlink); if (!$res) { echo "No users found, All done now.{$CONVERT['lbr']}"; flush(); exit; } // there are users... $count = 0; $userdata["date_added"] = time(); $cur_time = time(); while ($cur_user = phorum_convert_getNextUser($res)) { if (isset($cur_user['user_id'])) { phorum_api_user_save($cur_user, PHORUM_FLAG_RAW_PASSWORD); $user_groups = array(); if (isset($group_perms[$cur_user['user_id']])) { $user_groups = $group_perms[$cur_user['user_id']]; } if (count($user_groups)) { // setting the user's group-memberships phorum_db_user_save_groups($cur_user['user_id'], $user_groups); } $count++; } } unset($users); print "{$count} users converted{$CONVERT['lbr']}"; } echo "{$CONVERT['lbr']}Done.{$CONVERT['lbr']}"; flush();
/** * Save the groups and group permissions for a user. * * @param integer $user_id * The user_id of the user for which to store the group permissions. * * @param array $groups * An array of groups and their permissions. The keys in this array are * group ids. The values are either group permission values or arrays * containing at least the key "user_status" (which has the group * permission as its value) in them. The group permission value must be * one of the PHORUM_USER_GROUP_* constants. */ function phorum_api_user_save_groups($user_id, $groups) { if (!empty($GLOBALS["PHORUM"]['cache_users'])) { phorum_cache_remove('user', $user_id); } $dbgroups = array(); foreach ($groups as $id => $perm) { if (is_array($perm) && isset($perm['user_status'])) { $perm = $perm['user_status']; } if ($perm != PHORUM_USER_GROUP_SUSPENDED && $perm != PHORUM_USER_GROUP_UNAPPROVED && $perm != PHORUM_USER_GROUP_APPROVED && $perm != PHORUM_USER_GROUP_MODERATOR) { trigger_error('phorum_api_user_save_groups(): Illegal group permission for ' . 'group id ' . htmlspecialchars($id) . ': ' . htmlspecialchars($perm), E_USER_ERROR); return NULL; } $dbgroups[$id] = $perm; } return phorum_db_user_save_groups($user_id, $dbgroups); }
/** * Save the groups and group permissions for a user. * * @param integer $user_id * The user_id of the user for which to store the group permissions. * * @param array $groups * An array of groups and their permissions. The keys in this array are * group ids. The values are either group permission values or arrays * containing at least the key "user_status" (which has the group * permission as its value) in them. The group permission value must be * one of the PHORUM_USER_GROUP_* constants. */ function phorum_api_user_save_groups($user_id, $groups) { if (!empty($GLOBALS["PHORUM"]['cache_users'])) { phorum_cache_remove('user', $user_id); } $dbgroups = array(); foreach ($groups as $id => $perm) { if (is_array($perm) && isset($perm['user_status'])) { $perm = $perm['user_status']; } if ($perm != PHORUM_USER_GROUP_SUSPENDED && $perm != PHORUM_USER_GROUP_UNAPPROVED && $perm != PHORUM_USER_GROUP_APPROVED && $perm != PHORUM_USER_GROUP_MODERATOR) { trigger_error('phorum_api_user_save_groups(): Illegal group permission for ' . 'group id ' . htmlspecialchars($id) . ': ' . htmlspecialchars($perm), E_USER_ERROR); return NULL; } $dbgroups[$id] = $perm; } /** * [hook] * user_save_groups * * [description] * This hook can be used to handle the groups data that is going to be * stored in the database for a user. Modules can do some last * minute change on the data or keep some external system in sync * with the Phorum user data. * * [category] * User data handling * * [when] * Just before the groups for a user are stored in the database. * * [input] * An array containing user_id and groups-data as another array. * * [output] * The same array as the one that was used for the hook call * argument, possibly with some updated fields in it. * * [example] * <hookcode> * function phorum_mod_foo_user_save_groups($data) * { * list($user_id,$groups) = $data; * foreach($groups as $group_id => $group_permission) { * // do something with the groups permissions * } * * return array($user_id,$groups); * } * </hookcode> */ if (isset($GLOBALS['PHORUM']['hooks']['user_save_groups'])) { list($user_id, $dbgroups) = phorum_hook('user_save_groups', array($user_id, $dbgroups)); } return phorum_db_user_save_groups($user_id, $dbgroups); }
/** * phorum_user_save_groups() * * This function saves a users group permissions. The data * to save should be an array of the form array[group_id] = permission * @param int - the users user_id * @param array - group permissions to save * @return bool - true if successful */ function phorum_user_save_groups($user_id, $groups) { if(isset($GLOBALS["PHORUM"]['cache_users']) && $GLOBALS["PHORUM"]['cache_users']) { phorum_cache_remove('user',$user_id); } return phorum_db_user_save_groups($user_id, $groups); }