2010-09-28 22:08:11 +00:00
|
|
|
module Admin
|
|
|
|
class ImportsController < BaseController
|
|
|
|
|
|
|
|
sections 'settings', 'site'
|
|
|
|
|
|
|
|
actions :show, :new, :create
|
|
|
|
|
|
|
|
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-19 10:20:09 +00:00
|
|
|
identifier = store_zipfile!
|
2010-09-28 22:08:11 +00:00
|
|
|
|
2010-10-19 10:20:09 +00:00
|
|
|
if identifier
|
|
|
|
job = Locomotive::Import::Job.new(identifier, current_site)
|
2010-09-28 22:08:11 +00:00
|
|
|
Delayed::Job.enqueue job, { :site => current_site, :job_type => 'import' }
|
|
|
|
|
2010-10-12 00:12:18 +00:00
|
|
|
flash[:notice] = t('flash.admin.imports.create.notice')
|
2010-09-28 22:08:11 +00:00
|
|
|
|
|
|
|
redirect_to admin_import_url
|
2010-10-19 10:20:09 +00:00
|
|
|
else
|
|
|
|
@error = t('errors.messages.invalid_theme_file')
|
|
|
|
flash[:alert] = t('flash.admin.imports.create.alert')
|
|
|
|
|
|
|
|
render 'new'
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def store_zipfile!
|
2010-10-19 10:20:09 +00:00
|
|
|
return nil if params[:zipfile].blank?
|
|
|
|
|
2010-09-28 22:08:11 +00:00
|
|
|
file = CarrierWave::SanitizedFile.new(params[:zipfile])
|
2010-10-19 10:20:09 +00:00
|
|
|
|
|
|
|
uploader = ThemeUploader.new(current_site)
|
|
|
|
|
|
|
|
begin
|
|
|
|
uploader.store!(file)
|
|
|
|
rescue CarrierWave::IntegrityError
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
uploader.identifier
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|