Merge pull request 'fix bug.' (#6) from 123/seminar:master into master

Reviewed-on: spen/seminar#6
This commit is contained in:
chiu 2023-03-07 13:40:23 +00:00
commit 81ea8c4f67
3 changed files with 27 additions and 21 deletions

View File

@ -186,7 +186,12 @@ class SeminarMain
end end
end end
end end
after_initialize do after_destroy do
Thread.new do
Page.where(:bind_model=>self.class.to_s,:bind_uid=>self.uid).destroy
end
end
def migrate_old
unless self.new_record? || @triggered_initialize unless self.new_record? || @triggered_initialize
@triggered_initialize = true @triggered_initialize = true
save_flag = false save_flag = false
@ -234,11 +239,6 @@ class SeminarMain
self.save(:validate=>false) if save_flag self.save(:validate=>false) if save_flag
end end
end end
after_destroy do
Thread.new do
Page.where(:bind_model=>self.class.to_s,:bind_uid=>self.uid).destroy
end
end
def get_frontend_url(tmp_seminar_url, call_action=nil) def get_frontend_url(tmp_seminar_url, call_action=nil)
@enable_custom_template = self.enable_custom_template @enable_custom_template = self.enable_custom_template
if call_action.nil? if call_action.nil?
@ -494,16 +494,17 @@ class SeminarMain
approve_append = nil approve_append = nil
relations_fields.each do |k| relations_fields.each do |k|
belongs_to_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro == :belongs_to}.keys belongs_to_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro == :belongs_to}.keys
has_many_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro == :has_many}.keys has_many_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro.to_s.start_with?('has') }.keys
if (belongs_to_class - tmp_singularize_relations_fields).count == 0 if (belongs_to_class - tmp_singularize_relations_fields).count == 0
other_has_many_class = (has_many_class - unsort_relation_keys) other_has_many_class = (has_many_class - unsort_relation_keys)
if other_has_many_class.count == 0 if other_has_many_class.count == 0
tmp_relations_fields << k tmp_relations_fields << k
else else
org_k = k.to_s
result = other_has_many_class.map do |k| result = other_has_many_class.map do |k|
belongs_to_class = k.classify.constantize.relations.select{|kk,v| v.macro == :belongs_to}.keys belongs_to_class = k.classify.constantize.relations.select{|kk,v| v.macro == :belongs_to}.keys
has_many_class = k.classify.constantize.relations.select{|kk,v| v.macro == :has_many}.keys has_many_class = k.classify.constantize.relations.select{|kk,v| v.macro.to_s.start_with?('has') }.keys
if (belongs_to_class - tmp_singularize_relations_fields).count == 0 if (belongs_to_class - tmp_singularize_relations_fields - [org_k]).count == 0
true true
else else
fields_to_delete = fields_to_delete.concat(belongs_to_class) fields_to_delete = fields_to_delete.concat(belongs_to_class)
@ -546,7 +547,7 @@ class SeminarMain
no_dup_flag = false no_dup_flag = false
if clone_target.relations[f].macro == :belongs_to || clone_target.relations[f].macro == :has_one if clone_target.relations[f].macro == :belongs_to || clone_target.relations[f].macro == :has_one
no_dup_flag = new_object.send(f).present? no_dup_flag = new_object.send(f).present?
elsif clone_target.relations[f].macro == :has_many elsif clone_target.relations[f].macro == :has_many || clone_target.relations[f].macro == :has_and_belongs_to_many
no_dup_flag = new_object.send(f).to_a.count != 0 no_dup_flag = new_object.send(f).to_a.count != 0
elsif clone_target.relations[f].macro == :embeds_many #Fix localize fields elsif clone_target.relations[f].macro == :embeds_many #Fix localize fields
if new_object.send(f).to_a.count != 0 if new_object.send(f).to_a.count != 0
@ -597,7 +598,7 @@ class SeminarMain
end end
end end
new_object.send("#{f}=",clone_relation) new_object.send("#{f}=",clone_relation)
elsif clone_target.relations[f].macro == :has_many elsif clone_target.relations[f].macro == :has_many || clone_target.relations[f].macro == :has_and_belongs_to_many
next if self.except_clone_relations.to_s.include?(f) next if self.except_clone_relations.to_s.include?(f)
clone_relations = [] clone_relations = []
need_clone_relations = clone_target.send(f).asc(:_id).to_a need_clone_relations = clone_target.send(f).asc(:_id).to_a

View File

@ -337,8 +337,8 @@
<%= t('seminar.disable') %> <%= t('seminar.disable') %>
</td> </td>
<td> <td>
<input type="hidden" class="field_set" name='<%= "seminar_main[seminar_email_sets][#{index1}][disabled]" %>' value="false"> <input type="hidden" class="field_set" name='<%= "seminar_main[seminar_email_sets_attributes][#{index1}][disabled]" %>' value="false">
<%= check_box_tag("seminar_main[seminar_email_sets][#{index1}][disabled]", true ,@email_set[index1].disabled) %> <%= check_box_tag("seminar_main[seminar_email_sets_attributes][#{index1}][disabled]", true ,@email_set[index1].disabled) %>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -346,7 +346,7 @@
<%= t('seminar.email_title') %> <%= t('seminar.email_title') %>
</td> </td>
<td> <td>
<%= show_set_field(@email_set[index1],'seminar_email_sets',index1,'title','text_field') %> <%= show_set_field(@email_set[index1],'seminar_email_sets_attributes',index1,'title','text_field') %>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -355,7 +355,7 @@
</td> </td>
<td> <td>
<div class="form-group"> <div class="form-group">
<%= show_set_field(@email_set[index1],'seminar_email_sets',index1,'content','text_area') %> <%= show_set_field(@email_set[index1],'seminar_email_sets_attributes',index1,'content','text_area') %>
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -9,22 +9,27 @@ Rails.application.routes.draw do
update_flag = s.respond_to?(:tmp_flags) update_flag = s.respond_to?(:tmp_flags)
need_update1 = update_flag && !(s.tmp_flags.include?('fix_sr')) need_update1 = update_flag && !(s.tmp_flags.include?('fix_sr'))
need_update2 = !update_flag || !(s.tmp_flags.include?('smer1')) need_update2 = !update_flag || !(s.tmp_flags.include?('smer1'))
need_update3 = !update_flag || !(s.tmp_flags.include?('smer2'))
if need_update1 if need_update1
Page.where(:bind_model=>"SeminarMain",:all_pageids=>nil).each do |p| Page.where(:bind_model=>"SeminarMain",:all_pageids=>nil).each do |p|
p.save p.save
end end
tmp_flags = s.tmp_flags Site.update_all("$push"=>{"tmp_flags"=>'fix_sr'})
tmp_flags << 'fix_sr'
Site.update_all(:tmp_flags => tmp_flags)
end end
if need_update2 if need_update2
SeminarMain.where(:enable_recaptcha=>nil).each do |seminar_main| SeminarMain.where(:enable_recaptcha=>nil).each do |seminar_main|
seminar_main.update_enable_recaptcha seminar_main.update_enable_recaptcha
end end
if update_flag if update_flag
s = Site.first Site.update_all("$push"=>{"tmp_flags"=>'smer1'})
s.tmp_flags << 'smer1' end
s.save end
if need_update3
SeminarMain.all.to_a.each do |seminar_main|
seminar_main.migrate_old
end
if update_flag
Site.update_all("$push"=>{"tmp_flags"=>'smer2'})
end end
end end
end end