FEATURE: Category/topic importer skips objects that it has already imported.

This commit is contained in:
Neil Lalonde 2016-02-23 12:18:52 -05:00
parent 72784d23e7
commit eb87cffa13
2 changed files with 42 additions and 23 deletions

View file

@ -39,25 +39,33 @@ module ImportExport
def import_categories
id = @export_data[:category].delete(:id)
permissions = @export_data[:category].delete(:permissions_params)
parent = Category.new(@export_data[:category])
parent.user_id = @topic_importer.new_user_id(@export_data[:category][:user_id]) # imported user's new id
parent.custom_fields["import_id"] = id
parent.permissions = permissions if permissions
parent.save!
set_category_description(parent, @export_data[:category][:description])
parent = CategoryCustomField.where(name: 'import_id', value: id.to_s).first.try(:category)
unless parent
permissions = @export_data[:category].delete(:permissions_params)
parent = Category.new(@export_data[:category])
parent.user_id = @topic_importer.new_user_id(@export_data[:category][:user_id]) # imported user's new id
parent.custom_fields["import_id"] = id
parent.permissions = permissions if permissions
parent.save!
set_category_description(parent, @export_data[:category][:description])
end
@export_data[:subcategories].each do |cat_attrs|
id = cat_attrs.delete(:id)
permissions = cat_attrs.delete(:permissions_params)
subcategory = Category.new(cat_attrs)
subcategory.parent_category_id = parent.id
subcategory.user_id = @topic_importer.new_user_id(cat_attrs[:user_id])
subcategory.custom_fields["import_id"] = id
subcategory.permissions = permissions if permissions
subcategory.save!
set_category_description(subcategory, cat_attrs[:description])
existing = CategoryCustomField.where(name: 'import_id', value: id.to_s).first.try(:category)
unless existing
permissions = cat_attrs.delete(:permissions_params)
subcategory = Category.new(cat_attrs)
subcategory.parent_category_id = parent.id
subcategory.user_id = @topic_importer.new_user_id(cat_attrs[:user_id])
subcategory.custom_fields["import_id"] = id
subcategory.permissions = permissions if permissions
subcategory.save!
set_category_description(subcategory, cat_attrs[:description])
end
end
end

View file

@ -19,9 +19,11 @@ module ImportExport
def import_users
@export_data[:users].each do |u|
existing = User.where(email: u[:email]).first
if existing && existing.custom_fields["import_id"] != u[:id]
existing.custom_fields["import_id"] = u[:id]
existing.save!
if existing
if existing.custom_fields["import_id"] != u[:id]
existing.custom_fields["import_id"] = u[:id]
existing.save!
end
else
u = create_user(u, u[:id]) # see ImportScripts::Base
end
@ -38,15 +40,24 @@ module ImportExport
first_post_attrs[:user_id] = new_user_id(first_post_attrs[:user_id])
first_post_attrs[:category] = new_category_id(t[:category_id])
first_post = create_post( first_post_attrs, first_post_attrs[:id] )
first_post = PostCustomField.where(name: "import_id", value: first_post_attrs[:id]).first.try(:post)
unless first_post
first_post = create_post( first_post_attrs, first_post_attrs[:id] )
end
topic_id = first_post.topic_id
t[:posts].each_with_index do |post_data, i|
next if i == 0
print "."
create_post(post_data.merge({
topic_id: topic_id,
user_id: new_user_id(post_data[:user_id])
}), post_data[:id]) # see ImportScripts::Base
existing = PostCustomField.where(name: "import_id", value: post_data[:id]).first.try(:post)
unless existing
create_post(post_data.merge({
topic_id: topic_id,
user_id: new_user_id(post_data[:user_id])
}), post_data[:id]) # see ImportScripts::Base
end
end
end