lib/tasks/zena.rake in zena-1.0.0.rc2 vs lib/tasks/zena.rake in zena-1.0.0.rc3

- old
+ new

@@ -110,31 +110,31 @@ else copy_assets(Zena::ROOT, RAILS_ROOT) end end - desc "Create a new site, parameters are PASSWORD, HOST, LANG" + desc "Create a new site, parameters are PASSWORD, HOST, HOST_LANG" task :mksite => :environment do # 0. set host name unless host = ENV['HOST'] puts "Please set HOST to the hostname for the new site. Aborting." else unless pass = ENV['PASSWORD'] puts "Please set PASSWORD to the admin password for the new site. Aborting." else - ENV['LANG'] ||= 'en' + ENV['HOST_LANG'] ||= 'en' host_path = "#{SITES_ROOT}/#{host}" if Site.find_by_host(host) puts "Host already exists in the database. Aborting." else - site = Site.create_for_host(host, pass, :default_lang => ENV['LANG']) + site = Site.create_for_host(host, pass, :default_lang => ENV['HOST_LANG']) if site.new_record? puts "Could not create site ! Errors:" site.errors.each do |k,v| puts "[#{k}] #{v}" end - puts "Aborting." + raise "Aborting." else # 1. create directories and symlinks `rake zena:mksymlinks HOST=#{host.inspect}` puts "Site [#{host}] created." @@ -153,12 +153,16 @@ ['public', 'data', 'log'].each do |dir| next if File.exist?("#{host_path}/#{dir}") FileUtils.mkpath("#{host_path}/#{dir}") end - # FIXME! should not symlink RAILS_ROOT but /home/app_name/app/current ... - symlink_assets(RAILS_ROOT, host_path) + if RAILS_ROOT =~ /releases\/\d+/ + root = (Pathname(RAILS_ROOT) + '../../current').to_s + else + root = RAILS_ROOT + end + symlink_assets(root, host_path) end end desc "Rename a site" task :rename_site => :environment do @@ -243,12 +247,18 @@ cmd = "tar czf #{RAILS_ROOT}/sites_data.tgz #{data_folders.join(' ')}" puts cmd puts `#{cmd}` end + desc "Load environment without running brick init code." + task :environment_without_bricks do + Bricks.no_init = true + Rake::Task["environment"].invoke + end + desc "Migrate the database through scripts in db/migrate. Target specific brick and version with BRICK=x and VERSION=x" - task :migrate => :environment do + task :migrate => :environment_without_bricks do if ENV['VERSION'] || ENV['BRICK'] ENV['BRICK'] ||= 'zena' # migrate specific bricks only mig_path = Bricks.migrations_for(ENV['BRICK']) if File.exist?(mig_path) && File.directory?(mig_path) @@ -283,10 +293,12 @@ desc 'Reset development environment (drop database, migrate, rebuild and load fixtures, clone to test)' task :reset => :environment do if RAILS_ENV == 'production' puts "You cannot reset database in production !" else + ENV['WORKER'] = 'false' + # FIXME: it seems the ENV is not propagated to the tasks below... %w{db:drop db:create zena:migrate zena:build_fixtures db:test:clone}.each do |task| puts "******************************* #{task}" Rake::Task[task].invoke end end @@ -334,38 +346,71 @@ Rake::Task[task].invoke end index_tables = Node.connection.tables.select {|t| t =~ /^idx_/ } Zena::FoxyParser.dump_fixtures(index_tables) + # Currently, inline indexes are not serialized in the fixtures and need to be + # explicitely set along with the property value. end end - desc 'Rebuild index for all sites (without SiteWorker)' + desc 'Rebuild index for all sites or site defined by HOST param.' task :rebuild_index => :environment do include Zena::Acts::Secure - - Site.all.each do |site| - # We avoid SiteWorker because it's async. - Thread.current[:visitor] = User.find_by_login_and_site_id(nil, site.id) - nodes = Node.find(:all, - :conditions => ['site_id = ?', site.id] - ) - site.rebuild_index(secure_result(nodes)) + if ENV['HOST'] + sites = [Site.find_by_host(ENV['HOST'])] + else + sites = Site.all end + sites.each do |site| + if ENV['WORKER'] == 'false' || RAILS_ENV == 'test' + # We avoid SiteWorker by passing nodes. + Thread.current[:visitor] = site.any_admin + nodes = Node.find(:all, + :conditions => ['site_id = ?', site.id] + ) + site.rebuild_index(secure_result(nodes)) + else + # We try to use the site worker. + Thread.current[:visitor] = site.any_admin + site.rebuild_index + end + end end - desc 'Rebuild fullpath for all sites (without SiteWorker)' + desc 'Rebuild fullpath for all sites or site defined by HOST param.' task :rebuild_fullpath => :environment do include Zena::Acts::Secure - - Site.all.each do |site| - # We avoid SiteWorker because it's async. - Thread.current[:visitor] = User.find_by_login_and_site_id(nil, site.id) + if ENV['HOST'] + sites = [Site.find_by_host(ENV['HOST'])] + else + sites = Site.all + end + sites.each do |site| + # Does not use SiteWorker. site.rebuild_fullpath end end + desc 'Rebuild vhash for all sites or site defined by HOST param.' + task :rebuild_vhash => :environment do + include Zena::Acts::Secure + if ENV['HOST'] + sites = [Site.find_by_host(ENV['HOST'])] + else + sites = Site.all + end + sites.each do |site| + # We avoid SiteWorker by passing nodes. + Thread.current[:visitor] = site.any_admin + nodes = Node.find(:all, + :conditions => ['site_id = ?', site.id] + ) + site.rebuild_vhash(secure_result(nodes)) + end + end + Rake::RDocTask.new do |rdoc| files = ['README', 'doc/README_FOR_APP', 'CREDITS', 'MIT-LICENSE', 'app/**/*.rb', 'lib/**/*.rb'] rdoc.rdoc_files.add(files) rdoc.main = "doc/README_FOR_APP" # page to start on @@ -474,19 +519,19 @@ desc "Create the database, migrate, create 'localhost' site and start application (in production environment by default)" task :init do # FIXME: how to run sub-task ENV['RAILS_ENV'] = RAILS_ENV || 'production' ENV['HOST'] ||= 'localhost' - ENV['LANG'] = ENV['LANG'].to_s - ENV['LANG'] = 'en' if ENV['LANG'].empty? + ENV['HOST_LANG'] = ENV['HOST_LANG'].to_s + ENV['HOST_LANG'] = 'en' if ENV['HOST_LANG'].empty? ENV['PASSWORD'] ||= 'admin' Rake::Task["db:create"].invoke Rake::Task["zena:migrate"].invoke # We cannot use 'invoke' here because the User class needs to be reloaded - env = %w{RAILS_ENV HOST LANG PASSWORD}.map{|e| "#{e}=#{ENV[e]}"}.join(' ') + env = %w{RAILS_ENV HOST HOST_LANG PASSWORD}.map{|e| "#{e}=#{ENV[e]}"}.join(' ') cmd = "rake zena:mksite #{env}" puts cmd system(cmd) if RUBY_PLATFORM =~ /mswin32/ @@ -502,7 +547,12 @@ cmd = "ruby script/server -e #{ENV['RAILS_ENV']} -p 3000" puts cmd exec cmd end end +end # zena +namespace :gettext do + def files_to_translate + Dir.glob("{app,lib,bricks,config,locale}/**/*.{rb,erb,rjs,rhtml}") + end end