Fix category migration
This commit is contained in:
parent
5d3bc07488
commit
de6ce0073f
|
@ -29,38 +29,40 @@ namespace :new_ui do
|
||||||
category_name = model_name unless category_name
|
category_name = model_name unless category_name
|
||||||
# # coll_cat = @db["#{category_name}_categories"]
|
# # coll_cat = @db["#{category_name}_categories"]
|
||||||
# # categories = coll_cat.find if coll_cat
|
# # categories = coll_cat.find if coll_cat
|
||||||
categories = "#{category_name}_categories".classify.constantize.admin_manager_all
|
|
||||||
categories = "#{category_name}_categories".classify.constantize.all if categories.blank?
|
|
||||||
module_app = ModuleApp.where(key: app_key)[0]
|
module_app = ModuleApp.where(key: app_key)[0]
|
||||||
categories.each do |category|
|
if module_app.has_category
|
||||||
new_category = module_app.categories.build
|
categories = "#{category_name}_categories".classify.constantize.admin_manager_all rescue nil
|
||||||
new_category.title_translations = category['title']
|
categories = "#{category_name}_categories".classify.constantize.all if categories.blank?
|
||||||
new_category.disable = category['disable']
|
categories.each do |category|
|
||||||
new_category.save
|
new_category = module_app.categories.build
|
||||||
model_name.classify.constantize.where("#{category_name}_category_id" => category['_id']).each do |object|
|
new_category.title_translations = category['title']
|
||||||
if object.id.is_a?(String)
|
new_category.disable = category['disable']
|
||||||
object.destroy
|
new_category.save
|
||||||
else
|
model_name.classify.constantize.where("#{category_name}_category_id" => category['_id']).each do |object|
|
||||||
object.category = new_category.id
|
if object.id.is_a?(String)
|
||||||
object.remove_attribute("#{category_name}_category_id")
|
object.destroy
|
||||||
object.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if object_auths = ObjectAuth.where(obj_authable_type: "#{category_name.classify}Category")
|
|
||||||
object_auths.each do |object_auth|
|
|
||||||
case object_auth.title
|
|
||||||
when 'fact_check'
|
|
||||||
new_object_auth = new_category.get_object_auth_by_title("approval_#{module_app.key}")
|
|
||||||
else
|
else
|
||||||
new_object_auth = new_category.get_object_auth_by_title("submit_#{module_app.key}")
|
object.category = new_category.id
|
||||||
|
object.remove_attribute("#{category_name}_category_id")
|
||||||
|
object.save
|
||||||
end
|
end
|
||||||
object_auth.auth_users.each do |user|
|
|
||||||
new_object_auth.add_user_to_privilege_list(user)
|
|
||||||
end
|
|
||||||
object_auth.destroy
|
|
||||||
end
|
end
|
||||||
|
if object_auths = ObjectAuth.where(obj_authable_type: "#{category_name.classify}Category")
|
||||||
|
object_auths.each do |object_auth|
|
||||||
|
case object_auth.title
|
||||||
|
when 'fact_check'
|
||||||
|
new_object_auth = new_category.get_object_auth_by_title("approval_#{module_app.key}")
|
||||||
|
else
|
||||||
|
new_object_auth = new_category.get_object_auth_by_title("submit_#{module_app.key}")
|
||||||
|
end
|
||||||
|
object_auth.auth_users.each do |user|
|
||||||
|
new_object_auth.add_user_to_privilege_list(user)
|
||||||
|
end
|
||||||
|
object_auth.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
category.destroy
|
||||||
end
|
end
|
||||||
category.destroy
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Reference in New Issue