From 3a59df9efb4123b3eccfab67409cbf48ec3a5091 Mon Sep 17 00:00:00 2001 From: BoHung Chiu Date: Tue, 7 Feb 2023 11:30:38 +0800 Subject: [PATCH] Updated. --- app/models/seminar_main.rb | 12 ++++++------ config/routes.rb | 17 +++++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/models/seminar_main.rb b/app/models/seminar_main.rb index d1eb37c..fa3392d 100644 --- a/app/models/seminar_main.rb +++ b/app/models/seminar_main.rb @@ -186,7 +186,12 @@ class SeminarMain 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 @triggered_initialize = true save_flag = false @@ -234,11 +239,6 @@ class SeminarMain self.save(:validate=>false) if save_flag 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) @enable_custom_template = self.enable_custom_template if call_action.nil? diff --git a/config/routes.rb b/config/routes.rb index e8581ab..576d277 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,22 +9,27 @@ Rails.application.routes.draw do update_flag = s.respond_to?(:tmp_flags) need_update1 = update_flag && !(s.tmp_flags.include?('fix_sr')) need_update2 = !update_flag || !(s.tmp_flags.include?('smer1')) + need_update3 = !update_flag || !(s.tmp_flags.include?('smer2')) if need_update1 Page.where(:bind_model=>"SeminarMain",:all_pageids=>nil).each do |p| p.save end - tmp_flags = s.tmp_flags - tmp_flags << 'fix_sr' - Site.update_all(:tmp_flags => tmp_flags) + Site.update_all("$push"=>{"tmp_flags"=>'fix_sr'}) end if need_update2 SeminarMain.where(:enable_recaptcha=>nil).each do |seminar_main| seminar_main.update_enable_recaptcha end if update_flag - s = Site.first - s.tmp_flags << 'smer1' - s.save + Site.update_all("$push"=>{"tmp_flags"=>'smer1'}) + end + 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