mirror of
https://github.com/discourse/discourse.git
synced 2025-04-16 20:59:06 +08:00
VANILLA: use latest activity as user's profile by default
This commit is contained in:
parent
86fcc72546
commit
6ca4983463
@ -53,7 +53,7 @@ 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 ["activities", "user_meta"].include? table
|
next if ["user_meta"].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 }
|
||||||
@ -73,18 +73,25 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def import_users
|
def import_users
|
||||||
|
puts "", "importing users..."
|
||||||
|
|
||||||
admin_role_id = @roles.select { |r| r[:name] == "Administrator" }.first[:role_id]
|
admin_role_id = @roles.select { |r| r[:name] == "Administrator" }.first[:role_id]
|
||||||
moderator_role_id = @roles.select { |r| r[:name] == "Moderator" }.first[:role_id]
|
moderator_role_id = @roles.select { |r| r[:name] == "Moderator" }.first[:role_id]
|
||||||
|
|
||||||
|
activities = @activities.reject { |a| a[:activity_user_id] != a[:regarding_user_id] }
|
||||||
|
|
||||||
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
|
||||||
|
bio_raw = last_activity.try(:[], :story) || user[:discovery_text] || ""
|
||||||
|
|
||||||
u = {
|
u = {
|
||||||
id: user[:user_id],
|
id: user[:user_id],
|
||||||
email: user[:email],
|
email: user[:email],
|
||||||
name: user[:name],
|
name: user[:name],
|
||||||
created_at: parse_date(user[:date_inserted]),
|
created_at: parse_date(user[:date_inserted]),
|
||||||
bio_raw: clean_up(user[:discovery_text]),
|
bio_raw: clean_up(bio_raw),
|
||||||
avatar_url: user[:photo],
|
avatar_url: user[:photo],
|
||||||
moderator: @user_roles.select { |ur| ur[:user_id] == user[:user_id] }.map { |ur| ur[:role_id] }.include?(moderator_role_id),
|
moderator: @user_roles.select { |ur| ur[:user_id] == user[:user_id] }.map { |ur| ur[:role_id] }.include?(moderator_role_id),
|
||||||
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),
|
||||||
@ -99,6 +106,8 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def import_categories
|
def import_categories
|
||||||
|
puts "", "importing categories..."
|
||||||
|
|
||||||
# save some information about the root category
|
# save some information about the root category
|
||||||
@root_category = @categories.select { |c| c[:category_id] == "-1" }.first
|
@root_category = @categories.select { |c| c[:category_id] == "-1" }.first
|
||||||
@root_category_created_at = parse_date(@root_category[:date_inserted])
|
@root_category_created_at = parse_date(@root_category[:date_inserted])
|
||||||
@ -229,12 +238,15 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clean_up(raw)
|
def clean_up(raw)
|
||||||
(raw || "").gsub("\\n", "\n")
|
return "" if raw.blank?
|
||||||
.gsub(/<\/?pre\s*>/i, "\n```\n")
|
raw.gsub("\\n", "\n")
|
||||||
.gsub(/<\/?code\s*>/i, "`")
|
.gsub(/<\/?pre\s*>/i, "\n```\n")
|
||||||
.gsub("<", "<")
|
.gsub(/<\/?code\s*>/i, "`")
|
||||||
.gsub(">", ">")
|
.gsub("<", "<")
|
||||||
# .gsub("*", "\\*")
|
.gsub(">", ">")
|
||||||
|
# .gsub(/`([^`]+)`/im) { "`" + $1.gsub("*", "\u2603") + "`" }
|
||||||
|
# .gsub("*", "\*")
|
||||||
|
# .gsub("\u2603", "*")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user