Prepare to support ruby 3.3.
This commit is contained in:
parent
5a47481072
commit
a790cc0c72
|
@ -136,7 +136,7 @@ class FeedsController < ApplicationController
|
||||||
end
|
end
|
||||||
elsif params[:type] == 'update_all'
|
elsif params[:type] == 'update_all'
|
||||||
feed_data = params[:data]
|
feed_data = params[:data]
|
||||||
FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory)
|
FileUtils.mkdir_p(feed_directory) if !File.exist?(feed_directory)
|
||||||
File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file|
|
File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file|
|
||||||
feed_data.force_encoding("utf-8")
|
feed_data.force_encoding("utf-8")
|
||||||
file.write(feed_data)
|
file.write(feed_data)
|
||||||
|
@ -151,7 +151,7 @@ class FeedsController < ApplicationController
|
||||||
end
|
end
|
||||||
if need_write
|
if need_write
|
||||||
feed_data = feed_data.to_json
|
feed_data = feed_data.to_json
|
||||||
FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory)
|
FileUtils.mkdir_p(feed_directory) if !File.exist?(feed_directory)
|
||||||
File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file|
|
File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file|
|
||||||
feed_data.force_encoding("utf-8")
|
feed_data.force_encoding("utf-8")
|
||||||
file.write(feed_data)
|
file.write(feed_data)
|
||||||
|
|
|
@ -95,7 +95,7 @@ class SiteFeed
|
||||||
end
|
end
|
||||||
main_directory = File.join("#{Rails.root}","public","site_feeds")
|
main_directory = File.join("#{Rails.root}","public","site_feeds")
|
||||||
feed_directory = File.join(main_directory.to_s, self.id.to_s)
|
feed_directory = File.join(main_directory.to_s, self.id.to_s)
|
||||||
if !force_refresh && File.exists?(feed_directory)
|
if !force_refresh && File.exist?(feed_directory)
|
||||||
anns = JSON.parse(File.read(File.join(feed_directory.to_s, self.feed_uid + ".json")))[self.channel_key.pluralize] rescue []
|
anns = JSON.parse(File.read(File.join(feed_directory.to_s, self.feed_uid + ".json")))[self.channel_key.pluralize] rescue []
|
||||||
else
|
else
|
||||||
uri = URI(self.feed_url)
|
uri = URI(self.feed_url)
|
||||||
|
@ -143,7 +143,7 @@ class SiteFeed
|
||||||
end
|
end
|
||||||
res = JSON.dump({"announcements" => res_to_json})
|
res = JSON.dump({"announcements" => res_to_json})
|
||||||
end
|
end
|
||||||
FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory)
|
FileUtils.mkdir_p(feed_directory) if !File.exist?(feed_directory)
|
||||||
File.open(File.join(feed_directory.to_s,self.feed_uid + ".json"),"w") do |file|
|
File.open(File.join(feed_directory.to_s,self.feed_uid + ".json"),"w") do |file|
|
||||||
res.force_encoding("utf-8")
|
res.force_encoding("utf-8")
|
||||||
file.write(res)
|
file.write(res)
|
||||||
|
|
|
@ -1,62 +1,61 @@
|
||||||
module Feeds
|
module Feeds
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
initializer "feeds" do
|
initializer "feeds" do
|
||||||
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
Rails.application.config.to_prepare do
|
||||||
require File.expand_path('../../../app/models/site_feed_setting', __FILE__)
|
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
||||||
if defined?(SiteFeedSetting)
|
require File.expand_path('../../../app/models/site_feed_setting', __FILE__)
|
||||||
if SiteFeedSetting.count==0
|
if defined?(SiteFeedSetting)
|
||||||
SiteFeedSetting.create
|
if SiteFeedSetting.count==0
|
||||||
|
SiteFeedSetting.create
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
OrbitApp.registration "Feeds", :type => "ModuleApp" do
|
||||||
OrbitApp.registration "Feeds", :type => "ModuleApp" do
|
module_label "feed.feed"
|
||||||
module_label "feed.feed"
|
base_url File.expand_path File.dirname(__FILE__)
|
||||||
base_url File.expand_path File.dirname(__FILE__)
|
categorizable
|
||||||
categorizable
|
authorizable
|
||||||
authorizable
|
if File.basename($0) != 'rake'
|
||||||
if File.basename($0) != 'rake'
|
begin
|
||||||
begin
|
avoid_page_cache SiteFeed
|
||||||
avoid_page_cache SiteFeed
|
rescue => e
|
||||||
rescue => e
|
puts ["avoid_page_cache", e.to_s]
|
||||||
puts ["avoid_page_cache", e.to_s]
|
end
|
||||||
end
|
end
|
||||||
end
|
side_bar do
|
||||||
side_bar do
|
head_label_i18n 'feed.feed', icon_class: "icons-rss"
|
||||||
head_label_i18n 'feed.feed', icon_class: "icons-rss"
|
available_for "managers"
|
||||||
available_for "managers"
|
active_for_controllers (['admin/feeds'])
|
||||||
active_for_controllers (['admin/feeds'])
|
head_link_path "admin_feeds_path"
|
||||||
head_link_path "admin_feeds_path"
|
|
||||||
|
|
||||||
context_link 'feed.all_feeds',
|
context_link 'feed.all_feeds',
|
||||||
:link_path=>"admin_feeds_path" ,
|
:link_path=>"admin_feeds_path" ,
|
||||||
:priority=>1,
|
:priority=>1,
|
||||||
:active_for_action=>{'admin/feeds'=>'index'},
|
:active_for_action=>{'admin/feeds'=>'index'},
|
||||||
:available_for => 'managers'
|
:available_for => 'managers'
|
||||||
context_link 'feed.new_',
|
context_link 'feed.new_',
|
||||||
:link_path=>"new_admin_feed_path" ,
|
:link_path=>"new_admin_feed_path" ,
|
||||||
:priority=>2,
|
:priority=>2,
|
||||||
:active_for_action=>{'admin/feeds'=>'new'},
|
:active_for_action=>{'admin/feeds'=>'new'},
|
||||||
:available_for => 'managers'
|
:available_for => 'managers'
|
||||||
context_link 'feed.all_announcements',
|
context_link 'feed.all_announcements',
|
||||||
:link_path=>"admin_feeds_announcements_path" ,
|
:link_path=>"admin_feeds_announcements_path" ,
|
||||||
:priority=>3,
|
:priority=>3,
|
||||||
:active_for_action=>{'admin/feeds'=>'announcements'},
|
:active_for_action=>{'admin/feeds'=>'announcements'},
|
||||||
:available_for => 'managers'
|
:available_for => 'managers'
|
||||||
context_link 'feed.settings',
|
context_link 'feed.settings',
|
||||||
:link_path=>"admin_feeds_settings_path" ,
|
:link_path=>"admin_feeds_settings_path" ,
|
||||||
:priority=>3,
|
:priority=>3,
|
||||||
:active_for_action=>{'admin/feeds'=>'settings'},
|
:active_for_action=>{'admin/feeds'=>'settings'},
|
||||||
:available_for => 'managers'
|
:available_for => 'managers'
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
gem_root = Feeds::Engine.root
|
||||||
end
|
gem_tmp = File.join(gem_root, 'tmp')
|
||||||
spec = Gem::Specification.find_by_name("feeds") rescue nil
|
f = File.join(gem_tmp, "install_bash")
|
||||||
if !spec.nil?
|
if File.exist?(f)
|
||||||
gem_root = spec.gem_dir
|
|
||||||
gem_tmp = gem_root + "/tmp/"
|
|
||||||
f = File.join(gem_tmp + "install_bash")
|
|
||||||
if File.exists?(f)
|
|
||||||
File.delete(f)
|
File.delete(f)
|
||||||
%x(cp "#{gem_root}/config/schedule.rb" config/schedule.rb)
|
%x(cp "#{gem_root}/config/schedule.rb" config/schedule.rb)
|
||||||
%x(whenever --update-crontab feeds --set environment="#{ENV["RAILS_ENV"]}")
|
%x(whenever --update-crontab feeds --set environment="#{ENV["RAILS_ENV"]}")
|
||||||
|
|
Loading…
Reference in New Issue