76 lines
3.0 KiB
Ruby
76 lines
3.0 KiB
Ruby
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 defined?(SiteFeed) && defined?(SiteFeedAnnc)
|
|
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
|
|
tmp.save
|
|
elsif !tmp.nil?
|
|
tmp.destroy
|
|
end
|
|
end
|
|
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__)
|
|
categorizable
|
|
authorizable
|
|
|
|
side_bar do
|
|
head_label_i18n 'feed.feed', icon_class: "icons-rss"
|
|
available_for "managers"
|
|
active_for_controllers (['admin/feeds'])
|
|
head_link_path "admin_feeds_path"
|
|
|
|
context_link 'feed.all_feeds',
|
|
:link_path=>"admin_feeds_path" ,
|
|
:priority=>1,
|
|
:active_for_action=>{'admin/feeds'=>'index'},
|
|
:available_for => 'managers'
|
|
context_link 'feed.new_',
|
|
:link_path=>"new_admin_feed_path" ,
|
|
:priority=>2,
|
|
:active_for_action=>{'admin/feeds'=>'new'},
|
|
:available_for => 'managers'
|
|
context_link 'feed.all_announcements',
|
|
:link_path=>"admin_feeds_announcements_path" ,
|
|
:priority=>3,
|
|
:active_for_action=>{'admin/feeds'=>'announcements'},
|
|
:available_for => 'managers'
|
|
end
|
|
|
|
end
|
|
spec = Gem::Specification.find_by_name("feeds") rescue nil
|
|
if !spec.nil?
|
|
gem_root = spec.gem_dir
|
|
gem_tmp = gem_root + "/tmp/"
|
|
f = File.join(gem_tmp + "install_bash")
|
|
if File.exists?(f)
|
|
File.delete(f)
|
|
%x(cp "#{gem_root}/config/schedule.rb" config/schedule.rb)
|
|
%x(whenever --update-crontab feeds --set environment="#{ENV["RAILS_ENV"]}")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|