This commit is contained in:
BoHung Chiu 2022-09-19 12:01:17 +08:00
parent 300a4a8cba
commit e237aba5f2
4 changed files with 60 additions and 43 deletions

View File

@ -36,8 +36,9 @@ class BulletinsController < ApplicationController
annc_depts = annc_depts_translations[locale] rescue []
end
I18n.locale = :zh_tw
if !params[:keyword].blank?
keyword = Regexp.new(".*"+params[:keyword]+".*")
keyword = params[:keyword].to_s
if keyword.present?
keyword = Regexp.new(".*"+keyword+".*")
bulletins = Bulletin.any_of({:title=>keyword},{:subtitle=>keyword},{:text=>keyword})
else
bulletins = Bulletin.all
@ -111,8 +112,9 @@ class BulletinsController < ApplicationController
end
# 計算總筆數 Start
if !params[:keyword].blank?
keyword = Regexp.new(".*"+params[:keyword]+".*")
keyword = params[:keyword].to_s
if keyword.present?
keyword = Regexp.new(".*"+keyword+".*")
bulletin_count = Bulletin.any_of({:title=>keyword},{:subtitle=>keyword},{:text=>keyword})
else
bulletin_count = Bulletin.all

View File

@ -292,7 +292,7 @@ module AnnouncementsHelper
if @target_action == "index"
filename = overridehtml.nil? ? params[:layout_type] : overridehtml
filename = overridehtml.nil? ? params[:layout_type].to_s.split('/').last : overridehtml
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'announcement', "#{filename}.html.erb")
if !File.exists?f
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'announcement', "index.html.erb")

View File

@ -3,6 +3,19 @@ class Admin::PlaygroundController < OrbitAdminController
before_filter :check_for_testers, :only => "index"
layout "structure"
include Admin::PlaygroundHelper
begin
include BundlerHelper
rescue
def bundler_with_clean_env
if block_given?
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env(&Proc.new)
else
Bundler.with_clean_env(&Proc.new)
end
end
end
end
before_action :clean_multithread_model, :only => :command
def index
@ -103,17 +116,17 @@ class Admin::PlaygroundController < OrbitAdminController
File.delete(file) if File.exists?(file)
else
mul = Multithread.where(key: 'playground').first
if !mul.nil?
render :json => {"alive" => mul.status['alive'], "response" => mul.status['output'][params[:count].to_i..-1], "error" => mul.status['error']}.to_json
if !mul.status['alive']
mul.status['output'] = []
mul.status['error'] = false
mul.save
end
if !mul.nil?
render :json => {"alive" => mul.status['alive'], "response" => mul.status['output'][params[:count].to_i..-1], "error" => mul.status['error']}.to_json
if !mul.status['alive']
mul.status['output'] = []
mul.status['error'] = false
mul.save
end
else
render :json => {"alive" => true, "response" => "finish", "error" => false}.to_json
end
end
render :json => {"alive" => true, "response" => "finish", "error" => false}.to_json
end
end
end
private
@ -124,34 +137,34 @@ class Admin::PlaygroundController < OrbitAdminController
end
def exec_other_command(command)
mul = Multithread.where(key: 'playground').first
Thread.new do
begin
Bundler.with_clean_env do
IO.popen(command,:err=>[:child, :out]) do |stdout|
stdout.each do |line|
l = line.chomp
mul.status['output'] << l
if l == "rake aborted!"
mul.status['error'] = true
end
mul.save
end
end
mul.status['alive'] = false
mul.save
mul = Multithread.where(key: 'playground').first
Thread.new do
begin
bundler_with_clean_env do
IO.popen(command,:err=>[:child, :out]) do |stdout|
stdout.each do |line|
l = line.chomp
mul.status['output'] << l
if l == "rake aborted!"
mul.status['error'] = true
end
mul.save
end
end
mul.status['alive'] = false
mul.save
if command == 'bundle update'
system('sleep 2')
Bundler.with_clean_env{system("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")}
bundler_with_clean_env{system("#{RESTART_CMD}")}
end
end
rescue => e
mul.status['alive'] = false
mul.status['output'] << e.inspect
mul.status['error'] = true
mul.save
end
end
end
rescue => e
mul.status['alive'] = false
mul.status['output'] << e.inspect
mul.status['error'] = true
mul.save
end
end
end
def bundle_update
@ -160,7 +173,7 @@ class Admin::PlaygroundController < OrbitAdminController
end
def restart_server
cmd ="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"
cmd ="#{RESTART_CMD}"
exec_other_command(cmd)
end
@ -174,7 +187,7 @@ class Admin::PlaygroundController < OrbitAdminController
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
content = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s TERM $UNICORN_PID ; while (kill -0 $UNICORN_PID > /dev/null 2>&1) ; do printf '.' && sleep 1 ; done ; unset UNICORN_FD; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{mode}"
Thread.new do
Bundler.with_clean_env{system(content)}
bundler_with_clean_env{system(content)}
end
end

View File

@ -176,7 +176,9 @@ class Site
File.open("config/member_extra_db.txt","w+"){|f| f.write(self.member_extra_db)}
if (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash rescue false)
OrbitHelper::SharedHash['current_site']['site'] = self if @changed && OrbitHelper::SharedHash['current_site']
OrbitHelper::SharedHash['privileged_page_count'].value = self.privileged_page_count
if OrbitHelper::SharedHash['privileged_page_count']
OrbitHelper::SharedHash['privileged_page_count'].value = self.privileged_page_count
end
end
end
after_initialize do |record|