2011-06-17 21:32:54 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2011-06-18 08:31:43 +00:00
|
|
|
require 'locomotive'
|
2011-08-04 16:19:39 +00:00
|
|
|
require 'highline/import'
|
2011-06-18 08:31:43 +00:00
|
|
|
|
2011-05-27 15:19:20 +00:00
|
|
|
namespace :locomotive do
|
|
|
|
|
|
|
|
desc 'Fetch the Locomotive default site template for the installation'
|
|
|
|
task :fetch_default_site_template => :environment do
|
|
|
|
puts "Downloading default site template from '#{Locomotive::Import.DEFAULT_SITE_TEMPLATE}'"
|
|
|
|
`curl -L -s -o #{Rails.root}/tmp/default_site_template.zip #{Locomotive::Import.DEFAULT_SITE_TEMPLATE}`
|
|
|
|
puts '...done'
|
|
|
|
end
|
|
|
|
|
2011-07-07 14:59:50 +00:00
|
|
|
desc 'Rebuild the serialized template of all the site pages'
|
2011-07-18 21:11:22 +00:00
|
|
|
task :rebuild_serialized_page_templates => :environment do
|
2011-10-30 23:02:41 +00:00
|
|
|
Locomotive::Site.all.each do |site|
|
2011-07-19 09:49:15 +00:00
|
|
|
pages = site.pages.to_a
|
|
|
|
while !pages.empty? do
|
|
|
|
page = pages.pop
|
|
|
|
begin
|
|
|
|
page.send :_parse_and_serialize_template
|
|
|
|
page.save
|
|
|
|
puts "[#{site.name}] processing...#{page.title}"
|
|
|
|
rescue TypeError => e
|
|
|
|
pages.insert(0, page)
|
|
|
|
end
|
|
|
|
end
|
2011-07-07 14:59:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-04 13:25:02 +00:00
|
|
|
desc 'Import a remote template described by its URL -- 2 options: SITE=name or id, RESET=by default false'
|
|
|
|
task :import => :environment do
|
|
|
|
url, site_name_or_id, reset = ENV['URL'], ENV['SITE'], Boolean.set(ENV['RESET']) || false
|
|
|
|
|
|
|
|
if url.blank? || (url =~ /https?:\/\//).nil?
|
|
|
|
raise "URL is missing or it is not a valid http url."
|
|
|
|
end
|
|
|
|
|
2011-10-30 23:02:41 +00:00
|
|
|
site = Locomotive::Site.find(site_name_or_id) || Locomotive::Site.where(:name => site_name_or_id).first || Locomotive::Site.first
|
2011-07-04 13:25:02 +00:00
|
|
|
|
|
|
|
if site.nil?
|
|
|
|
raise "No site found. Please give a correct value (name or id) for the SITE env variable."
|
|
|
|
end
|
|
|
|
|
|
|
|
::Locomotive::Import::Job.run!(url, site, { :samples => true, :reset => reset })
|
|
|
|
end
|
|
|
|
|
2011-08-04 16:19:39 +00:00
|
|
|
desc 'Add a new admin user (NOTE: currently only supports adding user to first site)'
|
|
|
|
task :add_admin => :environment do
|
|
|
|
name = ask('Display name: ') { |q| q.echo = true }
|
|
|
|
email = ask('Email address: ') { |q| q.echo = true }
|
|
|
|
password = ask('Password: ') { |q| q.echo = '*' }
|
|
|
|
password_confirm = ask('Confirm password: ') { |q| q.echo = '*' }
|
|
|
|
|
2011-10-30 23:02:41 +00:00
|
|
|
account = Locomotive::Account.create :email => email, :password => password, :password_confirmation => password_confirm, :name => name
|
2011-08-04 16:19:39 +00:00
|
|
|
|
|
|
|
# TODO: this should be changed to work for multi-sites (see desc)
|
2011-10-30 23:02:41 +00:00
|
|
|
site = Locomotive::Site.first
|
2011-08-04 16:19:39 +00:00
|
|
|
site.memberships.build :account => account, :role => 'admin'
|
|
|
|
site.save!
|
|
|
|
end
|
|
|
|
|
2011-06-17 21:32:54 +00:00
|
|
|
namespace :upgrade do
|
|
|
|
|
2011-07-08 13:03:48 +00:00
|
|
|
desc "Index page is sometimes after the 404 error page. Fix this"
|
|
|
|
task :place_index_before_404 => :environment do
|
2011-10-30 23:02:41 +00:00
|
|
|
Locomotive::Site.all.each do |site|
|
2011-07-08 13:03:48 +00:00
|
|
|
site.pages.root.first.update_attribute :position, 0
|
|
|
|
site.pages.not_found.first.update_attribute :position, 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-19 14:47:56 +00:00
|
|
|
desc "Namespace collections"
|
|
|
|
task :namespace_collections do
|
|
|
|
db = Mongoid.config.master['sites'].db
|
|
|
|
db.collections.each do |collection|
|
|
|
|
next if collection.name =~ /^locomotive_/ # already namespaced
|
|
|
|
|
|
|
|
new_name = "locomotive_#{collection.name}"
|
|
|
|
new_name = "locomotive_content_assets" if collection.name =~ /^assets/
|
|
|
|
|
|
|
|
puts "renaming #{collection.name} into #{new_name}"
|
|
|
|
collection.rename_collection new_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-17 21:32:54 +00:00
|
|
|
end
|
|
|
|
|
2011-11-19 14:47:56 +00:00
|
|
|
end
|