diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 4ba4ca9..389afc2 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -96,7 +96,7 @@ class AnnouncementsController < ApplicationController locale = OrbitHelper.get_site_locale.to_s files = a.bulletin_files.to_fronted(locale) links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] - author = tmp_enable_annc_dept ? annc_depts[a.annc_dept] : User.find(a.create_user_id).member_name rescue (User.find(a.create_user_id).member_profile.name rescue "") + author = tmp_enable_annc_dept ? annc_depts[a.annc_dept] : User.find(a.update_user_id).member_name rescue (User.find(a.update_user_id).member_profile.name rescue "") desc = a.image_description desc = (desc.blank? ? "announcement image" : desc) link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param) @@ -955,7 +955,7 @@ class AnnouncementsController < ApplicationController locale = I18n.locale.to_s files = a.bulletin_files.to_fronted(locale) links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] - author = tmp_enable_annc_dept ? annc_depts[a.annc_dept] : User.find(a.create_user_id).member_profile.name rescue "" + author = tmp_enable_annc_dept ? annc_depts[a.annc_dept] : User.find(a.update_user_id).member_profile.name rescue "" desc = a.image_description desc = (desc.blank? ? "announcement image" : desc) link_to_show = (a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)) rescue "" diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index e620167..fbe1d47 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -32,7 +32,7 @@ module AnnouncementsHelper files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] files.delete(nil) links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] - author = tmp_enable_annc_dept ? annc_depts[a.annc_dept] : User.find(a.create_user_id).member_profile.name rescue "" + author = tmp_enable_annc_dept ? annc_depts[a.annc_dept] : User.find(a.update_user_id).member_profile.name rescue "" desc = a.image_description desc = (desc.nil? || desc == "" ? "announcement image" : desc) link_to_show = (a.is_external_link? ? a.external_link : OrbitHelper.widget_item_url(a.to_param)) rescue "" @@ -188,7 +188,7 @@ module AnnouncementsHelper else member_profile = MemberProfile.any_in(:uid=>params[:uids]) user_ids = member_profile.map{|m| m.user.id rescue nil}.select{|id| !id.nil?} - announcements = Bulletin.where(:title.nin => ["",nil],:is_preview.in=>[false,nil],:create_user_id.in=>user_ids) + announcements = Bulletin.where(:title.nin => ["",nil],:is_preview.in=>[false,nil],:update_user_id.in=>user_ids) .can_display_and_sorted.is_approved .filter_by_categories(categories,false).filter_by_tags(tags).to_a end diff --git a/app/models/announcement_setting.rb b/app/models/announcement_setting.rb index 5016248..0458c4d 100644 --- a/app/models/announcement_setting.rb +++ b/app/models/announcement_setting.rb @@ -37,21 +37,27 @@ class AnnouncementSetting before_save do can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash) - tmp_hash = {} if self.enable_manually_sort_changed? && self.enable_manually_sort AnnsCache.all.delete Bulletin.index({approved: -1,is_hidden: 1,is_preview: 1, is_top: -1,sort_number: 1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true }) Bulletin.create_indexes - tmp_hash[:enable_manually_sort] = self.enable_manually_sort + OrbitHelper::SharedHash["announcement"][:enable_manually_sort] = self.enable_manually_sort if can_update_shared_hash + end + @need_update_bulletin = false + if self.enable_annc_dept_changed? + OrbitHelper::SharedHash["announcement"][:enable_annc_dept] = self.enable_annc_dept + @need_update_bulletin = true end if self.annc_depts_changed? - tmp_hash[:annc_depts_translations] = self.annc_depts_translations + OrbitHelper::SharedHash["announcement"][:annc_depts_translations] = self.annc_depts_translations + @need_update_bulletin = true end - if can_update_shared_hash - if tmp_hash.count != 0 - tmp_hash[:enable_manually_sort] = self.enable_manually_sort if tmp_hash[:enable_manually_sort].nil? - tmp_hash[:annc_depts_translations] = self.annc_depts_translations if tmp_hash[:annc_depts_translations].nil? - OrbitHelper::SharedHash["announcement"] = ProcesssShareWraper.new(tmp_hash) + end + after_save do + if @need_update_bulletin + Thread.new do + AnnsCache.all.delete + Bulletin.notify_all_feed(true) end end end diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 8d4e338..8edc284 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -354,7 +354,7 @@ class Bulletin if tmp_enable_annc_dept author = annc_depts[self.annc_dept] rescue "" else - user = User.find(self.create_user_id) rescue nil + user = User.find(self.update_user_id) rescue nil if !user.nil? author = user.member_name || user.user_name else @@ -470,6 +470,45 @@ class Bulletin end end end + def self.notify_all_feed(force_update=false) + related_feeds = BulletinFeed.where(:remote_urls.nin=>[nil, []]).to_a + related_feeds.each do |feed| + uid = feed.uid + startdt = nil + enddt = nil + dt = nil + feed_cache = BulletinFeedCache.where(uid: uid, start: startdt, end: enddt, date: dt) + if force_update + feed_cache = nil + else + feed_cache_old = feed_cache.all_of([{:invalid_date.ne=>nil},{:invalid_date.lte => Time.now}]).last + feed_cache.all_of([{:invalid_date.ne=>nil},{:invalid_date.lte => Time.now}]).destroy + count = feed_cache.count + if count > 1 + feed_cache.limit(count-1).destroy + end + feed_cache = feed_cache.first + anns = '' + end + if feed_cache.nil? + anns = feed.generate_one_cache_timeout(startdt: startdt,enddt: enddt,dt: dt,timeout: 20) + anns = (feed_cache_old.content rescue "") if anns.nil? + else + anns = feed_cache.content + end + request = Net::HTTP::Post.new('/xhr/feeds/notify_change', 'Content-Type' => 'application/json') + tmp_data = {'type'=>'update_all', 'uid'=> uid, 'data'=>anns} + request.body = tmp_data.to_json + feed.remote_urls.each do |remote_url| + uri = URI(remote_url) + http_req = Net::HTTP.new(uri.host, uri.port) + if remote_url.include?('https') + http_req.use_ssl = true + end + response = self.http_request( http_req , request ) + end + end + end def self.notify_feed_delete(ids) all_feeds = BulletinFeed.all.select{|feed| feed.remote_urls.count != 0} if all_feeds.count != 0