Merge branch 'dev_local' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_local

dev_local_2
杨树林 5 years ago
commit 14c23d9af1

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

Loading…
Cancel
Save