Import data from Phorum


(František Zatloukal) #1

Hi,
I am trying to import data from Phorum database. I have filled db data to the phorum.rb script (mysql name, pass, db name) and tried to run the script with: ruby script/import_scripts/phorum.rb

but it failed with this error:

/var/discourse/script/import_scripts/base.rb:14:in `require_relative': cannot load such file --
/var/discourse/config/environment (LoadError)
from /var/discourse/script/import_scripts/base.rb:14:in `<top (required)>'
from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
from script/import_scripts/phorum.rb:3:in `<main>'

Have you any idea what am I doing wrong?

Thanks so much!


(RĂ©gis Hanol) #2

Have you installed the mysql2 gem? It’s not in our Gemfile since we use postgresql. You can install with gem install mysql2.


(František Zatloukal) #3

Yup, I have installed that (it was first thing I have done, import script showed different error and it was clear that mysql2 was missing).


(RĂ©gis Hanol) #4

Ok, pinging @techAPJ since he wrote it. He might be able to help you out.


(Arpit Jalan) #5

Are you running the import script on production server? If yes, can you confirm you’re running import script like this:

RAILS_ENV=production bundle exec ruby script/import_scripts/phorum.rb

(František Zatloukal) #6

I am not sure if it’s production server (I’ve followed Discourse installation guide here) and if I try to run command you’ve mentioned it ends with: Could not locate Gemfile (even if I try it from directory with phorum.rb).


(František Zatloukal) #7

Hey @techAPJ , sorry for pinging you. I’d be happy if you could point at what I am doing wrong. Thank you very much!


(Gerhard Schlager) #8

Looks like you’re trying to run the importer inside the Docker container. This should work:

cd /var/www/discourse
su discourse -c 'bundle exec ruby script/import_scripts/phorum.rb'

(František Zatloukal) #9

No, the result is same:
Could not locate Gemfile

Command to start was: su root -c 'bundle exec ruby script/import_scripts/phorum.rb' from /var/discourse. I have Vagrantfile there but really no Gemfile.


(Gerhard Schlager) #10

Did you delete the Gemfile? Try running

cd /var/www/discourse
git reset HEAD --hard

or recreate your Docker container.


(František Zatloukal) #11

I tried:
git reset HEAD --hard
git pull
./launcher rebuild app
bundle exec ruby script/import_scripts/phorum.rb as root

Still no Gemfile. I forgot to mention that I always have to modify launcher, because it detects uppercase characters, spaces or special characters in app, so I just comment out exit 1 line.


(František Zatloukal) #12

Ok, some progress at least. I’ve manually downloaded Gemfile and did bundle install but right now it’s ending because of:
script/import_scripts/phorum.rb:1:inrequire’: cannot load such file – mysql2`

(even if mysql2 gem is installed)


(Gerhard Schlager) #13

You need to enter the Docker container:

./launcher enter app

Then install the mysql2 gem…

apt-get update && apt-get install -y nano libmysqlclient-dev
cd /var/www/discourse
echo "gem 'mysql2'" >> Gemfile
su discourse -c 'bundle install --no-deployment --without test --without development --path vendor/bundle'

… configure the import script

nano script/import_scripts/phorum.rb

and execute the importer

su discourse -c 'bundle exec ruby script/import_scripts/phorum.rb'

(František Zatloukal) #14

It ended with:

/var/discourse/script/import_scripts/base.rb:14:in `require_relative': cannot load such file -- /var/discourse/config/environment (LoadError)
    from /var/discourse/script/import_scripts/base.rb:14:in `<top (required)>'
    from script/import_scripts/phorum.rb:3:in `require'
    from script/import_scripts/phorum.rb:3:in `<main>'

If I compare directories on github and in /var/discourse I have missing a lot of them (I don’t know how that’s possible). Shouldn’t I try to remove entire /var/discourse and download it again?


(RĂ©gis Hanol) #15

Sincerely, it would be much easier for you to set up a development environment and run the import there rather than in a production server.


(František Zatloukal) #16

I finally managed to find time to set up development installation and import worked perfectly.

Thanks!