From 13da6fc6a18828d53d346cb9b1bb1b9a20525bae Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Fri, 25 Oct 2013 21:55:02 +0800 Subject: [PATCH] Added a new rake task with arguments --- config/mongoid.yml | 2 +- lib/tasks/new_site.rake | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/new_site.rake diff --git a/config/mongoid.yml b/config/mongoid.yml index 9e54f531e..49a7167ce 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -24,4 +24,4 @@ production: # password: <%= ENV['MONGOID_PASSWORD'] %> # database: <%= ENV['MONGOID_DATABASE'] %> <<: *defaults - database: test_site_new + database: test_site diff --git a/lib/tasks/new_site.rake b/lib/tasks/new_site.rake new file mode 100644 index 000000000..03426b4e5 --- /dev/null +++ b/lib/tasks/new_site.rake @@ -0,0 +1,35 @@ +# encoding: utf-8 + +namespace :new_site do + task :build => :environment do |t, args| + Site.destroy_all + Purchase.destroy_all + + Site.create( :school => "#{args.website_name}", :department => 'Computer Science', :valid_locales => [ 'en', 'zh_tw' ], :in_use_locales => [ 'zh_tw', 'en' ]) + User.create!(:email=>'admin@rulingcom.com',:admin=>true,:user_id=>"#{args.username}",:password=>'#{args.password}') + `mongo #{Mongoid.config.database.name} --eval "db.fs.chunks.ensureIndex({files_id: 1, n: 1})"` + puts "Congres you can now login within url" + puts 'Please upload design package (/admin/designs/upload_package ) and run rake site:necessary_data' + I18nVariable.create!( :document_class => 'language', :key => 'en', :en => 'English', :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) + end + + task :necessary_data => :environment do + site = Site.first + site.title = "#{args.website_name}" + site.save + + # home_trans = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁') + design = Design.first + site = Site.first + site.design = design + site.save + theme = design.themes.first + home = Page.new( :design_id => design.id, :name => 'home', :is_published => true, :theme_id => theme.id, :menu_enabled_for => [] ) + + home.title_translations = {"zh_tw"=>"首頁", "en"=>"Home"} + home.save + end + +end