lib/tasks/zena.rake in zena-1.2.4 vs lib/tasks/zena.rake in zena-1.2.5
- old
+ new
@@ -141,11 +141,46 @@
end
end
end
end
end
+
+ desc "Create a new site alias, parameters are ALIAS, HOST"
+ task :mkalias => :environment do
+ # 0. set host name
+ unless host = ENV['HOST']
+ puts "Please set HOST to the hostname for the master site. Aborting."
+ else
+ unless ali = ENV['ALIAS']
+ puts "Please set ALIAS to the hostname of the alias site. Aborting."
+ else
+ if Site.find_by_host(ali)
+ puts "Host alias already exists in the database. Aborting."
+ else
+ unless site = Site.find_by_host(host)
+ puts "Master host not found in the database. Aborting."
+ else
+ alias_site = site.create_alias(ali)
+
+ if alias_site.new_record?
+ puts "Could not create site alias ! Errors:"
+ alias_site.errors.each do |k,v|
+ puts "[#{k}] #{v}"
+ end
+ raise "Aborting."
+ else
+ # 1. create directories and symlinks
+ `rake zena:mksymlinks HOST=#{ali.inspect}`
+ puts "Site alias [#{ali} => #{host}] created."
+ end
+ end
+ end
+ end
+ end
+ end
+
desc "Create symlinks for a site"
task :mksymlinks => :zena_config do
unless host = ENV['HOST']
puts "Please set HOST to the hostname for which you want to update the symlinks. Aborting."
else
@@ -360,15 +395,15 @@
include Zena::Acts::Secure
if ENV['HOST']
sites = [Site.find_by_host(ENV['HOST'])]
else
- sites = Site.all
+ sites = Site.master_sites
end
sites.each do |site|
- Thread.current[:visitor] = site.any_admin
+ setup_visitor(site.any_admin, site)
if ENV['WORKER'] == 'false' || RAILS_ENV == 'test'
# We avoid SiteWorker by passing nodes.
nodes = Node.find(:all,
:conditions => ['site_id = ?', site.id]
@@ -385,11 +420,11 @@
task :rebuild_fullpath => :environment do
include Zena::Acts::Secure
if ENV['HOST']
sites = [Site.find_by_host(ENV['HOST'])]
else
- sites = Site.all
+ sites = Site.master_sites
end
sites.each do |site|
# Does not use SiteWorker.
site.rebuild_fullpath
end
@@ -399,14 +434,14 @@
task :rebuild_vhash => :environment do
include Zena::Acts::Secure
if ENV['HOST']
sites = [Site.find_by_host(ENV['HOST'])]
else
- sites = Site.all
+ sites = Site.master_sites
end
sites.each do |site|
# We avoid SiteWorker by passing nodes.
- Thread.current[:visitor] = site.any_admin
+ setup_visitor(site.any_admin, site)
nodes = Node.find(:all,
:conditions => ['site_id = ?', site.id]
)
site.rebuild_vhash(secure_result(nodes))
end