2010-09-28 22:08:11 +00:00
|
|
|
module Admin
|
2011-07-04 13:25:02 +00:00
|
|
|
class ImportController < BaseController
|
2010-09-28 22:08:11 +00:00
|
|
|
|
|
|
|
sections 'settings', 'site'
|
|
|
|
|
|
|
|
actions :show, :new, :create
|
|
|
|
|
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
|
|
|
|
redirect_to new_admin_import_url if @job.nil?
|
|
|
|
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
|
|
|
|
|
|
|
|
def new; end
|
|
|
|
|
|
|
|
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-07-04 13:25:02 +00:00
|
|
|
flash[:notice] = t("flash.admin.import.create.#{Locomotive.config.delayed_job ? 'notice' : 'done'}")
|
2010-09-28 22:08:11 +00:00
|
|
|
|
2010-12-16 23:42:38 +00:00
|
|
|
redirect_to Locomotive.config.delayed_job ? admin_import_url : new_admin_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
|
2010-10-19 10:20:09 +00:00
|
|
|
flash[:alert] = t('flash.admin.imports.create.alert')
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|