146 lines
4.2 KiB
Ruby
146 lines
4.2 KiB
Ruby
# encoding: utf-8
|
|
require 'fileutils'
|
|
class Filefield
|
|
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
field :title, :type=> String ,default:"patchfile"
|
|
field :file_show, :type=> Hash ,default:{"ckeditor"=>0,"site-preference(two-site-logo)"=>0,"member"=>0,"accessibility"=>0}
|
|
field :recovery, :type=> String , default:"false"
|
|
after_update :updatefile
|
|
|
|
|
|
def enabled_for?(lang)
|
|
if lang.nil?
|
|
return true
|
|
else
|
|
return self.choose_lang.include?(lang)
|
|
end
|
|
end
|
|
def lastpath dir_path
|
|
dir_path = dir_path.gsub('\\','/')
|
|
dir_arr= dir_path.split('/')
|
|
dir_str=''
|
|
dir_arr.delete_at(-1)
|
|
dir_arr.each_with_index do |path,index|
|
|
dir_str = dir_str + path
|
|
if index != dir_arr.count - 1
|
|
dir_str = dir_str +"/"
|
|
end
|
|
end
|
|
return dir_str
|
|
end
|
|
def updatefile
|
|
self.file_show.each do |key,value|
|
|
if value == 1
|
|
@model_path = Rails.root.to_s + '/app/models/'
|
|
@helper_path = Rails.root.to_s + '/app/helpers/'
|
|
@views_path = Rails.root.to_s + '/app/views/'
|
|
@controller_path = Rails.root.to_s + '/app/controllers/'
|
|
if key == "ckeditor"
|
|
@app_path = File.expand_path(__dir__)
|
|
@app_path = lastpath(@app_path)
|
|
@app_path = lastpath(@app_path)
|
|
@ckeditor_path = Rails.root.to_s + '/app/assets/javascripts/ckeditor/'
|
|
puts 'copying CKEDITOR'
|
|
begin
|
|
Dir.chdir(@ckeditor_path)
|
|
File.rename('config.js.erb','config.js.erb_back')
|
|
rescue
|
|
puts Dir.pwd
|
|
end
|
|
FileUtils.cd(@app_path+'/updatefiles/')
|
|
begin
|
|
FileUtils.cp('config.js.erb' , @ckeditor_path)
|
|
puts @ckeditor_path
|
|
rescue
|
|
puts Dir.pwd
|
|
puts 'error copy'
|
|
end
|
|
elsif key == "site-preference(two-site-logo)"
|
|
@app_path = File.expand_path(__dir__)
|
|
@app_path = lastpath(@app_path)
|
|
@app_path = lastpath(@app_path)
|
|
puts @app_path
|
|
puts 'copying site'
|
|
begin
|
|
Dir.chdir(@model_path)
|
|
File.rename('site.rb','site.rb_back')
|
|
Dir.chdir(@helper_path)
|
|
File.rename('application_helper.rb','application_helper.rb_back')
|
|
Dir.chdir(@views_path+'admin/sites/')
|
|
File.rename('preference.html.erb','preference.html.erb_back')
|
|
rescue
|
|
puts Dir.pwd
|
|
end
|
|
FileUtils.cd(@app_path+'/updatefiles/')
|
|
begin
|
|
FileUtils.cp('site.rb' , @model_path)
|
|
FileUtils.cp('application_helper.rb' , @helper_path)
|
|
FileUtils.cd('admin/')
|
|
FileUtils.cp('preference.html.erb',@views_path+'admin/sites/')
|
|
rescue
|
|
puts Dir.pwd
|
|
Dir.chdir(Rails.root.to_s)
|
|
puts 'error copy'
|
|
end
|
|
elsif key == "member"
|
|
@app_path = File.expand_path(__dir__)
|
|
@app_path = lastpath(@app_path)
|
|
@app_path = lastpath(@app_path)
|
|
begin
|
|
Dir.chdir(@model_path)
|
|
File.rename('member_profile.rb','member_profile.rb_back')
|
|
Dir.chdir(@controller_path+'admin/')
|
|
File.rename('members_controller.rb','members_controller.rb_back')
|
|
Dir.chdir(@views_path+'admin/members/')
|
|
File.rename('_user_basic_passwd.html.erb','_user_basic_passwd.html.erb_back')
|
|
rescue
|
|
puts Dir.pwd
|
|
end
|
|
FileUtils.cd(@app_path+'/updatefiles/')
|
|
puts 'copying member'
|
|
begin
|
|
FileUtils.cp('member_profile.rb' , @model_path)
|
|
FileUtils.cd('admin/')
|
|
FileUtils.cp('members_controller.rb' , @controller_path+'admin/')
|
|
FileUtils.cp('_user_basic_passwd.html.erb' , @views_path+'admin/members/')
|
|
rescue
|
|
puts Dir.pwd
|
|
Dir.chdir(Rails.root.to_s)
|
|
puts 'error copy'
|
|
end
|
|
elsif key == "accessibility"
|
|
@app_path = File.expand_path(__dir__)
|
|
@app_path = lastpath(@app_path)
|
|
@app_path = lastpath(@app_path)
|
|
begin
|
|
Dir.chdir(@views_path+'layouts/')
|
|
File.rename('back_end.html.erb','back_end.html.erb_back')
|
|
Dir.chdir(@views_path+'page_parts/')
|
|
File.rename('_form.html.erb','_form.html.erb_back')
|
|
rescue
|
|
puts Dir.pwd
|
|
end
|
|
FileUtils.cd(@app_path+'/updatefiles/accessibility/')
|
|
puts 'copying accessibility'
|
|
begin
|
|
FileUtils.cp('back_end.html.erb' , @views_path+'layouts/')
|
|
FileUtils.cp('_form.html.erb' , @views_path+'page_parts/')
|
|
FileUtils.cp_r('jquery-ui-1.12.1/' , ENV['PWD'] + '/app/assets/stylesheets/lib/jquery-ui-1.12.1/')
|
|
rescue
|
|
puts Dir.pwd
|
|
Dir.chdir(Rails.root.to_s)
|
|
puts 'error copy'
|
|
end
|
|
end
|
|
Dir.chdir(Rails.root.to_s)
|
|
FileUtils.cd(Rails.root.to_s)
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|