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
|
||||
# # coll_cat = @db["#{category_name}_categories"]
|
||||
# # 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]
|
||||
categories.each do |category|
|
||||
new_category = module_app.categories.build
|
||||
new_category.title_translations = category['title']
|
||||
new_category.disable = category['disable']
|
||||
new_category.save
|
||||
model_name.classify.constantize.where("#{category_name}_category_id" => category['_id']).each do |object|
|
||||
if object.id.is_a?(String)
|
||||
object.destroy
|
||||
else
|
||||
object.category = new_category.id
|
||||
object.remove_attribute("#{category_name}_category_id")
|
||||
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}")
|
||||
if module_app.has_category
|
||||
categories = "#{category_name}_categories".classify.constantize.admin_manager_all rescue nil
|
||||
categories = "#{category_name}_categories".classify.constantize.all if categories.blank?
|
||||
categories.each do |category|
|
||||
new_category = module_app.categories.build
|
||||
new_category.title_translations = category['title']
|
||||
new_category.disable = category['disable']
|
||||
new_category.save
|
||||
model_name.classify.constantize.where("#{category_name}_category_id" => category['_id']).each do |object|
|
||||
if object.id.is_a?(String)
|
||||
object.destroy
|
||||
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
|
||||
object_auth.auth_users.each do |user|
|
||||
new_object_auth.add_user_to_privilege_list(user)
|
||||
end
|
||||
object_auth.destroy
|
||||
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
|
||||
category.destroy
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue