making other import types supported via plugins
Change-Id: I689c374060fbfcc89eb79b918ea2db283c6eb99c Reviewed-on: https://gerrit.instructure.com/2425 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
This commit is contained in:
parent
4e05ce3524
commit
96e746c31e
|
@ -30,6 +30,16 @@ class SisBatch < ActiveRecord::Base
|
|||
def self.max_attempts
|
||||
5
|
||||
end
|
||||
|
||||
def self.valid_import_types
|
||||
@valid_import_types ||= {
|
||||
"instructure_csv_zip" => {
|
||||
:name => "Instructure formatted CSV zip",
|
||||
:callback => lambda {|batch| batch.process_instructure_csv_zip},
|
||||
:default => true
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
workflow do
|
||||
state :created
|
||||
|
@ -46,13 +56,13 @@ class SisBatch < ActiveRecord::Base
|
|||
self.progress = 0
|
||||
self.save
|
||||
|
||||
case self.data[:import_type]
|
||||
when 'instructure_csv_zip'
|
||||
process_instructure_csv_zip
|
||||
else
|
||||
self.data[:error_message] = "Unrecognized import type"
|
||||
self.workflow_state = :failed
|
||||
self.save
|
||||
import_scheme = SisBatch.valid_import_types[self.data[:import_type]]
|
||||
if import_scheme.nil?
|
||||
self.data[:error_message] = "Unrecognized import type"
|
||||
self.workflow_state = :failed
|
||||
self.save
|
||||
else
|
||||
import_scheme[:callback].call(self)
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
|
@ -76,12 +86,6 @@ class SisBatch < ActiveRecord::Base
|
|||
self.workflow_state == 'importing' || self.workflow_state == 'created'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def messages?
|
||||
(self.processing_errors && self.processing_errors.length > 0) || (self.processing_warnings && self.processing_warnings.length > 0)
|
||||
end
|
||||
|
||||
def process_instructure_csv_zip
|
||||
require 'sis'
|
||||
download_zip
|
||||
|
@ -89,6 +93,12 @@ class SisBatch < ActiveRecord::Base
|
|||
finish importer.finished
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def messages?
|
||||
(self.processing_errors && self.processing_errors.length > 0) || (self.processing_warnings && self.processing_warnings.length > 0)
|
||||
end
|
||||
|
||||
def add_extension(ext)
|
||||
@temp_file.close
|
||||
new_path = @temp_file.path + ext
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
<input type="file" name="attachment" style="font-size: 1.2em;"/><br/>
|
||||
<label for="import_type">Import type</label>
|
||||
<select id="import_type" name="import_type">
|
||||
<option value="instructure_csv_zip">Instructure formatted CSV zip</option>
|
||||
<% SisBatch.valid_import_types.each do |type, data| %>
|
||||
<option value="<%= type %>"<% if data[:default] %> selected<% end %>><%= data[:name] %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
|
||||
<div id="batch_check" style="<%= hidden %>">
|
||||
|
|
Loading…
Reference in New Issue