|
|
@ -1,9 +1,9 @@
|
|
|
|
class Subjects::CopySubjectService < ApplicationService
|
|
|
|
class Subjects::CopySubjectService < ApplicationService
|
|
|
|
attr_reader :subject, :to_subject, :user_id, :laboratory
|
|
|
|
attr_reader :subject, :to_subject, :user, :laboratory
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(subject, user_id, laboratory=nil)
|
|
|
|
def initialize(subject, user, laboratory=nil)
|
|
|
|
@subject = subject
|
|
|
|
@subject = subject
|
|
|
|
@user_id = user_id
|
|
|
|
@user = user
|
|
|
|
@laboratory = laboratory
|
|
|
|
@laboratory = laboratory
|
|
|
|
subject_params = subject.attributes.dup.except('id', 'copy_subject_id', 'user_id', 'homepage_show')
|
|
|
|
subject_params = subject.attributes.dup.except('id', 'copy_subject_id', 'user_id', 'homepage_show')
|
|
|
|
@to_subject = Subject.new(subject_params)
|
|
|
|
@to_subject = Subject.new(subject_params)
|
|
|
@ -21,7 +21,7 @@ class Subjects::CopySubjectService < ApplicationService
|
|
|
|
# 复制实践课程表
|
|
|
|
# 复制实践课程表
|
|
|
|
def copy_subject!
|
|
|
|
def copy_subject!
|
|
|
|
to_subject.copy_subject_id = subject.id
|
|
|
|
to_subject.copy_subject_id = subject.id
|
|
|
|
to_subject.user_id = user_id
|
|
|
|
to_subject.user_id = user.id
|
|
|
|
to_subject.save!
|
|
|
|
to_subject.save!
|
|
|
|
|
|
|
|
|
|
|
|
copy_stages_data!(subject, to_subject)
|
|
|
|
copy_stages_data!(subject, to_subject)
|
|
|
@ -34,7 +34,7 @@ class Subjects::CopySubjectService < ApplicationService
|
|
|
|
subject.stages.each do |stage|
|
|
|
|
subject.stages.each do |stage|
|
|
|
|
to_stage = to_subject.stages.new
|
|
|
|
to_stage = to_subject.stages.new
|
|
|
|
to_stage.attributes = stage.attributes.dup.except('id', 'subject_id', 'user_id')
|
|
|
|
to_stage.attributes = stage.attributes.dup.except('id', 'subject_id', 'user_id')
|
|
|
|
to_stage.user_id = user_id
|
|
|
|
to_stage.user_id = user.id
|
|
|
|
to_stage.save!
|
|
|
|
to_stage.save!
|
|
|
|
|
|
|
|
|
|
|
|
copy_stage_shixuns_data!(stage, to_stage)
|
|
|
|
copy_stage_shixuns_data!(stage, to_stage)
|
|
|
@ -61,10 +61,15 @@ class Subjects::CopySubjectService < ApplicationService
|
|
|
|
to_shixun.attributes = shixun.attributes.dup.except('id', 'user_id', 'identifier', 'homepage_show',
|
|
|
|
to_shixun.attributes = shixun.attributes.dup.except('id', 'user_id', 'identifier', 'homepage_show',
|
|
|
|
'use_scope', 'averge_star', 'myshixuns_count')
|
|
|
|
'use_scope', 'averge_star', 'myshixuns_count')
|
|
|
|
to_shixun.identifier = Util::UUID.generate_identifier(Shixun, 8)
|
|
|
|
to_shixun.identifier = Util::UUID.generate_identifier(Shixun, 8)
|
|
|
|
to_shixun.user_id = user_id
|
|
|
|
to_shixun.user_id = user.id
|
|
|
|
if laboratory
|
|
|
|
if laboratory
|
|
|
|
to_shixun.laboratory_id = laboratory.id
|
|
|
|
to_shixun.laboratory_id = laboratory.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# 复制版本库
|
|
|
|
|
|
|
|
fork_repository_name = "#{user.login}/#{to_shixun.identifier}"
|
|
|
|
|
|
|
|
GitService.fork_repository(repo_path: "#{shixun.repo_name}.git",
|
|
|
|
|
|
|
|
fork_repository_path: (fork_repository_name + ".git"))
|
|
|
|
|
|
|
|
to_shixun.repo_name = fork_repository_name
|
|
|
|
to_shixun.save!
|
|
|
|
to_shixun.save!
|
|
|
|
|
|
|
|
|
|
|
|
copy_shixun_info_data!(shixun, to_shixun)
|
|
|
|
copy_shixun_info_data!(shixun, to_shixun)
|
|
|
@ -124,7 +129,7 @@ class Subjects::CopySubjectService < ApplicationService
|
|
|
|
shixun.challenges.each do |challenge|
|
|
|
|
shixun.challenges.each do |challenge|
|
|
|
|
to_challenge = to_shixun.challenges.new
|
|
|
|
to_challenge = to_shixun.challenges.new
|
|
|
|
to_challenge.attributes = challenge.attributes.dup.except('id', 'shixun_id', 'praises_count', 'user_id', 'visits')
|
|
|
|
to_challenge.attributes = challenge.attributes.dup.except('id', 'shixun_id', 'praises_count', 'user_id', 'visits')
|
|
|
|
to_challenge.user_id = user_id
|
|
|
|
to_challenge.user_id = user.id
|
|
|
|
to_challenge.shixun_id = to_shixun.id
|
|
|
|
to_challenge.shixun_id = to_shixun.id
|
|
|
|
to_challenge.save!
|
|
|
|
to_challenge.save!
|
|
|
|
|
|
|
|
|
|
|
@ -201,12 +206,12 @@ class Subjects::CopySubjectService < ApplicationService
|
|
|
|
|
|
|
|
|
|
|
|
# 创建实训成员
|
|
|
|
# 创建实训成员
|
|
|
|
def copy_shixun_members_data!(to_shixun)
|
|
|
|
def copy_shixun_members_data!(to_shixun)
|
|
|
|
to_shixun.shixun_members.create!(user_id: user_id, role: 1)
|
|
|
|
to_shixun.shixun_members.create!(user_id: user.id, role: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 创建课程成员
|
|
|
|
# 创建课程成员
|
|
|
|
def copy_subject_members_data(to_subject)
|
|
|
|
def copy_subject_members_data(to_subject)
|
|
|
|
to_subject.subject_members.create!(user_id: user_id, role: 1)
|
|
|
|
to_subject.subject_members.create!(user_id: user.id, role: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|