Updated new_site rake task with upload package
This commit is contained in:
parent
454e36b4ae
commit
49c1bff005
|
@ -1,4 +1,8 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
require 'fileutils'
|
||||||
|
require 'shell'
|
||||||
|
require 'open-uri'
|
||||||
|
require 'net/http/post/multipart'
|
||||||
|
|
||||||
namespace :new_site do
|
namespace :new_site do
|
||||||
task :build, [:website_name, :username, :password] => :environment do |t, args|
|
task :build, [:website_name, :username, :password] => :environment do |t, args|
|
||||||
|
@ -7,8 +11,10 @@ namespace :new_site do
|
||||||
password = "#{args.password}"
|
password = "#{args.password}"
|
||||||
Site.destroy_all
|
Site.destroy_all
|
||||||
Purchase.destroy_all
|
Purchase.destroy_all
|
||||||
Site.create( :school => "#{website_name}", :department => 'Computer Science', :valid_locales => [ 'en', 'zh_tw' ], :in_use_locales => [ 'zh_tw', 'en' ])
|
Site.create( :school => "#{website_name}", :department => 'Computer Science', :valid_locales => [ 'en', 'zh_tw' ], :in_use_locales => [ 'zh_tw', 'en' ], :frontend_open => true)
|
||||||
User.create!(:email=>'admin@rulingcom.com',:admin=>true,:user_id=>'#{username}',:password=>'#{password}')
|
upload_package
|
||||||
|
User.create!(:email=>'admin@rulingcom.com',:admin=>true,:user_id=>"#{username}",:password=>"#{password}")
|
||||||
|
puts @user = User.last
|
||||||
`mongo #{Mongoid.config.database.name} --eval "db.fs.chunks.ensureIndex({files_id: 1, n: 1})"`
|
`mongo #{Mongoid.config.database.name} --eval "db.fs.chunks.ensureIndex({files_id: 1, n: 1})"`
|
||||||
puts "Congres you can now login within url"
|
puts "Congres you can now login within url"
|
||||||
puts 'Please upload design package (/admin/designs/upload_package ) and run rake site:necessary_data'
|
puts 'Please upload design package (/admin/designs/upload_package ) and run rake site:necessary_data'
|
||||||
|
@ -16,10 +22,68 @@ namespace :new_site do
|
||||||
I18nVariable.create!( :document_class => 'language', :key => 'zh_tw', :en => 'Chinese', :zh_tw => '中文' )
|
I18nVariable.create!( :document_class => 'language', :key => 'zh_tw', :en => 'Chinese', :zh_tw => '中文' )
|
||||||
Info.create!(key: "profile", built_in: true, disabled: false, title: {"zh_tw"=>"基本欄位", "en"=>"Basic Info"}, to_search: false)
|
Info.create!(key: "profile", built_in: true, disabled: false, title: {"zh_tw"=>"基本欄位", "en"=>"Basic Info"}, to_search: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def upload_package
|
||||||
|
temp_file = Tempfile.new("temp_file")
|
||||||
|
path = File.expand_path('~')
|
||||||
|
puts original_file = File.open("#{path}/orbit_download/Orbit-Default.zip")
|
||||||
|
#if original_file.content_type == 'application/zip'
|
||||||
|
temp_file.write(original_file.read.force_encoding('UTF-8'))
|
||||||
|
temp_file.rewind
|
||||||
|
filename = File.basename(original_file,".zip")
|
||||||
|
unzip_design(temp_file, filename)
|
||||||
|
#else
|
||||||
|
# flash[:error] = "Upload file should be in zip format"
|
||||||
|
#end
|
||||||
|
temp_file.close
|
||||||
|
end
|
||||||
|
|
||||||
|
def unzip_design(file, zip_name)
|
||||||
|
Zip::ZipFile.open(file) { |zip_file|
|
||||||
|
design = Design.new.from_json(zip_file.read("#{zip_name}/info.json"))
|
||||||
|
Dir.mktmpdir('f_path') { |dir|
|
||||||
|
themes_entries = []
|
||||||
|
javascripts_entries = []
|
||||||
|
images_entries = []
|
||||||
|
|
||||||
|
zip_file.entries.each do |entry|
|
||||||
|
case (path = entry.to_s)
|
||||||
|
when /\A(#{zip_name})\/(default\.css)\z/ #for default css
|
||||||
|
design.build_css_default(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
when /\A(#{zip_name})\/(reset\.css)\z/ #for reset css
|
||||||
|
design.build_css_reset(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
when /\A(#{zip_name})\/(layout\.html)\z/ #for layout html
|
||||||
|
design.build_layout(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/ #for themes css
|
||||||
|
themes_entries << entry
|
||||||
|
when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ #for js
|
||||||
|
javascripts_entries << entry
|
||||||
|
when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img
|
||||||
|
images_entries << entry
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
['themes', 'javascripts', 'images'].each do |type|
|
||||||
|
eval("#{type}_entries").each do |entry|
|
||||||
|
eval("design.#{type}").build(:file => get_temp_file(zip_file, dir, entry))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
design.save
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_temp_file(zip_file, dir, entry)
|
||||||
|
filename = File.basename(entry.to_s)
|
||||||
|
temp_file = File.new(dir + '/' + filename, 'w+')
|
||||||
|
temp_file.write (zip_file.read entry ).force_encoding('UTF-8')
|
||||||
|
temp_file
|
||||||
|
end
|
||||||
|
|
||||||
task :necessary_data, [:website_name] => :environment do |t, args|
|
task :necessary_data, [:website_name] => :environment do |t, args|
|
||||||
site = Site.first
|
site = Site.first
|
||||||
puts website_name = "#{args.website_name}"
|
puts website_name = "#{args.website_name}"
|
||||||
puts site.title = '#{website_name}'
|
puts site.title = "#{website_name}"
|
||||||
site.save
|
site.save
|
||||||
|
|
||||||
# home_trans = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁')
|
# home_trans = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁')
|
||||||
|
|
Loading…
Reference in New Issue