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
|
2012-01-17 10:24:54 +00:00
|
|
|
url, site_name_or_id, samples, reset = ENV['URL'], ENV['SITE'], (Boolean.set(ENV['SAMPLES']) || false), (Boolean.set(ENV['RESET']) || false)
|
2011-07-04 13:25:02 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-01-17 10:24:54 +00:00
|
|
|
::Locomotive::Import::Job.run!(url, site, { :samples => samples, :reset => reset })
|
2011-07-04 13:25:02 +00:00
|
|
|
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
|
|
|
|
|
2012-01-25 21:07:10 +00:00
|
|
|
desc "Upgrade a site to i18n. Requires SITE (name or id) and LOCALE (by default: en) as env variables"
|
|
|
|
task :i18n => :environment do
|
|
|
|
locale, site_name_or_id = ENV['LOCALE'] || 'en', ENV['SITE']
|
|
|
|
|
|
|
|
site = Locomotive::Site.find(site_name_or_id) || Locomotive::Site.where(:name => site_name_or_id).first
|
|
|
|
|
|
|
|
raise 'Site not found' if site.nil?
|
|
|
|
|
|
|
|
site.locales ||= [locale]
|
|
|
|
|
|
|
|
# sites
|
|
|
|
%w(seo_title meta_keywords meta_description).each do |attribute|
|
|
|
|
if !site.send(:"#{attribute}_translations").respond_to?(:keys)
|
|
|
|
site.changed_attributes.store attribute, site.attributes[attribute]
|
|
|
|
site.attributes.store attribute, { locale => site.attributes[attribute] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
site.save!
|
|
|
|
|
|
|
|
Locomotive::Page.skip_callback(:validate, :before)
|
|
|
|
Locomotive::Page.skip_callback(:save, :after)
|
|
|
|
|
|
|
|
Locomotive::Page.all.each do |page|
|
2012-01-26 01:41:31 +00:00
|
|
|
%w(title slug fullpath raw_template seo_title meta_keywords meta_description serialized_template template_dependencies snippet_dependencies).each do |attribute|
|
|
|
|
if !page.send(:"#{attribute}_translations").respond_to?(:keys)
|
|
|
|
page.changed_attributes.store attribute, page.attributes[attribute]
|
|
|
|
page.attributes.store attribute, { locale => page.attributes[attribute] }
|
2012-01-25 21:07:10 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-26 01:41:31 +00:00
|
|
|
page.save(:validate => false)
|
2012-01-25 21:07:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-17 21:32:54 +00:00
|
|
|
end
|
|
|
|
|
2011-11-19 14:47:56 +00:00
|
|
|
end
|