mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: Kunena import script no longer requires a csv file with Joomla user records. MySQL is used for all data.
This commit is contained in:
parent
9062719480
commit
cd74829d55
1 changed files with 9 additions and 31 deletions
|
@ -1,25 +1,14 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/base.rb")
|
require File.expand_path(File.dirname(__FILE__) + "/base.rb")
|
||||||
|
|
||||||
require "mysql2"
|
require "mysql2"
|
||||||
require "csv"
|
|
||||||
|
|
||||||
# TODO
|
|
||||||
#
|
|
||||||
# It would be better to have a mysql dump of the joomla users too.
|
|
||||||
# But I got a csv file and had an awful time trying to use the LOAD DATA command to put it into a table.
|
|
||||||
# So, this script reads Joomla users from a csv file for now.
|
|
||||||
|
|
||||||
class ImportScripts::Kunena < ImportScripts::Base
|
class ImportScripts::Kunena < ImportScripts::Base
|
||||||
|
|
||||||
KUNENA_DB = "kunena"
|
KUNENA_DB = "kunena"
|
||||||
JOOMLA_USERS = "j-users.csv"
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
|
||||||
@joomla_users_file = ARGV[0]
|
|
||||||
raise ArgumentError.new('Joomla users file argument missing. Provide full path to joomla users csv file.') if !@joomla_users_file.present?
|
|
||||||
|
|
||||||
@users = {}
|
@users = {}
|
||||||
|
|
||||||
@client = Mysql2::Client.new(
|
@client = Mysql2::Client.new(
|
||||||
|
@ -31,8 +20,6 @@ class ImportScripts::Kunena < ImportScripts::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
check_files_exist
|
|
||||||
|
|
||||||
parse_users
|
parse_users
|
||||||
|
|
||||||
puts "creating users"
|
puts "creating users"
|
||||||
|
@ -49,6 +36,8 @@ class ImportScripts::Kunena < ImportScripts::Base
|
||||||
suspended_till: user[:suspended] ? 100.years.from_now : nil }
|
suspended_till: user[:suspended] ? 100.years.from_now : nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@users = nil
|
||||||
|
|
||||||
create_categories(@client.query("SELECT id, parent, name, description, ordering FROM jos_kunena_categories ORDER BY parent, id;")) do |c|
|
create_categories(@client.query("SELECT id, parent, name, description, ordering FROM jos_kunena_categories ORDER BY parent, id;")) do |c|
|
||||||
h = {id: c['id'], name: c['name'], description: c['description'], position: c['ordering'].to_i}
|
h = {id: c['id'], name: c['name'], description: c['description'], position: c['ordering'].to_i}
|
||||||
if c['parent'].to_i > 0
|
if c['parent'].to_i > 0
|
||||||
|
@ -68,32 +57,21 @@ class ImportScripts::Kunena < ImportScripts::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_files_exist
|
|
||||||
raise ArgumentError.new("File does not exist: #{@joomla_users_file}") unless File.exist?(@joomla_users_file)
|
|
||||||
end
|
|
||||||
|
|
||||||
def read_csv(f)
|
|
||||||
data = File.read(f)
|
|
||||||
data.gsub!(/\" \n/,"\"\n")
|
|
||||||
data.gsub!(/\\\"/,";;")
|
|
||||||
data.gsub!(/\\/,"\n")
|
|
||||||
data
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_users
|
def parse_users
|
||||||
# Need to merge data from joomla with kunena
|
# Need to merge data from joomla with kunena
|
||||||
|
|
||||||
puts "parsing joomla user data from #{@joomla_users_file}"
|
puts "fetching Joomla users data from mysql"
|
||||||
CSV.foreach(@joomla_users_file) do |u|
|
results = @client.query("SELECT id, username, email, registerDate FROM jos_users;", cache_rows: false)
|
||||||
next unless u[0].to_i > 0 and u[1].present? and u[2].present?
|
results.each do |u|
|
||||||
username = u[1].gsub(' ', '_').gsub(/[^A-Za-z0-9_]/, '')[0,User.username_length.end]
|
next unless u['id'].to_i > 0 and u['username'].present? and u['email'].present?
|
||||||
|
username = u['username'].gsub(' ', '_').gsub(/[^A-Za-z0-9_]/, '')[0,User.username_length.end]
|
||||||
if username.length < User.username_length.first
|
if username.length < User.username_length.first
|
||||||
username = username * User.username_length.first
|
username = username * User.username_length.first
|
||||||
end
|
end
|
||||||
@users[u[0].to_i] = {id: u[0].to_i, username: username, email: u[2], created_at: Time.zone.parse(u[3])}
|
@users[u['id'].to_i] = {id: u['id'].to_i, username: username, email: u['email'], created_at: u['registerDate']}
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "parsing kunena user data from mysql"
|
puts "fetching Kunena user data from mysql"
|
||||||
results = @client.query("SELECT userid, signature, moderator, banned FROM jos_kunena_users;", cache_rows: false)
|
results = @client.query("SELECT userid, signature, moderator, banned FROM jos_kunena_users;", cache_rows: false)
|
||||||
results.each do |u|
|
results.each do |u|
|
||||||
next unless u['userid'].to_i > 0
|
next unless u['userid'].to_i > 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue