Importing phpBB group/forum permissions

I’ve been able to run the excellent import script for phpBB and get most of the content moved over with a few tweaks for our situation.

Thanks to @neil and everyone who had a hand in the script. I’ve made an addition to the script for placing the imported users into their respective groups also. I’ll add this to the official git and make a pr. Code at the end of message for review.

Has anyone had any luck with importing the phpBB3 group to forum permissions into Discourse as group to category permissions? I’m importing 123 forums so it’d be great if someone else had already knocked this out. I’ve searched meta but found nothing.

Importing user/group data:

def put_users_in_groups
   # group_id 4 and 5 are taken care of in import_users 

    puts '', "adding users to groups"
    progress_count = 0
    total_count = mysql_query("SELECT count(*) count
                                 FROM amazingc_forum.phpbb_user_group ug
                                join phpbb_groups g on g.group_id = ug.group_id
                                join phpbb_users u on u.user_id = ug.user_id
                                AND ug.group_id NOT IN (4,5);").first['count']

    batches(BATCH_SIZE) do |offset|
      results = mysql_query(
        "SELECT u.user_id, g.group_id
          FROM amazingc_forum.phpbb_user_group ug
          join phpbb_groups g on g.group_id = ug.group_id
          join phpbb_users u on u.user_id = ug.user_id
          AND ug.group_id NOT IN (4,5)
          order by user_id
          LIMIT #{BATCH_SIZE}
         OFFSET #{offset};")

      break if results.size < 1

      results.each do |users_group|
        begin
          current_user = find_user_by_import_id(users_group["user_id"])
          current_group = group_id_from_imported_group_id(users_group["group_id"])
          progress_count += 1
          print_status(progress_count, total_count)

          next if current_user.nil?
          next if current_group.nil?

          GroupUser.find_or_create_by(user: current_user, group_id: current_group)
        rescue SystemCallError => err
          puts "Couldnt add user to group: #{err.message}"
        end
      end
    end
  end
2 Likes

Looks great, @casey! I haven’t had to import category permissions yet, so haven’t done it.

Thanks @neil. I hope the code is helpful.

After doing a deep dive into the phpBB permissions scheme I realize that, at least to my understanding of it now, it would be near impossible to do a direct automatic translation of the permissions. As a new user to both phpBB and Discourse I didn’t know that phpBB allows negation of permissions while Discourse only allows additive permissions. I don’t have an opinion on which is better, just that they don’t jive.

Basically, in phpBB you can set all “Registered Users”, or everyone, to see a forum and then set “Group1” to have no permissions at all on the forum. While in Discourse you’d have to have a group for all users EXCEPT Group1 to accomplish the same.

1 Like

Maybe the importer can declare a subset of possible permission setups that it will allow, and make sure that the permissions are normalized into that form before importing?

@riking that would probably work for, at least, getting a beginning set of permissions in place. In our situation it would have been removing “everyone” from all categories and then mapping “See” “See / Reply”, “See / Reply / Create” to the relevant phpBB3 permissions and groups. Turns out this is basically what we wound up doing manually.

The latest version of the script imports groups.

2 Likes