mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: simplify CSV file upload
This commit is contained in:
@@ -14,21 +14,12 @@ module Jobs
|
||||
end
|
||||
|
||||
def execute(args)
|
||||
filename = args[:filename]
|
||||
identifier = args[:identifier]
|
||||
chunks = args[:chunks].to_i
|
||||
filename = args[:filename]
|
||||
@current_user = User.find_by(id: args[:current_user_id])
|
||||
|
||||
raise Discourse::InvalidParameters.new(:filename) if filename.blank?
|
||||
raise Discourse::InvalidParameters.new(:identifier) if identifier.blank?
|
||||
raise Discourse::InvalidParameters.new(:chunks) if chunks <= 0
|
||||
|
||||
# merge chunks, and get csv path
|
||||
csv_path = get_csv_path(filename, identifier, chunks)
|
||||
raise Discourse::InvalidParameters.new(:filename) if filename.blank?
|
||||
|
||||
# read csv file, and send out invitations
|
||||
read_csv_file(csv_path)
|
||||
|
||||
read_csv_file("#{Invite.base_directory}/#{filename}")
|
||||
ensure
|
||||
# send notification to user regarding progress
|
||||
notify_user
|
||||
@@ -37,17 +28,6 @@ module Jobs
|
||||
FileUtils.rm_rf(csv_path) rescue nil
|
||||
end
|
||||
|
||||
def get_csv_path(filename, identifier, chunks)
|
||||
csv_path = "#{Invite.base_directory}/#{filename}"
|
||||
tmp_csv_path = "#{csv_path}.tmp"
|
||||
# path to tmp directory
|
||||
tmp_directory = File.dirname(Invite.chunk_path(identifier, filename, 0))
|
||||
# merge all chunks
|
||||
HandleChunkUpload.merge_chunks(chunks, upload_path: csv_path, tmp_upload_path: tmp_csv_path, model: Invite, identifier: identifier, filename: filename, tmp_directory: tmp_directory)
|
||||
|
||||
return csv_path
|
||||
end
|
||||
|
||||
def read_csv_file(csv_path)
|
||||
CSV.foreach(csv_path, encoding: "iso-8859-1:UTF-8") do |csv_info|
|
||||
if csv_info[0]
|
||||
|
||||
Reference in New Issue
Block a user