Fix bug.
This commit is contained in:
邱博亞 2024-01-28 15:09:09 +08:00
parent c57a79dcc8
commit dfdefa3032
3 changed files with 41 additions and 3 deletions

View File

@ -468,7 +468,7 @@ class Admin::EventNewsController < OrbitAdminController
content = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s USR2 $UNICORN_PID ; n=20; while (kill -0 $UNICORN_PID > /dev/null 2>&1) && test $n -ge 0; do printf '.' && sleep 1 && n=$(( $n - 1 )); done ; if test $n -lt 0; then kill -s TERM $UNICORN_PID; sleep 3; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{Rails.env}; else kill -s QUIT $UNICORN_PID; fi" content = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s USR2 $UNICORN_PID ; n=20; while (kill -0 $UNICORN_PID > /dev/null 2>&1) && test $n -ge 0; do printf '.' && sleep 1 && n=$(( $n - 1 )); done ; if test $n -lt 0; then kill -s TERM $UNICORN_PID; sleep 3; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{Rails.env}; else kill -s QUIT $UNICORN_PID; fi"
system(content) system(content)
end end
redirect_to action: :index redirect_to admin_event_news_index_path
end end
private private

View File

@ -3,6 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version: # Maintain your gem's version:
require "event_news_mod/version" require "event_news_mod/version"
require "json"
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install' bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag if bundle_update_flag
require File.expand_path("../update_event_news", __FILE__) require File.expand_path("../update_event_news", __FILE__)
@ -24,7 +25,9 @@ if bundle_update_flag
app_path = File.expand_path(__dir__) app_path = File.expand_path(__dir__)
template_path = env_pwd + '/app/templates' template_path = env_pwd + '/app/templates'
all_template = Dir.glob(template_path+'/*/') all_template = Dir.glob(template_path+'/*/')
default_event_news_widget_info = JSON.parse(File.read("#{app_path}/modules/event_news_mod/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue [] default_info_contents = JSON.parse(File.read("#{app_path}/modules/event_news_mod/info.json")) rescue {}
default_event_news_index_info = default_info_contents["frontend"].sort_by{|h| h["filename"].to_f} rescue []
default_event_news_widget_info = default_info_contents["widgets"].sort_by{|h| h["filename"].to_f} rescue []
all_template.each do |folder| all_template.each do |folder|
if !folder.include?('mobile') if !folder.include?('mobile')
if Dir.exist?("#{folder}modules/event_news") if Dir.exist?("#{folder}modules/event_news")
@ -44,6 +47,41 @@ if bundle_update_flag
info = JSON.parse(encode_file_text) rescue {} info = JSON.parse(encode_file_text) rescue {}
flag = (info.count != 0 rescue false) flag = (info.count != 0 rescue false)
if flag if flag
puts "Checking event_news index"
index_info = info["frontend"].sort_by{|h| h["filename"].to_i} rescue []
update_flag = false
last_index = index_info.collect{|v| v["filename"].to_s.scan(/\d+/).collect{|v1| v1.to_i}}.flatten.sort[-1] rescue nil
if !last_index.nil?
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
default_event_news_index_info.each do |h|
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
index_info_index = (index_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
if index_info_index == -1
update_flag = true
copy_h = h.dup
h.delete("force_cover")
last_index = last_index + 1
copy_h["filename"] = copy_h["filename"].sub(/\d+/){|ff| last_index.to_s}
copy_h["name"].keys.each do |locale|
copy_h["name"][locale] = copy_h["name"][locale].sub(/\d+/){|ff| last_index.to_s}
end
index_info << copy_h
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{h["filename"]}.html.erb #{folder}modules/event_news_mod/#{copy_h["filename"]}.html.erb]}
elsif h["force_cover"] == "true"
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{h["filename"]}.html.erb #{folder}modules/event_news_mod/#{index_info[index_info_index]["filename"]}.html.erb]}
end
end
if update_flag
info["frontend"] = index_info
puts "Writing json #{info["frontend"].count} in #{info_json_file}"
begin
info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n")
rescue
info_json = info.to_s.gsub("=>",": \n")
end
File.open(info_json_file,"w+"){|f| f.write(info_json)}
end
end
puts "Checking event_news widgets" puts "Checking event_news widgets"
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue [] widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
update_flag = false update_flag = false

View File

@ -47,7 +47,7 @@ def add_css_style_for_block(c,head_key,value_key,css_key)
[flag,c_tp] [flag,c_tp]
end end
def update_event_news_template(folder) def update_event_news_template(folder)
Dir["#{folder}modules/event_news/*.html.erb"].each do |f| Dir["#{folder}modules/event_news_mod/*.html.erb"].each do |f|
c = File.open(f,'r'){|f1| f1.read}.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???") c = File.open(f,'r'){|f1| f1.read}.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???")
next if (c.include?("???") rescue true) next if (c.include?("???") rescue true)
flag1,c = add_css_style_for_block(c,'speaker-head','speaker','speaker-css') flag1,c = add_css_style_for_block(c,'speaker-head','speaker','speaker-css')