mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: don't use latest activity as user's bio in vanilla import by default
This commit is contained in:
parent
10db8f21d7
commit
898ceb41e8
1 changed files with 11 additions and 10 deletions
|
@ -8,6 +8,8 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
||||||
|
|
||||||
@vanilla_file = ARGV[0]
|
@vanilla_file = ARGV[0]
|
||||||
raise ArgumentError.new('Vanilla file argument missing. Provide full path to vanilla csv file.') if @vanilla_file.blank?
|
raise ArgumentError.new('Vanilla file argument missing. Provide full path to vanilla csv file.') if @vanilla_file.blank?
|
||||||
|
|
||||||
|
@use_lastest_activity_as_user_bio = true if ARGV.include?('use-latest-activity-as-user-bio')
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
@ -53,7 +55,9 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
||||||
data << line.strip
|
data << line.strip
|
||||||
end
|
end
|
||||||
# PERF: don't parse useless tables
|
# PERF: don't parse useless tables
|
||||||
next if ["user_meta"].include? table
|
useless_tables = ["user_meta"]
|
||||||
|
useless_tables << "activities" unless @use_lastest_activity_as_user_bio
|
||||||
|
next if useless_tables.include?(table)
|
||||||
# parse the data
|
# parse the data
|
||||||
puts "parsing #{table}..."
|
puts "parsing #{table}..."
|
||||||
parsed_data = CSV.parse(data.join("\n"), headers: true, header_converters: :symbol).map { |row| row.to_hash }
|
parsed_data = CSV.parse(data.join("\n"), headers: true, header_converters: :symbol).map { |row| row.to_hash }
|
||||||
|
@ -83,8 +87,12 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
||||||
create_users(@users) do |user|
|
create_users(@users) do |user|
|
||||||
next if user[:name] == "[Deleted User]"
|
next if user[:name] == "[Deleted User]"
|
||||||
|
|
||||||
last_activity = activities.select { |a| user[:user_id] == a[:activity_user_id] }.last
|
if @use_lastest_activity_as_user_bio
|
||||||
bio_raw = last_activity.try(:[], :story) || ""
|
last_activity = activities.select { |a| user[:user_id] == a[:activity_user_id] }.last
|
||||||
|
bio_raw = last_activity.try(:[], :story) || ""
|
||||||
|
else
|
||||||
|
bio_raw = user[:discovery_text]
|
||||||
|
end
|
||||||
|
|
||||||
u = {
|
u = {
|
||||||
id: user[:user_id],
|
id: user[:user_id],
|
||||||
|
@ -97,10 +105,6 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
||||||
admin: @user_roles.select { |ur| ur[:user_id] == user[:user_id] }.map { |ur| ur[:role_id] }.include?(admin_role_id),
|
admin: @user_roles.select { |ur| ur[:user_id] == user[:user_id] }.map { |ur| ur[:role_id] }.include?(admin_role_id),
|
||||||
}
|
}
|
||||||
|
|
||||||
# if @comments.select { |c| c[:insert_user_id] == user[:user_id] }.map { |c| c[:discussion_id] }.uniq.count > 3
|
|
||||||
# u[:trust_level] = TrustLevel[2]
|
|
||||||
# end
|
|
||||||
|
|
||||||
u
|
u
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -244,9 +248,6 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
||||||
.gsub(/<\/?code\s*>/i, "`")
|
.gsub(/<\/?code\s*>/i, "`")
|
||||||
.gsub("<", "<")
|
.gsub("<", "<")
|
||||||
.gsub(">", ">")
|
.gsub(">", ">")
|
||||||
# .gsub(/`([^`]+)`/im) { "`" + $1.gsub("*", "\u2603") + "`" }
|
|
||||||
# .gsub("*", "\\*")
|
|
||||||
# .gsub("\u2603", "*")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue