Fix feed not update when updating setting.
Change display update user instead of create user.
This commit is contained in:
parent
2067444a7e
commit
2178bafe2a
|
@ -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 ""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue