update startup file
This commit is contained in:
parent
9494e37cd5
commit
80edfa528d
|
@ -548,10 +548,25 @@ if File.basename($0) != 'rake'
|
|||
User.where(:member_name=>nil).each do |user|
|
||||
user.fix_member_name
|
||||
end
|
||||
site.tmp_flags << "uf1"
|
||||
site.save
|
||||
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
|
||||
Tag.create_indexes
|
||||
Category.create_indexes
|
||||
Page.create_indexes
|
||||
RoleStatus.create_indexes
|
||||
|
@ -591,9 +606,9 @@ if File.basename($0) != 'rake'
|
|||
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
|
||||
# Email.where(template: 'reset_password_mailer/reset_user_password',"template_data.period_flag" => true).count
|
||||
if (!(site.tmp_flags.include?("uf2")) rescue false)
|
||||
flag = !User::PasswordValidTime.nil?
|
||||
User.all.each do |v|
|
||||
m = MemberProfile.where(id: v.member_profile_id).first
|
||||
if m.nil?
|
||||
|
@ -604,15 +619,13 @@ if File.basename($0) != 'rake'
|
|||
v.send_password_reset_email(send_date: send_date,period_flag: true,email: m.email)
|
||||
end
|
||||
end
|
||||
site.tmp_flags << "uf2"
|
||||
site.save
|
||||
Site.update_all("$push"=>{"tmp_flags"=>'uf2'})
|
||||
end
|
||||
if (!(site.tmp_flags.include?("uf3")) rescue false)
|
||||
MemberProfile.all.each do |m|
|
||||
m.save
|
||||
end
|
||||
site.tmp_flags << "uf3"
|
||||
site.save
|
||||
Site.update_all("$push"=>{"tmp_flags"=>'uf3'})
|
||||
end
|
||||
if (!(site.tmp_flags.include?("asf1")) rescue false)
|
||||
Asset.where(:title=>nil).each do |a|
|
||||
|
@ -620,21 +633,18 @@ if File.basename($0) != 'rake'
|
|||
a.description_translations = I18n.available_locales.map{|l| [l.to_s, ""]}.to_h
|
||||
a.save
|
||||
end
|
||||
site.tmp_flags << "asf1"
|
||||
site.save
|
||||
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"=>"網站導覽")
|
||||
site.tmp_flags << "sm1"
|
||||
site.save
|
||||
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
|
||||
site.tmp_flags << "sm2"
|
||||
site.save
|
||||
Site.update_all("$push"=>{"tmp_flags"=>'sm2'})
|
||||
end
|
||||
if (!(site.tmp_flags.include?("sort1")) rescue false)
|
||||
Category.where(:sort_number=>nil).each do |c|
|
||||
|
@ -645,8 +655,7 @@ if File.basename($0) != 'rake'
|
|||
t.sort_number = 0
|
||||
t.save
|
||||
end
|
||||
site.tmp_flags << "sort1"
|
||||
site.save
|
||||
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')
|
||||
|
@ -672,20 +681,18 @@ if File.basename($0) != 'rake'
|
|||
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
|
||||
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
|
||||
site.tmp_flags << "uf5"
|
||||
site.save
|
||||
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
|
||||
site.tmp_flags << "uf6"
|
||||
site.save
|
||||
Site.update_all("$push"=>{"tmp_flags"=>'uf6'})
|
||||
end
|
||||
if (!(site.tmp_flags.include?("uf7")) rescue false)
|
||||
MemberProfile.where(:is_approved=>true).each do |member|
|
||||
|
@ -695,29 +702,84 @@ if File.basename($0) != 'rake'
|
|||
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
|
||||
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
|
||||
site.tmp_flags << "uf8"
|
||||
site.save
|
||||
Site.update_all("$push"=>{"tmp_flags"=>'uf8'})
|
||||
end
|
||||
if (!(site.tmp_flags.include?("uf9")) rescue false)
|
||||
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
|
||||
site.tmp_flags << "uf9"
|
||||
site.save
|
||||
Site.update_all("$push"=>{"tmp_flags"=>'uf10'})
|
||||
end
|
||||
site.tmp_flags = site.tmp_flags.uniq
|
||||
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
|
||||
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
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
def fetch_design_thumb(site,locale=I18n.locale,fetch_size=nil,force_update = false)
|
||||
thread = Multithread.where(:key=>"fetch_design_thumbs").first
|
||||
if (thread && thread.status["status"] == "Finished" rescue false)
|
||||
thread.destroy
|
||||
thread = nil
|
||||
end
|
||||
if thread.nil?
|
||||
thread = Multithread.create(:key=>"fetch_design_thumbs")
|
||||
thread.status = {}
|
||||
thread.status["status"] = "fetching"
|
||||
thread.status["finish_list"] = []
|
||||
thread.save
|
||||
fetch_size = "1366*768px" if fetch_size.blank?
|
||||
Dir.glob("#{Rails.root}/app/templates/*").each do |template|
|
||||
template_json = "#{template}/template.json"
|
||||
thumb_path = "#{template}/assets/images/design_thumb.png"
|
||||
next unless File.exist?(template_json)
|
||||
next if (File.exist?(thumb_path) && !force_update)
|
||||
data = JSON.parse(File.read(template_json)) rescue {}
|
||||
design = {
|
||||
"key"=>data["key"],
|
||||
"title"=>data["title"],
|
||||
"author"=>data["author"],
|
||||
"thumbnail"=>data["thumbnail"]
|
||||
}
|
||||
Phantomjs.path
|
||||
puts "Fetching thumbnail for #{design["key"]}"
|
||||
cmd = "#{Phantomjs.path} --ignore-ssl-errors=true --ssl-protocol=any rasterize.js #{site.root_url}/#{locale}/xhr/preview_pages?template_key=#{design["key"]} #{thumb_path} #{fetch_size}"
|
||||
puts ['cmd',cmd]
|
||||
error = `#{cmd}`
|
||||
puts "Finish fetching #{design["key"]}!"
|
||||
if File.exist?(thumb_path)
|
||||
design["thumbnail"] = "assets/images/design_thumb.png"
|
||||
File.open(template_json,"w+") do |f|
|
||||
f.write(design.to_json)
|
||||
end
|
||||
thread.status["finish_list"] << design["key"]
|
||||
thread.save
|
||||
end
|
||||
if error.present?
|
||||
puts error
|
||||
thread.status["error"] = [] if thread.status["error"].nil?
|
||||
thread.status["error"] << error
|
||||
end
|
||||
end
|
||||
thread.status["status"] = "Finished"
|
||||
thread.save
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue