fix Ning import script when resuming an import
This commit is contained in:
parent
20308ecfd9
commit
a064bad9a3
|
@ -21,6 +21,12 @@ class ImportScripts::Ning < ImportScripts::Base
|
||||||
#SiteSetting.max_image_size_kb = 3072
|
#SiteSetting.max_image_size_kb = 3072
|
||||||
#SiteSetting.max_attachment_size_kb = 1024
|
#SiteSetting.max_attachment_size_kb = 1024
|
||||||
SiteSetting.authorized_extensions = (SiteSetting.authorized_extensions.split("|") + EXTRA_AUTHORIZED_EXTENSIONS).uniq.join("|")
|
SiteSetting.authorized_extensions = (SiteSetting.authorized_extensions.split("|") + EXTRA_AUTHORIZED_EXTENSIONS).uniq.join("|")
|
||||||
|
|
||||||
|
# Example of importing a custom profile field:
|
||||||
|
# @interests_field = UserField.find_by_name("My interests")
|
||||||
|
# unless @interests_field
|
||||||
|
# @interests_field = UserField.create(name: "My interests", description: "Do you like stuff?", field_type: "text", editable: true, required: false, show_on_profile: true)
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
@ -65,6 +71,10 @@ class ImportScripts::Ning < ImportScripts::Base
|
||||||
avatar_url: u["profilePhoto"],
|
avatar_url: u["profilePhoto"],
|
||||||
bio_raw: u["profileQuestions"].is_a?(Hash) ? u["profileQuestions"]["About Me"] : nil,
|
bio_raw: u["profileQuestions"].is_a?(Hash) ? u["profileQuestions"]["About Me"] : nil,
|
||||||
post_create_action: proc do |newuser|
|
post_create_action: proc do |newuser|
|
||||||
|
# if u["profileQuestions"].is_a?(Hash)
|
||||||
|
# newuser.custom_fields = {"user_field_#{@interests_field.id}" => u["profileQuestions"]["My interests"]}
|
||||||
|
# end
|
||||||
|
|
||||||
if staff_levels.include?(u["level"].downcase)
|
if staff_levels.include?(u["level"].downcase)
|
||||||
if u["level"].downcase == "admin" || u["level"].downcase == "owner"
|
if u["level"].downcase == "admin" || u["level"].downcase == "owner"
|
||||||
newuser.admin = true
|
newuser.admin = true
|
||||||
|
@ -74,7 +84,7 @@ class ImportScripts::Ning < ImportScripts::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# states: ["active", "suspended", "left", "pending"]
|
# states: ["active", "suspended", "left", "pending"]
|
||||||
if u["state"] == "active"
|
if u["state"] == "active" && newuser.approved_at.nil?
|
||||||
newuser.approved = true
|
newuser.approved = true
|
||||||
newuser.approved_by_id = @system_user.id
|
newuser.approved_by_id = @system_user.id
|
||||||
newuser.approved_at = newuser.created_at
|
newuser.approved_at = newuser.created_at
|
||||||
|
@ -82,7 +92,7 @@ class ImportScripts::Ning < ImportScripts::Base
|
||||||
|
|
||||||
newuser.save
|
newuser.save
|
||||||
|
|
||||||
if u["profilePhoto"]
|
if u["profilePhoto"] && newuser.user_avatar.try(:custom_upload_id).nil?
|
||||||
photo_path = file_full_path(u["profilePhoto"])
|
photo_path = file_full_path(u["profilePhoto"])
|
||||||
if File.exists?(photo_path)
|
if File.exists?(photo_path)
|
||||||
begin
|
begin
|
||||||
|
@ -106,6 +116,7 @@ class ImportScripts::Ning < ImportScripts::Base
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
EmailToken.delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
def suspend_users
|
def suspend_users
|
||||||
|
@ -176,6 +187,11 @@ class ImportScripts::Ning < ImportScripts::Base
|
||||||
topics_json.each do |topic|
|
topics_json.each do |topic|
|
||||||
if topic["title"].present? && topic["description"].present?
|
if topic["title"].present? && topic["description"].present?
|
||||||
@current_topic_title = topic["title"] # for debugging
|
@current_topic_title = topic["title"] # for debugging
|
||||||
|
parent_post = nil
|
||||||
|
|
||||||
|
if parent_post_id = post_id_from_imported_post_id(topic["id"])
|
||||||
|
parent_post = Post.find(parent_post_id) # already imported this post
|
||||||
|
else
|
||||||
mapped = {}
|
mapped = {}
|
||||||
mapped[:id] = topic["id"]
|
mapped[:id] = topic["id"]
|
||||||
mapped[:user_id] = user_id_from_imported_user_id(topic["contributorName"]) || -1
|
mapped[:user_id] = user_id_from_imported_user_id(topic["contributorName"]) || -1
|
||||||
|
@ -198,9 +214,15 @@ class ImportScripts::Ning < ImportScripts::Base
|
||||||
puts "Error creating topic #{mapped[:id]}. Skipping."
|
puts "Error creating topic #{mapped[:id]}. Skipping."
|
||||||
puts parent_post.inspect
|
puts parent_post.inspect
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if topic["comments"].present?
|
if topic["comments"].present?
|
||||||
topic["comments"].reverse.each do |post|
|
topic["comments"].reverse.each do |post|
|
||||||
|
|
||||||
|
if post_id_from_imported_post_id(post["id"])
|
||||||
|
next # already imported this post
|
||||||
|
end
|
||||||
|
|
||||||
raw = process_ning_post_body(post["description"])
|
raw = process_ning_post_body(post["description"])
|
||||||
if post["fileAttachments"]
|
if post["fileAttachments"]
|
||||||
raw = add_file_attachments(raw, post["fileAttachments"])
|
raw = add_file_attachments(raw, post["fileAttachments"])
|
||||||
|
|
Loading…
Reference in New Issue