mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
add env variables for vBulletin import script
This commit is contained in:

committed by
Arpit Jalan

parent
0f2de4863b
commit
3a5c0c5605
@ -1,16 +1,35 @@
|
|||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/base.rb")
|
require File.expand_path(File.dirname(__FILE__) + "/base.rb")
|
||||||
require 'htmlentities'
|
require 'htmlentities'
|
||||||
require 'php_serialize' # https://github.com/jqr/php-serialize
|
begin
|
||||||
|
require 'php_serialize' # https://github.com/jqr/php-serialize
|
||||||
|
rescue LoadError
|
||||||
|
puts
|
||||||
|
puts 'php_serialize not found.'
|
||||||
|
puts 'Add to Gemfile, like this: '
|
||||||
|
puts
|
||||||
|
puts "echo gem \\'php-serialize\\' >> Gemfile"
|
||||||
|
puts "bundle install"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
# See https://meta.discourse.org/t/importing-from-vbulletin-4/54881
|
||||||
|
# Please update there if substantive changes are made!
|
||||||
|
|
||||||
class ImportScripts::VBulletin < ImportScripts::Base
|
class ImportScripts::VBulletin < ImportScripts::Base
|
||||||
BATCH_SIZE = 1000
|
BATCH_SIZE = 1000
|
||||||
|
|
||||||
# CHANGE THESE BEFORE RUNNING THE IMPORTER
|
# CHANGE THESE BEFORE RUNNING THE IMPORTER
|
||||||
DATABASE = "q23"
|
|
||||||
TABLE_PREFIX = "vb_"
|
DB_HOST ||= ENV['DB_HOST'] || "localhost"
|
||||||
TIMEZONE = "America/Los_Angeles"
|
DB_NAME ||= ENV['DB_NAME'] || "vbulletin"
|
||||||
ATTACHMENT_DIR = '/path/to/your/attachment/folder'
|
DB_PW ||= ENV['DB_PW'] || ""
|
||||||
|
DB_USER ||= ENV['DB_USER'] || "root"
|
||||||
|
TIMEZONE ||= ENV['TIMEZONE'] || "America/Los_Angeles"
|
||||||
|
TABLE_PREFIX ||= ENV['TABLE_PREFIX'] || "vb_"
|
||||||
|
ATTACHMENT_DIR ||= ENV['ATTACHMENT_DIR'] || '/path/to/your/attachment/folder'
|
||||||
|
|
||||||
|
puts "#{DB_USER}:#{DB_PW}@#{DB_HOST} wants #{DB_NAME}"
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
@ -22,12 +41,37 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
|||||||
@htmlentities = HTMLEntities.new
|
@htmlentities = HTMLEntities.new
|
||||||
|
|
||||||
@client = Mysql2::Client.new(
|
@client = Mysql2::Client.new(
|
||||||
host: "localhost",
|
host: DB_HOST,
|
||||||
username: "root",
|
username: DB_USER,
|
||||||
database: DATABASE
|
password: DB_PW,
|
||||||
|
database: DB_NAME
|
||||||
)
|
)
|
||||||
|
rescue Exception => e
|
||||||
|
puts '='*50
|
||||||
|
puts e.message
|
||||||
|
puts <<EOM
|
||||||
|
Cannot connect in to database.
|
||||||
|
|
||||||
|
Hostname: #{DB_HOST}
|
||||||
|
Username: #{DB_USER}
|
||||||
|
Password: #{DB_PW}
|
||||||
|
database: #{DB_NAME}
|
||||||
|
|
||||||
|
Edit the script or set these environment variables:
|
||||||
|
|
||||||
|
export DB_HOST="localhost"
|
||||||
|
export DB_NAME="vbulletin"
|
||||||
|
export DB_PW=""
|
||||||
|
export DB_USER="root"
|
||||||
|
export TABLE_PREFIX="vb_"
|
||||||
|
export ATTACHMENT_DIR '/path/to/your/attachment/folder'
|
||||||
|
|
||||||
|
Exiting.
|
||||||
|
EOM
|
||||||
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
import_groups
|
import_groups
|
||||||
import_users
|
import_users
|
||||||
@ -141,6 +185,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
|||||||
picture = query.first
|
picture = query.first
|
||||||
|
|
||||||
return if picture.nil?
|
return if picture.nil?
|
||||||
|
return if picture["filedata"].nil?
|
||||||
|
|
||||||
file = Tempfile.new("profile-picture")
|
file = Tempfile.new("profile-picture")
|
||||||
file.write(picture["filedata"].encode("ASCII-8BIT").force_encoding("UTF-8"))
|
file.write(picture["filedata"].encode("ASCII-8BIT").force_encoding("UTF-8"))
|
||||||
@ -170,6 +215,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
|||||||
background = query.first
|
background = query.first
|
||||||
|
|
||||||
return if background.nil?
|
return if background.nil?
|
||||||
|
return if background["filedata"].nil?
|
||||||
|
|
||||||
file = Tempfile.new("profile-background")
|
file = Tempfile.new("profile-background")
|
||||||
file.write(background["filedata"].encode("ASCII-8BIT").force_encoding("UTF-8"))
|
file.write(background["filedata"].encode("ASCII-8BIT").force_encoding("UTF-8"))
|
||||||
|
Reference in New Issue
Block a user