Migrate a vBulletin 4 forum to Discourse

Hi. Just want to share my solution.
As for the problems with quotes. As I said before, i’m was facing with problems - regexp not capture quotes then:

  • username and post id may be enclosed in double quotes
  • nested quotes

I decided to do a search and replace using a different logic. Instead of searching for tags and their contents, I used a regular expression that searches only for tags:

was:
raw.gsub!(%r{\[quote="?([^;]+);(\d+)"?\](.+?)\[\/quote\]}im) do

became:
raw.gsub!(%r{(\[QUOTE(="?([^;]+);(\d+)"?)?\])|(\[\/QUOTE\])}im) do

and then little change the determining the source of a quote:

      if $3 && $4
        if topic_lookup = topic_lookup_from_imported_post_id(post_id)
          post_number = topic_lookup[:post_number]
          topic_id = topic_lookup[:topic_id]
          "\n[quote=\"#{new_username},post:#{post_number},topic:#{topic_id}\"]\n"
        else
          "\n[quote=\"#{new_username}\"]\n"
        end
      elsif $5
        "\n[/quote]\n"        
      end

Also, I change the spoiler’s code. Instead of:

    # [spoiler=Some hidden stuff]SPOILER HERE!![/spoiler]
    raw.gsub!(%r{\[spoiler="?(.+?)"?\](.+?)\[/spoiler\]}im) do
      "\n#{$1}\n[spoiler]#{$2}[/spoiler]\n"
    end

that blured text, I convert it to details tag:

    raw.gsub!(%r{(\[spoiler(="?(.*?)"?)?\])|(\[\/spoiler\])}im) do
      if $3
        "\n[details=#{$3}]\n"
      elsif $1
        "\n[details]\n"
      elsif $4
        "\n[/details]\n"
      end
    end

Because it just so happens that in the vbulletin world - sploiler it is not the blurred content, but rather the collapsed content. So I think it is much more appropriate for the vbulletin import script to convert spoilers to details instead of the blurred spoiler.

I also noticed the mention tag. In my case, in vbulletin, the mentions looked like this:
[mention=XXX]username[/mention]

The regular expression used in the script does not take into account that the tag may contain the user id.

    # [MENTION]<username>[/MENTION]
    raw.gsub!(%r{\[mention\](.+?)\[/mention\]}i) do
      new_username = get_username_for_old_username($1)
      "@#{new_username}"
    end

I fixed this in my own way too:

    # [MENTION]<username>[/MENTION]
    raw.gsub!(%r{\[mention(=\d+)?\](.+?)\[/mention\]}i) do
      new_username = get_username_for_old_username($2)
      "@#{new_username}"
    end
1 Like