fix error

This commit is contained in:
邱博亞 2021-11-17 22:05:08 +08:00
parent e3ab735f43
commit 2f2ea7768b
2 changed files with 37 additions and 41 deletions

View File

@ -1,7 +1,43 @@
Rails.application.routes.draw do
locales = Site.first.in_use_locales rescue I18n.available_locales
Thread.new do
begin
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
trans = {}
locales.each do |locale|
locale = locale.to_s
trans[locale] = {}
I18n.with_locale(locale) do
trans[locale]['top'] = I18n.t(:top)
trans[locale]['hot'] = I18n.t(:hot)
trans[locale]['more_plus'] = I18n.t(:more_plus)
end
end
SiteFeed.each do |site_feed|
tmp = SiteFeedAnnc.where(feed_id: site_feed.id).first
if site_feed.disabled != true
if tmp.nil?
tmp = SiteFeedAnnc.new(feed_id: site_feed.id)
end
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.remote_site_url = site_feed.remote_site_url
tmp.channel_title = site_feed.channel_title_for_cache
tmp.all_contents_for_feed = tmp.cache_annc(false,locales,trans)
tmp.save
elsif !tmp.nil?
tmp.destroy
end
end
SiteFeedAnnc.create_indexes
end
rescue => e
puts ['feed_routes',e]
end
end
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
get "/feeds/get_channel_list", to: 'feeds#get_channel_list'

View File

@ -1,46 +1,6 @@
module Feeds
class Engine < ::Rails::Engine
initializer "feeds" do
Thread.new do
begin
require File.expand_path('../../../app/models/site_feed', __FILE__)
require File.expand_path('../../../app/models/site_feed_annc', __FILE__)
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console') && defined?(SiteFeed) && defined?(SiteFeedAnnc)
locales = Site.first.in_use_locales rescue I18n.available_locales
trans = {}
locales.each do |locale|
locale = locale.to_s
trans[locale] = {}
I18n.with_locale(locale) do
trans[locale]['top'] = I18n.t(:top)
trans[locale]['hot'] = I18n.t(:hot)
trans[locale]['more_plus'] = I18n.t(:more_plus)
end
end
SiteFeed.each do |site_feed|
tmp = SiteFeedAnnc.where(feed_id: site_feed.id).first
if site_feed.disabled != true
if tmp.nil?
tmp = SiteFeedAnnc.new(feed_id: site_feed.id)
end
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.remote_site_url = site_feed.remote_site_url
tmp.channel_title = site_feed.channel_title_for_cache
tmp.all_contents_for_feed = tmp.cache_annc(false,locales,trans)
tmp.save
elsif !tmp.nil?
tmp.destroy
end
end
SiteFeedAnnc.create_indexes
end
rescue => e
puts ['feed_engine',e]
end
end
OrbitApp.registration "Feeds", :type => "ModuleApp" do
module_label "feed.feed"
base_url File.expand_path File.dirname(__FILE__)