From 3a5c0c560520aa38d95dd254cd1c638389ff54f8 Mon Sep 17 00:00:00 2001 From: Jay Pfaffman Date: Tue, 31 Jan 2017 10:31:18 +0530 Subject: [PATCH] add env variables for vBulletin import script --- script/import_scripts/vbulletin.rb | 62 ++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/script/import_scripts/vbulletin.rb b/script/import_scripts/vbulletin.rb index 967a88bf714..232ad987d80 100644 --- a/script/import_scripts/vbulletin.rb +++ b/script/import_scripts/vbulletin.rb @@ -1,16 +1,35 @@ require 'mysql2' require File.expand_path(File.dirname(__FILE__) + "/base.rb") 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 BATCH_SIZE = 1000 # CHANGE THESE BEFORE RUNNING THE IMPORTER - DATABASE = "q23" - TABLE_PREFIX = "vb_" - TIMEZONE = "America/Los_Angeles" - ATTACHMENT_DIR = '/path/to/your/attachment/folder' + + DB_HOST ||= ENV['DB_HOST'] || "localhost" + DB_NAME ||= ENV['DB_NAME'] || "vbulletin" + 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 super @@ -22,12 +41,37 @@ class ImportScripts::VBulletin < ImportScripts::Base @htmlentities = HTMLEntities.new @client = Mysql2::Client.new( - host: "localhost", - username: "root", - database: DATABASE + host: DB_HOST, + username: DB_USER, + password: DB_PW, + database: DB_NAME ) + rescue Exception => e + puts '='*50 + puts e.message + puts <