From 7e203b6863b757d0006e8f1d0f8745d760ca813f Mon Sep 17 00:00:00 2001 From: Bohung Date: Sun, 4 Apr 2021 09:49:24 +0800 Subject: [PATCH] Fix bug. --- app/controllers/admin/seminars_controller.rb | 2 +- app/models/seminar_main.rb | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index a9c3dee..f5c8fdd 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -343,7 +343,7 @@ class Admin::SeminarsController < OrbitAdminController seminar.create_user_id = current_user.id seminar.update_user_id = current_user.id if seminar.copy_id && params["clone_signups"].blank? - seminar.except_clone_relations = ["seminar_signups","seminar_signup_values"] + seminar.except_clone_relations = ["seminar_signups","seminar_signup_values","seminar_signup_contributes","seminar_submission_values"] end seminar.save if seminar.copy_id diff --git a/app/models/seminar_main.rb b/app/models/seminar_main.rb index 15f451b..e36f507 100644 --- a/app/models/seminar_main.rb +++ b/app/models/seminar_main.rb @@ -309,6 +309,7 @@ def clone_new_for_object(object,clone_target=nil,clone_mode=false) clone_target = object if clone_target.nil? new_object = object.dup end + return if self.except_clone_relations.to_s.include?(new_object.class.to_s.underscore) @records_all["#{new_object.class.to_s.underscore.singularize}_ids"] = {} if @records_all["#{new_object.class.to_s.underscore.singularize}_ids"].nil? begin @records_all["#{new_object.class.to_s.underscore.singularize}_ids"][clone_target.id] = object.id @@ -372,6 +373,7 @@ def clone_new_for_object(object,clone_target=nil,clone_mode=false) end relations_fields = tmp_relations_fields fields_to_delete.each{|f| relations_fields.delete(f)} + @clone_mode = clone_mode end @parent_level = true if clone_mode @@ -396,7 +398,7 @@ def clone_new_for_object(object,clone_target=nil,clone_mode=false) new_object.send("#{f}_id=",(@records_all["#{f}_ids"][clone_target.send("#{f}_id")])) end elsif clone_target.relations[f].macro == :has_many - next if self.except_clone_relations.include?(f) + next if self.except_clone_relations.to_s.include?(f) clone_relations = [] need_clone_relations = clone_target.send(f).asc(:_id).to_a file_flag = false @@ -409,14 +411,16 @@ def clone_new_for_object(object,clone_target=nil,clone_mode=false) check_fields = clone_relation.fields.except(initialize_fields) check_fields.keys.each do |f| if (clone_relation.send(f).class.to_s.match(/uploader/i) rescue false) - if clone_relation[f].blank? + if clone_relation[f].blank? && (clone_relation.send(f).file.nil? rescue true) clone_relation[f] = r[f] source_filepath = r.send(f).file.file - if clone_mode + if @clone_mode dest_filepath = clone_relation.send(f).file.file FileUtils.mkdir_p(File.dirname(dest_filepath)) FileUtils.cp(source_filepath,dest_filepath) end + elsif (clone_relation.send(f).file rescue nil) + clone_relation[f] = File.basename(clone_relation.send(f).file.file.to_s) end file_flag = true end