fix some error

This commit is contained in:
chiu 2020-04-08 20:54:44 +08:00
parent 97dd61fc52
commit f844b3d600
3 changed files with 21 additions and 11 deletions

View File

@ -13,6 +13,12 @@ class SiteFeed
require 'feed_model/cache'
include FeedModel::Cache
Category.send(:include,FeedModel::Cache)
before_destroy do
tmp = SiteFeedAnnc.where(feed_id: self.id).first
if !tmp.nil?
tmp.destroy
end
end
scope :enabled, ->{where(:disabled => false)}
def get_annc
main_directory = File.join("#{Rails.root}","public","site_feeds")

View File

@ -19,7 +19,7 @@ class SiteFeedAnnc
cat = self.category_title
Array(self[:all_contents_for_feed]).collect do |v|
tmp = v
if hidden_annc.exclude?(v['id'])
if hidden_annc.exclude?(v['id']) && !tmp["title_translations"][locale].blank?
tmp['statuses'] = []
if self[:top_list].count == 0 || self[:top_list].exclude?(tmp['id'])
tmp[:is_top] = false

View File

@ -6,18 +6,22 @@ module Feeds
require File.expand_path('../../../app/models/site_feed', __FILE__)
require File.expand_path('../../../app/models/site_feed_annc', __FILE__)
if defined?(SiteFeed) && defined?(SiteFeedAnnc)
SiteFeed.where(:disabled.ne => true).each do |site_feed|
SiteFeed.each do |site_feed|
tmp = SiteFeedAnnc.where(feed_id: site_feed.id).first
if tmp.nil?
tmp = SiteFeedAnnc.new(feed_id: site_feed.id)
if site_feed.disabled != true
if tmp.nil?
tmp = SiteFeedAnnc.new(feed_id: site_feed.id)
end
tmp.all_contents_for_feed = site_feed.get_annc
tmp[:feed_name] = site_feed[:feed_name]
tmp.merge_with_category = site_feed.merge_with_category
tmp.channel_key = site_feed.channel_key
tmp.category_title = site_feed.category[:title] rescue {}
tmp.channel_title = site_feed.channel_title_for_cache
tmp.save
elsif !tmp.nil?
tmp.destroy
end
tmp.all_contents_for_feed = site_feed.get_annc
tmp[:feed_name] = site_feed[:feed_name]
tmp.merge_with_category = site_feed.merge_with_category
tmp.channel_key = site_feed.channel_key
tmp.category_title = site_feed.category[:title] rescue {}
tmp.channel_title = site_feed.channel_title_for_cache
tmp.save
end
end
rescue => e