Migrating a myBB forum to Discourse using Kubuntu in a VM

After spending way too many hours I thought I was close but then…

$ bundle exec ruby script/import_scripts/mybb.rb 
Loading existing groups...
Loading existing users...
Loading existing categories...
Loading existing posts...
Loading existing topics...

creating users
script/import_scripts/mybb.rb:96:in `block (3 levels) in import_users': undefined method `exists?' for File:Class (NoMethodError)

                  @uploader.create_avatar(newuser, filename) if File.exists?(filename)
Did you mean?  exist?

still no cigar :frowning:

1 Like

If I understand well, the method was deprecated then removed from current versions of Ruby:

The import script should be updated to reflect this change.

Maybe try replacing exists with exist without “s” here:


Ruby doc: https://ruby-doc.org/3.2.2/File.html#method-c-exist-3F

1 Like

Yeah - it’s been deprecated for ages before that. I’ll try to grep relevant occurrences out and change them but I need to take a break out of this lengthy and so far not highly rewarding exercise :wink:


$ bundle exec ruby script/import_scripts/mybb.rb
Loading existing groups...
Loading existing users...
Loading existing categories...
Loading existing posts...
Loading existing topics...
/home/silverdr/sources/discourse/lib/site_setting_extension.rb:444:in `get': No setting named 'email_domains_blacklist' exists (Discourse::InvalidParameters)

You can find the new name in site settings. I think it’s email_domains_blocklist

Thank you.

$ grep -R email_domains_blocklist ./

doesn’t return anything

$ grep -R email_domains_blacklist ./
./script/import_scripts/base.rb:      email_domains_blacklist: '',
./app/models/site_setting.rb:    email_domains_blacklist: "blocked_email_domains",

returns as above. Meaning it’s most probably blocked_email_domains. OTOH I noticed that in previous attempts I replaced the original script/import_scripts/base.rb with the gist based one linked to above by @Paul_King:

I restored the original one back and it seems to have gone through this time. Too good to be true. I/It must have missed something :wink: Going to find out now


Summing up the (much longer than this post) :wink: journey:

NOTE: I used a Kubuntu distribution running in virtual machine for the process so please have in mind that it may not be the same on different OS or even distribution

0. installing Discourse dev environment

Following this post and running this script linked to in the post using

`bash <(wget -qO- https://raw.githubusercontent.com/discourse/install-rails/master/linux)` 

as described there plus cloning the sources

git clone https://github.com/discourse/discourse.git ~/discourse

1. Preparing MySQL database

Get dump of the original mybb database as described on top of the thread:

$ mysqldump -u USER_NAME -p DATABASE_NAME > mybb_dump.sql

and copy/move it over to the newly set development environment.

Install MySQL server

$ sudo apt-get install mysql-server

Authentication for mysql changed in more recent versions. You have to be root on the host if you want to be root on mysql these days so

$ sudo mysql

instead of

$mysql -u root

Of course you have to be a “sudoer” (administrator) first

$ sudo mysql
mysql> CREATE DATABASE mybb;
mysql> CREATE USER 'nonrootuser'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON mybb.* TO 'nonrootuser'@'localhost';
mysql> quit
$ mysql -unonrootuser -ppassword mybb < mybb_dump.sql
<here you get warning about providing password on the command line not being a smart thing to do>

$ sudo mysql
mysql> USE mybb;
<here verify if all the tables are present - see the original post>

mysql> quit

2. Install Ruby gems

Checking the Gemfile in the current sources reveals that

$ echo "gem 'mysql2', require: false" >> Gemfile

is not really needed. It is enough to set the environment variable IMPORT to 1.
What is needed though are development files for MySQL clients, which is what the first line below is about

$ sudo apt-get install libmysqlclient-dev
$ cd ~/discourse
$ IMPORT=1 bundle install

2. Prepare Discourse (PostgreSQL database)

$ bundle exec rails db:drop
$ bundle exec rails db:create
$ bundle exec rails db:migrate
$ export DB_PW="password"
$ export DB_USER="nonrootuser"

3. Execute the actual import

The next line fixes a long deprecated and currently already removed method call in mybb.rb import script, which is still there at the time of writing and won’t change anything if this is already fixed

$ sed -i.original 's/File.exists?/File.exist?/' script/import_scripts/mybb.rb

Now check if Redis is still running. The Rails install script starts it but does not enable it as a permanent service so it doesn’t survive reboots, crashes, whatever, etc.

$ ps -aux |grep redis
silverdr    2808  0.3  0.3  89972 14512 ?        Ssl  05:25   2:04 redis-server *:6379

If you don’t see anything like the line above run

$ redis-server --daemonize yes

which is the very same command the above Rails installation script used the first time when installing.

Finally :pray: and

$ IMPORT=1 bundle exec ruby script/import_scripts/mybb.rb

If at this time the script didn’t stop with YAE (Yet Another Error) than it’s time to pop open that bottle :champagne:

A few things remain

  • OK - so the one obvious missing part are users’ passwords. Apparently, even though both applications store hash’n salt, judging by those hashes length “mybb” uses an older hashing algorithm. Therefore this is understandable and not a show-stopper. Everyone should be able to reset her password the first time.
  • Some bbcode stuff does not get converted. I have for example problem with code blocks, which have some tags around them setting monospaced Courier font and whatnot. I have no more stamina to try to automate this thing further. If you manage to do something about it please let me / us here know! :man_bowing:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.