fix error for comment and bundle update

This commit is contained in:
邱博亞 2023-05-06 16:24:25 +08:00
parent 742382ed67
commit 14822f2bbf
7 changed files with 941 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,4 +1,5 @@
class AnnouncementsController < ApplicationController class AnnouncementsController < ApplicationController
ViewRootDir = File.expand_path("../../views", __FILE__)
include AnnouncementsHelper include AnnouncementsHelper
DefaultImgSrc = "/assets/announcement-default.jpg\" onerror=\"this.src=&quot;/assets/announcement-default-2.jpg&quot;;this.onerror='';" DefaultImgSrc = "/assets/announcement-default.jpg\" onerror=\"this.src=&quot;/assets/announcement-default-2.jpg&quot;;this.onerror='';"
def initialize def initialize
@ -29,6 +30,12 @@ class AnnouncementsController < ApplicationController
AnnouncementSetting.first.enable_manually_sort rescue false AnnouncementSetting.first.enable_manually_sort rescue false
end end
end end
def render_400
render(:file => "#{ViewRootDir}/announcements/400.html", :layout => false, :status => 400, :formats => [:html])
end
def render_404
render(:file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => 404, :formats => [:html])
end
def comment def comment
@bulletin = Bulletin.where(:uid=>params[:uid]).first @bulletin = Bulletin.where(:uid=>params[:uid]).first
comment_val = params['comment'] comment_val = params['comment']
@ -38,6 +45,8 @@ class AnnouncementsController < ApplicationController
b.bulletin_id = @bulletin.id b.bulletin_id = @bulletin.id
b.save b.save
render :json => {} render :json => {}
else
render_404
end end
end end
def index def index
@ -1018,6 +1027,15 @@ class AnnouncementsController < ApplicationController
}, },
"total_pages" => total_pages "total_pages" => total_pages
} }
@layout_type = params[:layout_type]
if @layout_type.blank?
@layout_type = 'annc_index1'
else
@layout_type = @layout_type.to_s
if File.dirname(@layout_type) != '.'
render_400 and return
end
end
render :layout => false render :layout => false
end end

View File

@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<html lang="zh-tw">
<head>
<meta charset="UTF-8">
<title>Bad Request</title>
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
</head>
<body>
<style>
::selection {
color: #fff;
background: #040114;
}
body {
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
font-size: 100%;
background: url(/assets/error_image/404.jpg) center center fixed no-repeat;
background-size: cover;
background-color: #000;
}
#error-page {
min-height: 768px;
}
.message {
text-align: center;
position: absolute;
left: 50%;
top: 25%;
margin-left: -175px;
}
.message h1 {
margin: 0 0.2em 0 0;
color: #fff;
font-size: 8.5em;
font-weight: normal;
}
.message h2 {
margin: 0;
padding: 0;
color: #fff;
}
.message p {
color: #fff;
}
.home {
color: #fff;
}
a.home:hover {
text-decoration: none;
}
</style>
<div id="error-page">
<section class="message">
<h1>400</h1>
<h2>Bad Request</h2>
<p>Your request is invalid, <br>
get back to your home planet by <a class="home" href="/">clicking here!</a></p>
</section>
</div>
</body>
</html>

View File

@ -170,6 +170,20 @@ else
self.to_bson_key.bson_int64? self.to_bson_key.bson_int64?
end end
end end
if Mongoid::VERSION.to_i >= 7
begin
require 'mongoid/association/relatable'
module Mongoid::Association::Relatable
alias_method :org_initialize, :initialize
attr_reader :macro
def initialize(*args, &block)
@macro = self.class.to_s.demodulize.underscore.to_sym
org_initialize(*args, &block)
end
end
rescue ScriptError => e
end
end
end end
module Mongoid module Mongoid
module Findable module Findable
@ -248,7 +262,10 @@ module Orbit
alias_method :org_call, :call alias_method :org_call, :call
def call(env) def call(env)
request = ActionDispatch::Request.new(env) request = ActionDispatch::Request.new(env)
request_path = env["REQUEST_PATH"].to_s.sub(/^\/#{I18n.locale}\//, '/') request_path = env["REQUEST_PATH"].to_s
I18n.available_locales.each do |locale|
request_path = request_path.sub(/^\/#{locale}\//, '/')
end
session = env["rack.session"] session = env["rack.session"]
if (Site::DEBUG rescue false) || (Rails.env != "production" && request_path.start_with?('/admin') && (@current_user = (session[:user_id] ? User.find(session[:user_id]) : nil) rescue nil)) if (Site::DEBUG rescue false) || (Rails.env != "production" && request_path.start_with?('/admin') && (@current_user = (session[:user_id] ? User.find(session[:user_id]) : nil) rescue nil))
exception = env['action_dispatch.exception'] exception = env['action_dispatch.exception']

5
temp_file/config/boot.rb Normal file
View File

@ -0,0 +1,5 @@
# Set up gems listed in the Gemfile.
puts 'boot'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])

