From 1ce77b43e1a75fbd55e334d6c48402c7b918588d Mon Sep 17 00:00:00 2001 From: Bohung Date: Tue, 21 Jun 2022 11:12:37 +0800 Subject: [PATCH] Add update_all notify callback. --- app/controllers/feeds_controller.rb | 33 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/app/controllers/feeds_controller.rb b/app/controllers/feeds_controller.rb index 4a633d5..9ee3c6f 100644 --- a/app/controllers/feeds_controller.rb +++ b/app/controllers/feeds_controller.rb @@ -22,6 +22,7 @@ class FeedsController < ApplicationController feed_directory = File.join(main_directory.to_s, feed.id.to_s) feed_data = JSON.parse(File.read(File.join(feed_directory.to_s, feed.feed_uid + ".json"))) channel_key_pluralize = feed_annc.channel_key.pluralize + need_write = true if params[:type] == 'create' trans = {} locales.each do |locale| @@ -132,15 +133,31 @@ class FeedsController < ApplicationController if can_create_record feeds_model.where(feeds_uid_field.to_sym.in =>params[:data].map{|a| a["id"]}, :site_feed_id=>feed_id).destroy end + elsif params[:type] == 'update_all' + feed_data = params[:data] + FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory) + File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file| + feed_data.force_encoding("utf-8") + file.write(feed_data) + end + need_write = false + feed_annc.all_contents_for_feed_will_change! + feed_annc[:all_contents_for_feed] = feed_annc.cache_annc + feed_annc.save! + if feeds_finish_callback + feeds_model.send(feeds_finish_callback, 'update_all', {"data"=>feed.get_annc(false),"feed_id"=>feed.id,"category_id"=>feed.merge_with_category}) + end end - feed_data = feed_data.to_json - FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory) - File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file| - feed_data.force_encoding("utf-8") - file.write(feed_data) - end - if feeds_finish_callback - feeds_model.send(feeds_finish_callback, params[:type]) + if need_write + feed_data = feed_data.to_json + FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory) + File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file| + feed_data.force_encoding("utf-8") + file.write(feed_data) + end + if feeds_finish_callback + feeds_model.send(feeds_finish_callback, params[:type]) + end end end render :json => {success: true}