Subsubcategories after import


(Judith Meyer) #1

We have a phpbb forum with 3 levels and tens of thousands of users evenly spread all over Europe. The top level is for the type of discussion, e.g. announcements, policy discussion, events, local meetups or volunteering. Within local meetups, we originally only had drill-down by country, but some countries got so active that it was necessary to create subforums per region, e.g. Find Local Members > Germany > Bavaria

After importing, all the region forums have been placed on the same level as the countries. That is annoying. Even more annoying is that there doesn’t seem to be a way to fix it. Solutions in order of preference:

  1. Enable 3 levels (maybe through a plugin?). If it matters, the topics within regional forums do not have to be shown on the front page because they tend to be very local; also many of the topic titles in the regional forums are simply variations on “Hi” or “Let’s meet”. The regional forums also shouldn’t be shown on the categories page, just displaying two levels is enough and in fact preferred.

  2. Move all topics from the regional forums up into the national forums, and use tags to identify regions. This would have to be done automatically or semi-automatically because of the sheer number of posts involved. I am a Rails coder and could execute commands in the Rails console for Discourse if someone can tell me how to achieve this.

  3. Only if unavoidable: move all topics up into the national forums and don’t apply tags. The sad thing is that even this option and even with lots of manpower seems out of reach because I have yet to see a per-forum “move all topics” function like phpbb has.

Please advise!


(Michael - DiscourseHosting.com) #2

4 fold the names: call them “Germany - Bavaria” and “Germany - Nordrhein Westfalen”


(Neil Lalonde) #3

This is the solution that the Vanilla bulk importer uses. It should be possible to take the same approach in the PHPBB importer.


(Judith Meyer) #4

So after reviewing Neil’s code and some other topics, I came up with the following code for fixing the botched import by

  1. creating/adding appropriate tags for each forum that used to be regional
  2. moving the regional topics into the national forum
  3. deleting the regional forum

I hope that someone will update the phpbb importer though! Or simply support more depth…

This is a huge change; take a backup before running!

Note: if you don’t plan to delete the subforums you may need to fiddle with the code some more, because Discourse told me the subforum couldn’t be deleted through the admin interface because it had topics in it - which it didn’t. So something probably needs to be updated there if you plan to keep using the subforums. I don’t.

First, ensure that the national subforum is in a variable called new_category and the regional subsubforums are in a variable called old_categories. The easiest way:

new_category = Category.select('id, name').find_by(slug: 'italy')
slugs = %w(basilicata calabria campania emilia-romagna friuli-venezia-giulia lazio liguria lombardia marche molise piemonte puglia sardegna sicilia toscana trentino-alto-adige umbria valle-daosta veneto)
old_categories = Category.where(slug: slugs); nil

If using this code, ensure that all your slugs actually yielded a valid category, i.e. slugs.count == old_categories.count .

Then, run this reusable function:

def fix_subsubcategories(old_categories, new_category)
  old_categories.each do |old_category|
    tag_name = DiscourseTagging.clean_tag(old_category.name)
    tag = Tag.find_by_name(tag_name) || Tag.create(name: tag_name)

    Topic.where(category: old_category).each do |topic|
      if topic.tags.exclude?(tag)
        topic.tags << tag
      end
    end
    Topic.where(category_id: old_category.id).update_all(category_id: new_category.id)
    old_category.destroy
  end
end

(Judith Meyer) #5

The problem after running this for all regions is that now the Germany forum for example looks like this:

All these sticky posts are collecting meeting times of local groups on a per-region basis - in order to avoid spamming the forum by having each group open a new topic for their meetings, and enable visitors to quickly identify the upcoming meetups near them. I will suggest Discourse to our members but they may vote to stick to phpbb after all.

@michaeld Folding the names would yield a really unwieldy front page, because we have 5 countries with 15-20 regions each, plus 22 countries where activity is not high enough to split into regions. The whole point of subsubcategories is to NOT display them until users actually drill down. If I’m not in Portugal then I certainly don’t care about meetups in Leiria…

EDIT: I wonder if it would be possible to prominently feature all of the subcategory’s tags on a subcategory page. That might enable people to drill down to topics concerning their region.


(Kane York) #6

One solution is to have a single pinned topic that acts as a directory / index for the per-region meeting notes topics.