View File

@ -0,0 +1,726 @@
OrbitApp.cleanup_modules
begin
OrbitApp.check_module_permissions
rescue Exception => e
end
include BundlerHelper
current_locale = I18n.locale
extra_langs = File.read('config/extra_lang.txt').scan(/.*extra_.*/).select{|v| v.exclude? '#'}[0].to_s.split(/extra_language.*:|,| /).select{|v| !v.empty?}.map{|v| v.to_sym} rescue []
site = Site.first
if (site.password_failed_lock_num.nil? rescue false)
site.update({:password_failed_lock_num=> site.fields['password_failed_lock_num'].options[:default]})
end
site.reset_cache
if ModuleApp.where(:key=>'member_sign_up').count > 1
ModuleApp.where(:key=>'member_sign_up')[0...1].each{|m| m.destroy}
end
if (site.page_sets.count==0 rescue false)
site.page_sets.create()
elsif site.page_sets.count > 1
site.page_sets.skip(1).destroy
end
$member_extra_url = site.member_extra_url
if File.basename($0) != 'rake'
crontab_email=%x[crontab -l|grep 'bundle exec rake email:deliver_all'|grep `pwd`]
crontab_email_all = crontab_email.split("\n")
if crontab_email_all.count >= 1
crontab_jobs=%x[crontab -l|grep -v "cd `pwd`.*bundle exec rake email:deliver_all"].gsub(/^\n$/,'').gsub(/'/,"'\"'\"'")
system("echo '#{crontab_jobs}' | crontab -")
end
CronWorker.cron_every_minute(Email.method(:deliver_all))
nginx_exe = %x[ps -o args -C nginx| grep -E 'daemon|master'| awk '{print $4}'].split("\n")[0]
if !nginx_exe.nil?
nginx_config = %x[#{nginx_exe} -V 2>&1 | grep -o '\\-\\-conf-path=\\(.*conf\\)' | cut -d '=' -f2].sub("\n",'')
orbit_sites_config = %x[grep orbit_sites #{nginx_config}].scan(/^[\t ]*include(.*);/)[0][0].gsub(/ /,'')
current_site_config = %x[grep -H `pwd` #{orbit_sites_config}|grep -E ':\s\+root'].split(':')[0]
current_site_config_content = current_site_config.present? ? %x[cat #{current_site_config}] : ""
config_domain = site.site_settings['domain'] rescue nil
server_names = current_site_config_content.scan(/^[\t ]*server_name[\t ]*(.*);/).flatten.collect{|v| v.to_s.split(/[\t ]+/)}.flatten.sort_by{|v| v==config_domain ? 0 : v.split(".").count}.reverse
ip = UDPSocket.open {|s| s.connect("8.8.8.8", 1); s.addr.last} rescue nil
new_server_names = server_names.uniq.select{|server_name| ip == (IPSocket.getaddress(server_name) rescue nil)}
server_name = new_server_names.select{|server_name| ip != server_name}.first
if server_name.nil?
if new_server_names.count != 0
server_name = new_server_names.first
else
server_name = server_names.first
if server_name.nil?
server_name = ip || (`ip route get 8.8.8.8|xargs|awk '{print $7}'`.strip)
end
end
end
ports = current_site_config_content.scan(/^[\t ]*listen[\t ]*(.*);/).flatten.collect{|v| v.split(/[\t ]+/)}.flatten.select{|v| v.to_i.to_s == v}
port = ports.blank? ? '80' : (ports.select{|v| v=='443'}.blank? ? ports.sort_by{|v| v.to_i==80 ? -1 : v.to_i}[0] : '443')
root_url = (port=='443' ? "https://#{server_name}" : (port=='80' ? "http://#{server_name}" : "http://#{server_name}:#{port}"))
site.update_attributes(root_url: root_url)
end
if ShowForAdminMessage.first.nil?
ShowForAdminMessage.create()
end
if site.template.nil?
site.template = (Dir.glob("#{Rails.root}/app/templates/*").collect{|temp| temp.split('/').last}-['mobile']).first
site.save
end
if Page.count == 0
home = Page.new
extra_trans = {}
extra_langs.each do |extra_lang|
extra_trans[extra_lang] = 'Home'
end
home.name_translations = {:en=>"Home",:zh_tw=>"首頁"}.merge(extra_trans)
home.url = "/"
home.save
end
if Page.where(:module=>"sitemap").blank?
sitemap = Page.new
sitemap.module = "sitemap"
sitemap.page_id = "sitemap"
extra_trans = {}
extra_langs.each do |extra_lang|
extra_trans[extra_lang] = 'Sitemap'
end
sitemap.name_translations = {:en=>"Sitemap",:zh_tw=>"網站導覽"}.merge(extra_trans)
sitemap.enabled_for = ["en", "zh_tw"]
sitemap.menu_enabled_for = []
sitemap.url = "/sitemap"
sitemap.parent_page_id = Page.root.id
sitemap.save
end
termofuse = Page.where(:page_id=>'termofuse').first
page = termofuse.page_contexts.order(:version=>-1).first rescue nil
default_content_translations = {}
ac = ActionController::Base.new()
site.in_use_locales.each do |locale|
I18n.with_locale(locale) do
content = ac.render_to_string(:partial=>"pages/default_term_of_use",locals: {:current_site=>site})
default_content_translations[locale] = content
end
end
if page.nil?
page = PageContext.new
extra_trans = {}
extra_langs.each do |extra_lang|
extra_trans[extra_lang] = ''
end
page.content_translations = default_content_translations
page.version = 1
page.save
else
change_flag = false
new_content_translations = {}
site.in_use_locales.each do |locale|
if page.content_translations[locale].blank?
change_flag = true
new_content_translations[locale] = default_content_translations[locale]
end
end
if change_flag
page.content_translations = page.content_translations.merge(new_content_translations)
page.save
end
end
if termofuse.nil?
termofuse = Page.new
termofuse.module = "page_content"
termofuse.page_id = "termofuse"
termofuse.page_contexts << page
extra_trans = {}
extra_langs.each do |extra_lang|
extra_trans[extra_lang] = 'Term of use'
end
termofuse.name_translations = {:en=>"Term of use",:zh_tw=>"使用規則"}.merge(extra_trans)
termofuse.enabled_for = ["en", "zh_tw"]
termofuse.menu_enabled_for = []
termofuse.url = "/termofuse"
termofuse.parent_page_id = Page.root.id
termofuse.save
site.terms_of_use_link = "/termofuse"
site.save
end
if Workgroup.count == 0
groups = [{"title"=>"Administrator", "key"=>"admin"},
{"title"=>"Sub Managers", "key"=>"sub_managers"},
{"title"=>"Managers", "key"=>"managers"}]
groups.each do |group|
workgroup = Workgroup.new
workgroup.title = group["title"]
workgroup.key = group["key"]
workgroup.save
end
end
if Role.count==0
#teacher
role = Role.new
role.key = 'teacher'
role.title_translations = {:en=>'Teacher', :zh_tw=>'老師'}
role.save
role_status = RoleStatus.new
role_status.key = 'Full-Time'
role_status.role_id = role.id
role_status.title_translations = {:en=>'Full-Time', :zh_tw=>'專任'}
role_status.save
role_status = RoleStatus.new
role_status.key = 'Adjunct'
role_status.role_id = role.id
role_status.title_translations = {:en=>'Adjunct', :zh_tw=>'兼任'}
role_status.save
role_status = RoleStatus.new
role_status.key = 'appointment'
role_status.role_id = role.id
role_status.title_translations = {:en=>'appointment', :zh_tw=>'合聘'}
role_status.save
attribute_field = AttributeField.new
attribute_field.key = 'job_title'
attribute_field.role_id = role.id
attribute_field.title_translations = {:en=>'Job Title', :zh_tw=>'職稱'}
attribute_field.markup = 'select'
attribute_field.option_list = {
"0" => { "zh_tw" => "教授兼系主任",
"en" => "Professor and Chairman" },
"1" => { "zh_tw" => "教授",
"en" => "Professor" },
"2" => { "zh_tw" => "副教授",
"en" => "Associate Professor" },
"3" => { "zh_tw" => "助理教授",
"en" => "Assistant Professor" },
"4" => { "zh_tw" => "講師",
"en" => "Lecturer" }
}
attribute_field.typeB = {
"initial" => { "zh_tw" => "",
"en" => "" },
"option_list" => {
"0" => { "zh_tw" => "教授兼系主任",
"en" => "Professor and Chairman" },
"1" => { "zh_tw" => "教授",
"en" => "Professor" },
"2" => { "zh_tw" => "副教授",
"en" => "Associate Professor" },
"3" => { "zh_tw" => "助理教授",
"en" => "Assistant Professor" },
"4" => { "zh_tw" => "講師",
"en" => "Lecturer" }
} }
attribute_field.save
attribute_field = AttributeField.new
attribute_field.key = 'Research_Expertise'
attribute_field.role_id = role.id
attribute_field.title_translations = {:en=>'Research Expertise', :zh_tw=>'研究專長'}
attribute_field.markup = 'text_area'
attribute_field.save
attribute_field = AttributeField.new
attribute_field.key = 'Teaching_Field'
attribute_field.role_id = role.id
attribute_field.title_translations = {:en=>'Teaching Field', :zh_tw=>'授課領域'}
attribute_field.markup = 'text_area'
attribute_field.save
#satff
role = Role.new
role.key = 'staff'
role.title_translations = {:en=>'Staff', :zh_tw=>'行政人員'}
role.save
role_status = RoleStatus.new
role_status.key = 'Full-Time'
role_status.role_id = role.id
role_status.title_translations = {:en=>'Full-Time', :zh_tw=>'全職'}
role_status.save
role_status = RoleStatus.new
role_status.key = 'Part-time'
role_status.role_id = role.id
role_status.title_translations = {:en=>'Part-time', :zh_tw=>'兼職'}
role_status.save
role_status = RoleStatus.new
role_status.key = 'Contracted'
role_status.role_id = role.id
role_status.title_translations = {:en=>'Contracted', :zh_tw=>'約聘'}
role_status.save
attribute_field = AttributeField.new
attribute_field.key = 'job_title'
attribute_field.role_id = role.id
attribute_field.title_translations = {:en=>'Job Title', :zh_tw=>'職稱'}
attribute_field.markup = 'select'
attribute_field.option_list = {
"0" => { "zh_tw" => "組長",
"en" => "Group Leader" },
"1" => { "zh_tw" => "編審",
"en" => "Editor" },
"2" => { "zh_tw" => "技士",
"en" => "Technician" },
"3" => { "zh_tw" => "幹事",
"en" => "Assistant" },
"4" => { "zh_tw" => "組員",
"en" => "Clerk" } ,
"5" => { "zh_tw" => "工讀",
"en" => "Work-study" }
}
attribute_field.typeB = {
"initial" => { "zh_tw" => "",
"en" => "" },
"option_list" => {
"0" => { "zh_tw" => "組長",
"en" => "Group Leader" },
"1" => { "zh_tw" => "編審",
"en" => "Editor" },
"2" => { "zh_tw" => "技士",
"en" => "Technician" },
"3" => { "zh_tw" => "幹事",
"en" => "Assistant" },
"4" => { "zh_tw" => "組員",
"en" => "Clerk" } ,
"5" => { "zh_tw" => "工讀",
"en" => "Work-study" }
} }
attribute_field.save
attribute_field = AttributeField.new
attribute_field.key = 'Duties'
attribute_field.role_id = role.id
attribute_field.title_translations = {:en=>'Duties', :zh_tw=>'承辦業務'}
attribute_field.markup = 'text_area'
attribute_field.save
attribute_field = AttributeField.new
attribute_field.key = 'Deputy'
attribute_field.role_id = role.id
attribute_field.title_translations = {:en=>'Deputy', :zh_tw=>'代理人'}
attribute_field.markup = 'text_area'
attribute_field.save
end
if User.all.count==0
group = Workgroup.where(:key=>'admin').first
profile = MemberProfile.new
profile.first_name_translations = {:en=>'Digital', :zh_tw=>'Digital'}
profile.last_name_translations = {:en=>'Ruling', :zh_tw=>'Ruling'}
profile.email = "orbit@rulingcom.com"
profile.is_hidden = true
profile.save
user = User.new
user.workgroup = group
user.member_profile = profile
user.user_name = "rulingcom"
user.password_digest = "$2a$12$ODoNQJc22aU.U6HpWhUJIeKRYIf/3xcfzym8V.4tqt/V7pM2c9alq"
user.email = "orbit@rulingcom.com"
user.approved = true
user.beta_tester = true
user.save(:validate=>false)
profile = MemberProfile.new
profile.first_name_translations = {:en=>'Admin', :zh_tw=>'Admin'}
profile.last_name_translations = {:en=>'Admin', :zh_tw=>'Admin'}
profile.email = "service@rulingcom.com"
profile.save
user = User.new
user.workgroup = group
user.member_profile = profile
user.user_name = "admin"
user.password_digest = "$2a$12$zCT/qE6TdMUcYzA8NHhM/.G150JlazF1PRThjOuuxYt3Oi7DBrHrK"
user.email = "service@rulingcom.com"
user.approved = true
user.save(:validate=>false)
end
MemberProfileDefaultField.get_field_to_set
MemberIndexCache.destroy_all
env_pwd = ENV['PWD']
dir_name = env_pwd.split('/')[-1]
watch_dog = %x[screen -ls auto_reopen_#{dir_name}]
all_css_files = Dir["app/templates/**/*.css","app/templates/**/*.scss"]
contents = all_css_files.collect do |css_file|
[css_file,File.open(css_file, "r") { |f| f.read }]
end
s=contents.collect do |f,c|
c_tp = c
tmp = []
flag = false
c_tp = c_tp.gsub(/(^[ \t]*background(?:(?!\R).)*:[ \t]*linear-gradient(?:(?!\R|;).)*;[ \r]*(?:\/\/(?:(?!\R|;).)*)*)[ \r\t]*[\n]*([\t ]*(?:(?!\R|;).)*(?:$|;))/m) do |m|
var1 = $1
var2 = $2
if !var2.to_s.match(/^[ \t]*-pie-background/)
get_indent = var1.scan(/([ \t]*)background/).flatten[0].to_s
t = var1.sub(/background.*:/,'-pie-background:')
m = "#{var1}\n#{t}\n#{get_indent}behavior: url(\"/assets/ie_support/PIE2/PIE.htc\");\n#{var2}"
tmp << m
flag = true
end
m
end
c_tp = c_tp.gsub(/^([ \t]*border-radius:[ \t]*\d+(?:em|px|%|cm|pt|rem|vw|vh)(?:(?!\R|;).)*;[ \r]*(?:\/\/(?:(?!\R|;).)*)*)[ \r\t]*[\n]*([\t ]*(?:(?!\R|;).)*(?:$|;))/m) do |m|
var1 = $1
var2 = $2
if !var2.to_s.match(/^[ \t]*behavior: url\(\"\/assets\/ie_support\/PIE2\/PIE.htc\"\);/)
get_indent = var1.scan(/([ \t]*)border-radius/).flatten[0].to_s
m = "#{var1}\n#{get_indent}behavior: url(\"/assets/ie_support/PIE2/PIE.htc\");\n#{var2}"
tmp << m
flag = true
end
m
end
if flag
File.open(f, "w") { |f| f.write c_tp }
end
flag ? [f,tmp] : nil
end.compact
def gsub_block(c,rg,block)
return c.scan(rg) if !block
result = c.gsub(rg) do |str|
block.call(str)
end
end
def get_js_include_name(c,name,&block)
gsub_block(c,/^[ \t]*(?:<script|<%=[ \t]*javascript_include_tag)(?:(?!<script|<%=|<%#).)*[\"\/\']+#{name}[-\d\.]*(?:\.js|\.min|\")(?:(?!<script|<%=|<%#|<\/script>).)*(?:<\/script>|%>)[ \t\r]*(?:\n)*/m,block)
end
def get_css_include_name(c,name,&block)
gsub_block(c,/^[ \t]*(?:<link|<%=[ \t]*stylesheet_link_tag)(?:(?!<link|<%=|<%#).)*[\"\/\']+#{name}[-\d\.]*(?:\.js|\.min|\")(?:(?!<link|<%=|<%#).)*(?:>|%>)[ \t\r]*(?:\n)*/m,block)
end
all_html_files = Dir['app/templates/**/*.html','app/templates/**/*.erb']
all_html_contents = all_html_files.collect{|file| [file,File.open(file,'r'){|f| f.read}]}
s = all_html_contents.collect do |f,c|
flag = false
c_tp = c.clone
tmp = []
c_tp = get_js_include_name(c_tp,"(?:html5shiv|jquery|jquery\_prefix|response|ie9|cssParser|polycalc|jquery\.cycle2|jquery\.cycle2\.carousel|jquery\.cycle2\.scrollVert|jquery\.cycle2\.tile|jquery\.dataTables|dataTables\.responsive)") do |m|
flag = true
tmp << m
m = ''
end
c_tp = get_css_include_name(c_tp,"(?:responsive\.dataTables)") do |m|
flag = true
tmp << m
m = ''
end
if flag
File.open(f, "w") { |f| f.write c_tp }
end
tmp.length>0 ? [f,tmp] : nil
end.compact
all_head_files = Dir['app/templates/*/partial/_head.html.erb','app/templates/mobile/orbit_mobile/partial/_head.html.erb']
all_head_files.each do |f|
c = File.open(f, "r") { |f| f.read }
flag = false
if c.scan(/<%= render 'shared\/ie_html5_fix' %>/).length == 0
c = "<%= render 'shared/ie_html5_fix' %>\n#{c}"
flag = true
end
c = get_css_include_name(c,/\/\/(?:(?!\n).)*bootstrap/) do |m|
flag = true
v_match = m.scan(/"(.*)"/).flatten[0]
v = v_match.start_with?('http') ? v_match : ("http:"+v_match)
save_path = File.expand_path('../../assets/stylesheets/bootstrap/bootstrap.min.css',f)
system("wget #{v} -O #{save_path}")
m.sub(v_match,"bootstrap/bootstrap.min")
end
if flag
File.open(f, "w") { |f| f.write c }
end
end
#autofix DataTable width 0 issue
bs = "[ \t\r\n]*"
Dir['app/templates/**/*.erb'].each do |v|
c = File.open(v,'r'){|f| f.read}
flag = false
c = c.gsub(/(<table(?:(?!>).)*class=\"(?:(?!>).)*) nowrap((?:(?!>).)*\"(?:(?!>).)*>)/m) do |m|
flag = true
"#{$1}#{$2}"
end
c = c.gsub(/\$\('\.i-member span a'\)/) do |m|
flag = true
"$('.i-member span.member-data-value-name a')"
end
c = c.gsub(/^([ \t]*)(\$\((?:(?!\n).)*\))\.(DataTable\({#{bs}searching:#{bs}false,#{bs}paging:#{bs}false,#{bs}ordering:#{bs}false,#{bs}info:#{bs}false(?:(?!,|\n).)*(?:(?!autoWidth|}).)*)[\r\n]+^[ \t]*}\)/m) do |m|
flag = true
indent = $1
new_text = "#{indent}#{$2}.each(function(){\n#{indent} if($(this).find('thead').length!=0 && $(this).find('td').length!=0 && !$(this).hasClass('dataTable')){\n#{indent} $(this).#{$3.gsub(/^ /,' ')},\n#{indent} autoWidth: false\n#{indent} });\n#{indent} }\n#{indent}});"
new_text
end
if flag
File.open(v,'w'){|f| f.write c}
end
end
if watch_dog.scan("auto_reopen_#{dir_name}").count != 0
bundler_with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
end
if !Rails.const_defined?('Console')
Thread.new do
begin
admin_message = ShowForAdminMessage.first
save_flag = false
message_tmp = ''
PagePart.all.group_by{|v| [v.part_id,v.page_id]}.each do |k,v|
next if k[1].nil? #For popup window
if v.count > 1
page = Page.find(k[1])
all_sub_parts = []
new_v = []
v.each do |v1|
tmp_sub_parts = v1.sub_parts
if tmp_sub_parts.count == 0
v1.destroy
else
all_sub_parts += tmp_sub_parts
new_v << v1
end
end
if new_v.count > 1
if message_tmp.exclude? ("<a href=\"#{page.url}\">#{page.name}</a>")
message_tmp += "<a href=\"#{page.url}\">#{page.name}</a><br>"
end
save_flag = true
new_v.each_with_index do |p1,i1|
if i1 == 0
p1.sub_parts = all_sub_parts
p1.save!
else
p1.sub_parts = []
p1.destroy
end
end
end
end
end
if save_flag
admin_message_message_tp = admin_message.message
admin_message_message_tp << [I18n.t('please_check_for_repeate_data'),message_tmp,false]
admin_message.update_attributes(message: admin_message_message_tp)
end
broken_pages = Page.all.select{|v| v.child_page_ids.include?(v.id)}
if broken_pages.length>0
page_root = Page.root
broken_pages.each do |p|
p.child_page_ids -= [p.id]
p.save
end
end
broken_pages = Page.all.select{|v| v.id==v.parent_page_id}
if broken_pages.length>0
page_root = Page.root
broken_pages.each do |p|
p.parent_page_id = page_root.id
p.save
end
end
# Site.make_cache
if (!(site.tmp_flags.include?("uf1")) rescue false)
MemberProfile.any_of([{:is_approved => nil},{:tmp_name=>nil}]).each do |member|
if (member.user.approved rescue true)
member.is_approved = true
else
member.is_approved = false
end
begin
member.save!
rescue => e
puts "member save failed"
puts e.to_s
end
end
User.where(:member_name=>nil).each do |user|
user.fix_member_name
end
site.tmp_flags << "uf1"
site.save
end
ModuleApp.create_indexes
Category.create_indexes
Page.create_indexes
RoleStatus.create_indexes
MemberProfile.create_indexes
Role.create_indexes
User.create_indexes
AttributeValue.create_indexes
Impression.index(impressionable_type: -1,impressionable_id: -1)
Impression.index(created_at: -1)
Impression.create_indexes
PageCacheModel.create_indexes
['bulletin', 'page_context', 'web_link'].each do |app|
app_class = app.classify.constantize rescue nil
if !app_class.nil?
[{updated_at: -1}, {view_count: -1}].map{|v| app_class.index(v)}
app_class.create_indexes
end
end
image_regex = Asset::ImageRegex
#remove duplicated index
AssetTag.collection.indexes.drop_one({asset_wrap_id: 1}) rescue nil
AssetTag.collection.indexes.drop_one({asset_tag_id: -1, created_at: -1}) rescue nil
AssetTag.collection.indexes.drop_one({is_public: 1, is_admin: -1}) rescue nil
Asset.collection.indexes.drop_one({_fts: 'text', _ftsx: 1}) rescue nil
Asset.where("data" => image_regex).update_all(is_image: true)
Asset.where(:data.not => image_regex).update_all(is_image: false)
Asset.where(size: nil).each{|asset| asset.save}
AssetTag.create_indexes
SubPart.create_indexes
PagePart.create_indexes
Asset.create_indexes
AssetTag.all.update_all(assets_count: 0)
Asset.collection.aggregate([{"$match"=>{"user_id"=>{"$ne"=>nil}}},{"$group"=>{"_id"=>"$user_id","count"=>{"$sum"=> 1}}}]).to_a.each do |gp|
User.where(id: gp['_id']).update_all(assets_count: gp['count'])
end
Asset.collection.aggregate([{"$match"=>{"asset_tag_id"=>{"$ne"=>nil}}},{"$group"=>{"_id"=>{"tag_id" => "$asset_tag_id","parent_ids" => "$root_asset_tag_ids"},"count"=>{"$sum"=> 1}}}]).to_a.each do |gp|
AssetTag.where(:id => gp['_id']['tag_id']).update_all(assets_count: gp['count'])
end
flag = !User::PasswordValidTime.nil?
Email.where(template: 'reset_password_mailer/reset_user_password',"template_data.period_flag" => true).count
if (!(site.tmp_flags.include?("uf2")) rescue false)
User.all.each do |v|
m = MemberProfile.where(id: v.member_profile_id).first
if m.nil?
v.destroy
end
if flag
send_date = v.password_updated_at.nil? ? Time.now : (v.password_updated_at+User::PasswordValidTime)
v.send_password_reset_email(send_date: send_date,period_flag: true,email: m.email)
end
end
site.tmp_flags << "uf2"
site.save
end
if (!(site.tmp_flags.include?("uf3")) rescue false)
MemberProfile.all.each do |m|
m.save
end
site.tmp_flags << "uf3"
site.save
end
if (!(site.tmp_flags.include?("asf1")) rescue false)
Asset.where(:title=>nil).each do |a|
a.title_translations = I18n.available_locales.map{|l| [l.to_s, a[:data]]}.to_h
a.description_translations = I18n.available_locales.map{|l| [l.to_s, ""]}.to_h
a.save
end
site.tmp_flags << "asf1"
site.save
end
if (!(site.tmp_flags.include?("sm1")) rescue false)
Page.where(:page_id=>'sitemap').update_all("name.zh_tw"=>"網站導覽")
site.tmp_flags << "sm1"
site.save
end
if (!(site.tmp_flags.include?("sm2")) rescue false)
Page.where(:module => "login_page").each do |p|
p.instance_variable_set(:@skip_callback, true)
p.save
end
site.tmp_flags << "sm2"
site.save
end
if (!(site.tmp_flags.include?("sort1")) rescue false)
Category.where(:sort_number=>nil).each do |c|
c.sort_number = 0
c.save
end
Tag.where(:sort_number=>nil).each do |t|
t.sort_number = 0
t.save
end
site.tmp_flags << "sort1"
site.save
end
if File.exist?('start_site.sh') && File.stat('start_site.sh').mode < 0100755
tmp = File.read('start_site.sh')
File.open('start_site.sh', 'w+'){|f| f.write(tmp.gsub("\r", ""))}
File.chmod(0755, 'start_site.sh')
end
if File.exist?('close_site.sh') && File.stat('close_site.sh').mode < 0100755
tmp = File.read('close_site.sh')
File.open('close_site.sh', 'w+'){|f| f.write(tmp.gsub("\r", ""))}
File.chmod(0755, 'close_site.sh')
end
force_update_thumb = !(site.tmp_flags.include?('uf4'))
if `which fc-list`.present? && `fc-list |grep 'MingLiU'`.blank?
puts "Installing fonts for system to fix fetching template bug ..."
system("wget -q http://gitlab.tp.rulingcom.com/erictyl/install_r45_on_ubuntu_1804lts_doc/-/raw/master/fonts.tgz?inline=false -O fonts.tgz")
system("mkdir ~/.local/share/fonts -p")
system("tar -zxf fonts.tgz -C ~/.local/share && fc-cache -r")
puts "Finish installing fonts!"
force_update_thumb = true
end
Multithread.where(:key=>"fetch_design_thumbs").destroy
require File.expand_path('../fetch_design_thumb', __FILE__)
puts 'fetch_design_thumb start'
fetch_design_thumb(site,current_locale,nil,force_update_thumb)
puts 'fetch_design_thumb finish'
site.tmp_flags << "uf4" if force_update_thumb
if (!(site.tmp_flags.include?("uf5")) rescue false)
SelectOption.all.to_a.group_by{|o| [o.field_name, o.sub_part_id]}.each do |k, select_options|
select_options[1..-1].each{|o| o.destroy}
end
site.tmp_flags << "uf5"
site.save
end
if (!(site.tmp_flags.include?("uf6")) rescue false)
MemberProfileField.where(:option_list.in=>[{},nil]).each do |m|
m.save
end
site.tmp_flags << "uf6"
site.save
end
if (!(site.tmp_flags.include?("uf7")) rescue false)
MemberProfile.where(:is_approved=>true).each do |member|
if (member.user && !(member.user.approved))
member.user.update(:approved=>true)
end
end
user = User.where(:user_name=>'rulingcom').first
user.member_profile.update(:is_hidden=>true) if user && user.member_profile
site.tmp_flags << "uf7"
site.save
end
if (!(site.tmp_flags.include?("uf8")) rescue false)
users = User.where(beta_tester: true)
users.each do |user|
user.member_profile.update(:is_hidden=>true) if user.member_profile
end
site.tmp_flags << "uf8"
site.save
end
if (!(site.tmp_flags.include?("uf9")) rescue false)
Page.where(:module=>'member').each do |page|
page.custom_array_field = page.custom_array_field.to_a.sort_by{|a| a['sort_order'].to_i}
page.custom_array_field_for_show = page.custom_array_field_for_show.to_a.sort_by{|a| a['sort_order'].to_i}
page.save
end
MemberProfile.cache_member_page
site.tmp_flags << "uf9"
site.save
end
site.tmp_flags = site.tmp_flags.uniq
site.save
rescue => e
puts [e,e.backtrace]
end
end
end
end

View File

@ -0,0 +1,111 @@
# Load the Rails application.
require File.expand_path('../application', __FILE__)
require File.expand_path('../../app/helpers/orbit_helper', __FILE__)
OrbitHelper.const_set("SharedMutex",Thread.current[:shared_mutex])
OrbitHelper.const_set("SharedHash",Thread.current[:shared_hash])
# Initialize the Rails application.
Orbit::Application.initialize!
Orbit::Application.config.secret_key_base = 'acc6ffc5a7d360c9cf2a7bdb4ddf9a897942ec6767413a5c0324a0fa8b86197a96298288a66bd46d8770d8b6edf509aad65716961c2c364ce006b475e6cfd418'
site = Site.first
default_locale = (site.default_locale rescue I18n.available_locales[0]) rescue nil
if !default_locale.nil?
I18n.default_locale = default_locale
I18n.locale = default_locale
end
[MemberProfile,Page,Role,RoleStatus,AttributeValue,AttributeField,MemberProfileField,MemberProfileFieldValue,MemberProfileDefaultField,MemberRelation].each do |m|
m.class_eval{include MemberCleanCache}
end
require File.expand_path('../../app/models/page_cache_model', __FILE__) rescue nil
if (site.enable_cache rescue false)
module MongoidObs
require 'active_support/concern'
extend ActiveSupport::Concern
included do
excluded_classes = [Asset,AssetTag,Email,EmailLog,Multithread,Site,Impression,ModuleApp,OrbitMemberModule,OrbitWidget,PageCacheModel,UserAction]
excluded_classes += OrbitApp::Module::Registration.avoid_page_cache
if excluded_classes.exclude?(self)
custom_flag = false
if self == Page
def delete_page_cache
if self.changed? || self.new_record?
drop_flag = false
if self.changed != ['view_count']
if (['access_level', 'always_show_on_menu'] & self.changed).count != 0
drop_flag = true
end
end
if drop_flag
PageCacheModel.delete_all
else
PageCacheModel.where(page_id: self.id).delete
end
end
true #return true to save ok
end
elsif self == SubPart
def delete_page_cache
if self.changed? || self.new_record?
page = self.page_part.page rescue nil
if page
PageCacheModel.where(page_id: self.id).delete
end
end
true #return true to save ok
end
elsif self == PagePart
def delete_page_cache
if self.changed? || self.new_record?
page = self.page rescue nil
if page
PageCacheModel.where(page_id: self.id).delete
end
end
true #return true to save ok
end
elsif self.instance_methods.include?(:delete_page_cache_custom)
custom_flag = true
else
def delete_page_cache
if self.changed? || self.new_record?
PageCacheModel.delete_all
end
true #return true to save ok
end
end
if custom_flag
self.after_save :delete_page_cache_custom
else
self.after_save :delete_page_cache
end
end
end
end
module MongoidObsWrap
def included(m)
super(m)
m.include(MongoidObs)
end
end
Mongoid::Document.extend(MongoidObsWrap)
preload_models = Mongoid.models
preload_models.each{|v| v.include(MongoidObs)}
end
if Rails.env != "production"
load_models = %w(app/models/attribute_value.rb app/models/member_profile_field_value.rb)
load_models.each do |load_model|
load(load_model)
end
end
$Orbit_Categorized = JSON.parse(File.read("orbit_categorized_tmp.txt")) rescue {}
if ENV['worker_num'] == '0'
if defined?(PageCacheModel)
PageCacheModel.collection.drop
PageCacheModel.create_indexes
end
require File.expand_path('../do_on_startup', __FILE__)
end