diff --git a/app/controllers/initialization_data_controller.rb b/app/controllers/initialization_data_controller.rb index b2fb51f36..7ed01ad8c 100644 --- a/app/controllers/initialization_data_controller.rb +++ b/app/controllers/initialization_data_controller.rb @@ -67,7 +67,7 @@ class InitializationDataController < ApplicationController logger.info("#########test_sets: #{@test_sets.map(&:id)}") logger.info("#########challenge_chooses: #{@challenge_chooses.map(&:id)}") logger.info("#########challenge_questions: #{@challenge_questions.map(&:id)}") - logger.info("#########attachments: #{@att_ids.count}") + logger.info("#########attachments: #{@attachments.count}") connect_to_origin_date database logger.info("#########subjects: #{@subjects.count}") logger.info("#########stage: #{@stages.count}") @@ -83,7 +83,7 @@ class InitializationDataController < ApplicationController logger.info("#########test_sets: #{@test_sets.count}") logger.info("#########challenge_chooses: #{@challenge_chooses.count}") logger.info("#########challenge_questions: #{@challenge_questions.count}") - logger.info("#########attachments: #{@att_ids}") + logger.info("#########attachments: #{@attachments.count}") ActiveRecord::Base.transaction do copy_subject_data copy_stages_data @@ -107,22 +107,22 @@ class InitializationDataController < ApplicationController # 链接库 def connect_to_origin_date database - # ActiveRecord::Base.establish_connection( - # adapter: "mysql2", - # host: "rm-bp13v5020p7828r5r.mysql.rds.aliyuncs.com", - # username: "testeducoder", - # password: "TEST@123", - # database: "#{database}", - # encoding: "utf8" - # ) ActiveRecord::Base.establish_connection( adapter: "mysql2", - host: "127.0.0.1", - username: "root", - password: "123456", + host: "rm-bp13v5020p7828r5r.mysql.rds.aliyuncs.com", + username: "testeducoder", + password: "TEST@123", database: "#{database}", encoding: "utf8" ) + # ActiveRecord::Base.establish_connection( + # adapter: "mysql2", + # host: "127.0.0.1", + # username: "root", + # password: "123456", + # database: "#{database}", + # encoding: "utf8" + # ) end @@ -192,7 +192,6 @@ class InitializationDataController < ApplicationController Shixun.bulk_insert(*shixun_attrs) do |worker| @shixuns.each do |shixun| base_attr = shixun.attributes.dup.except("user_id", "myshixuns_count", "use_scope") - logger.info("#######shixun:#{base_attr}") worker.add(base_attr.merge(user_id: 1)) end end @@ -387,24 +386,26 @@ class InitializationDataController < ApplicationController # 获取关卡附件 def get_attachment_data task_pass = Challenge.where(id: @challenges).where("task_pass like '%/api/attachments/%'").pluck(:task_pass) - @att_ids = [] + att_ids = [] # 附件的格式为(/api/attachments/ + 附件id)的形式,因此下面的正文匹配是为了取出附件的id,方便迁移attachments task_pass.each do |tp| - @att_ids += tp.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} + att_ids += tp.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} end + @attachments = Attachment.where(id: att_ids).to_a end # 创建附件数据 def copy_attachment_data - return if @att_ids.blank? - attachment_attrs = %i[id container_id container_type filename disk_filename filesize content_type digest author_id created_on - downloads description disk_directory attachtype is_public copy_from quotes is_publish publish_time resource_bank_id unified_setting + return if @attachments.blank? + attachment_attrs = %i[id container_id container_type filename disk_filename filesize content_type digest downloads author_id + created_on description disk_directory attachtype is_public copy_from quotes is_publish publish_time resource_bank_id unified_setting cloud_url course_second_category_id] Attachment.bulk_insert(*attachment_attrs) do |worker| - Attachment.where(id: @att_ids).find_each do |att| - base_attr = att.attributes.except("author_id", "disk_directory", "copy_from") + @attachments.each do |att| + logger.info("########att_id: #{att.id}") + base_attr = att.attributes.dup.except("author_id", "disk_directory", "copy_from") # 本地版将过关任务的图片迁移到files/localshixuns 目录下, copy_from记录的是他原来的目录结构 - worker.add(base_attr.merge({author_id: 1, disk_directory: "localshixuns", copy_from: att.disk_directory})) + worker.add(base_attr.merge(author_id: 1, disk_directory: "localshixuns", copy_from: att.disk_directory)) end end end