announcement-test/temp_file/config/do_on_startup.rb

788 lines
31 KiB
Ruby
Raw Normal View History

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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'uf1'})
end
MemberProfile.where(:is_approved => nil).each do |member|
if (member.user.approved rescue true)
member.is_approved = true
else
member.is_approved = false
end
member.save
end
MemberProfile.where({:tmp_name=>nil}).each do |member|
update_key = {}
member.name_translations.each do |k, v|
update_key["tmp_name.#{k}"] = v
end
MemberProfile.where(id: member.id).update_all(update_key)
end
ModuleApp.create_indexes
2023-09-05 14:54:01 +00:00
Tag.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
2023-09-05 14:54:01 +00:00
# Email.where(template: 'reset_password_mailer/reset_user_password',"template_data.period_flag" => true).count
if (!(site.tmp_flags.include?("uf2")) rescue false)
2023-09-05 14:54:01 +00:00
flag = !User::PasswordValidTime.nil?
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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'uf2'})
end
if (!(site.tmp_flags.include?("uf3")) rescue false)
2023-09-05 14:54:01 +00:00
MemberProfile.all.each do |m|
m.save
end
Site.update_all("$push"=>{"tmp_flags"=>'uf3'})
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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'asf1'})
end
if (!(site.tmp_flags.include?("sm1")) rescue false)
Page.where(:page_id=>'sitemap').update_all("name.zh_tw"=>"網站導覽")
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'sm1'})
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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'sm2'})
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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'sort1'})
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'
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'uf5'})
end
if (!(site.tmp_flags.include?("uf6")) rescue false)
MemberProfileField.where(:option_list.in=>[{},nil]).each do |m|
m.save
end
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'uf6'})
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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'uf7'})
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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'uf8'})
end
2023-09-05 14:54:01 +00:00
if (!(site.tmp_flags.include?("uf10")) 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
2023-09-05 14:54:01 +00:00
Site.update_all("$push"=>{"tmp_flags"=>'uf10'})
end
2023-09-05 14:54:01 +00:00
if (!(site.tmp_flags.include?("uf11")) rescue false)
ModuleApp.all.each do |module_app|
module_app.update_tmp_sort_number
end
Site.update_all("$push"=>{"tmp_flags"=>'uf11'})
end
if (!(site.tmp_flags.include?("uf12")) rescue false)
Tag.where(:module_app_ids.in=>[[], nil]).each do |tag|
tag.module_app_ids = ModuleApp.where(:tag_ids=>tag.id).pluck(:id)
tag.save
end
Site.update_all("$push"=>{"tmp_flags"=>'uf12'})
end
ImpressionCount.create_indexes
if (!(site.tmp_flags.include?("imc1")) rescue false)
ImpressionCount.migrate_all
site.tmp_flags << "imc1"
site.tmp_flags << "imc2"
Site.update_all("$push"=>{"tmp_flags"=>{"$each"=>['imc1', 'imc2']}})
elsif (!(site.tmp_flags.include?("imc2")) rescue false)
if Rails.env == 'production'
rails_root = Rails.root
cpu_cores = %x(cat /proc/cpuinfo | grep processor | wc -l).sub("\n",'').to_i * 3 / 4 rescue 2
default_cpu_cores = cpu_cores
if File.exists?("#{rails_root}/cpu_cores.txt")
cpu_cores = File.read("#{rails_root}/cpu_cores.txt").force_encoding('utf-8').sub("\n",'').to_i rescue default_cpu_cores
else
begin
cpu_cores = File.read("#{rails_root}/../cpu_cores.txt").force_encoding('utf-8').sub("\n",'').to_i if (File.exists?("#{rails_root}/../cpu_cores.txt") rescue false)
rescue => e
cpu_cores = default_cpu_cores
end
end
cpu_cores = 1 if (cpu_cores < 1)
else
cpu_cores = 1
end
last_date = ImpressionCount.order_by(:date=>-1)[cpu_cores*2].date rescue nil
if last_date.nil?
ImpressionCount.migrate_all
else
mongoid_version = Mongoid.default_client.command(buildInfo: 1).first[:version].to_f rescue 2.6
if mongoid_version >= 3.6
last_date = DateTime.parse(last_date.to_s+" 00:00:00"+Time.zone.formatted_offset)
else #mongoid < 3.6 only support UTC
last_date = DateTime.parse(last_date.to_s+" 00:00:00+00:00")
end
ImpressionCount.migrate_all({"$match"=>{"created_at"=>{"$gte"=>last_date}}})
end
Site.update_all("$push"=>{"tmp_flags"=>'imc2'})
end
site.tmp_flags = Site.pluck(:tmp_flags).flatten.uniq
site.save
2023-09-05 14:54:01 +00:00
if ChecklistMainSetting.count == 0
ChecklistMainSetting.create
end
ChecklistSubSetting.create_indexes
ChecklistField.create_indexes
ChecklistRecord.create_indexes
ChecklistValue.create_indexes
rescue => e
puts [e,e.backtrace]
end
end
end
end