2011-10-30 23:02:41 +00:00
|
|
|
module Locomotive
|
2011-07-04 13:25:02 +00:00
|
|
|
class ImportController < BaseController
|
2010-09-28 22:08:11 +00:00
|
|
|
|
|
|
|
sections 'settings', 'site'
|
|
|
|
|
2011-06-26 23:02:48 +00:00
|
|
|
skip_load_and_authorize_resource
|
|
|
|
|
|
|
|
before_filter :authorize_import
|
|
|
|
|
2010-09-28 22:08:11 +00:00
|
|
|
def show
|
|
|
|
@job = Delayed::Job.where({ :job_type => 'import', :site_id => current_site.id }).last
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2011-10-31 23:44:23 +00:00
|
|
|
redirect_to new_import_url if @job.nil?
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
2010-10-12 00:12:18 +00:00
|
|
|
format.json { render :json => {
|
|
|
|
:step => @job.nil? ? 'done' : @job.step,
|
|
|
|
:failed => @job && @job.last_error.present?
|
|
|
|
} }
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-20 10:59:12 +00:00
|
|
|
def new
|
|
|
|
end
|
2010-09-28 22:08:11 +00:00
|
|
|
|
|
|
|
def create
|
2010-10-27 00:11:44 +00:00
|
|
|
begin
|
2010-12-16 23:42:38 +00:00
|
|
|
Locomotive::Import::Job.run!(params[:zipfile], current_site, {
|
2010-10-29 15:12:57 +00:00
|
|
|
:samples => Boolean.set(params[:samples]),
|
|
|
|
:reset => Boolean.set(params[:reset])
|
|
|
|
})
|
2010-09-28 22:08:11 +00:00
|
|
|
|
2011-10-30 23:02:41 +00:00
|
|
|
flash[:notice] = t("fash.locomotive.import.create.#{Locomotive.config.delayed_job ? 'notice' : 'done'}")
|
2010-09-28 22:08:11 +00:00
|
|
|
|
2011-10-31 23:44:23 +00:00
|
|
|
redirect_to Locomotive.config.delayed_job ? import_url : new_import_url
|
2011-01-03 10:50:09 +00:00
|
|
|
rescue Exception => e
|
2011-01-29 23:20:15 +00:00
|
|
|
logger.error "[Locomotive import] #{e.message} / #{e.backtrace}"
|
2011-01-03 10:50:09 +00:00
|
|
|
|
2011-02-28 05:42:50 +00:00
|
|
|
@error = e.message
|
2011-10-30 23:02:41 +00:00
|
|
|
flash[:alert] = t('fash.locomotive.import.create.alert')
|
2010-10-19 10:20:09 +00:00
|
|
|
|
|
|
|
render 'new'
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-26 23:02:48 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def authorize_import
|
2011-06-27 15:27:07 +00:00
|
|
|
authorize! :import, Site
|
2011-06-26 23:02:48 +00:00
|
|
|
end
|
|
|
|
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
2011-11-20 10:59:12 +00:00
|
|
|
end
|