mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 09:29:25 +08:00
FIX: mbox importer and rake task were broken
This commit is contained in:
parent
f60b10d090
commit
ee18d9ace0
@ -890,12 +890,12 @@ module Email
|
|||||||
|
|
||||||
def create_post_with_attachments(options = {})
|
def create_post_with_attachments(options = {})
|
||||||
# deal with attachments
|
# deal with attachments
|
||||||
options[:raw] = add_attachments(options[:raw], options[:user], options)
|
options[:raw] = add_attachments(options[:raw], options[:user].id, options)
|
||||||
|
|
||||||
create_post(options)
|
create_post(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_attachments(raw, user, options = {})
|
def add_attachments(raw, user_id, options = {})
|
||||||
rejected_attachments = []
|
rejected_attachments = []
|
||||||
attachments.each do |attachment|
|
attachments.each do |attachment|
|
||||||
tmp = Tempfile.new(["discourse-email-attachment", File.extname(attachment.filename)])
|
tmp = Tempfile.new(["discourse-email-attachment", File.extname(attachment.filename)])
|
||||||
@ -904,7 +904,7 @@ module Email
|
|||||||
File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded }
|
File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded }
|
||||||
# create the upload for the user
|
# create the upload for the user
|
||||||
opts = { for_group_message: options[:is_group_message] }
|
opts = { for_group_message: options[:is_group_message] }
|
||||||
upload = UploadCreator.new(tmp, attachment.filename, opts).create_for(user.id)
|
upload = UploadCreator.new(tmp, attachment.filename, opts).create_for(user_id)
|
||||||
if upload&.valid?
|
if upload&.valid?
|
||||||
# try to inline images
|
# try to inline images
|
||||||
if attachment.content_type&.start_with?("image/")
|
if attachment.content_type&.start_with?("image/")
|
||||||
|
@ -93,6 +93,7 @@ module ImportScripts::Mbox
|
|||||||
next if all_records_exist?(:posts, rows.map { |row| row['msg_id'] })
|
next if all_records_exist?(:posts, rows.map { |row| row['msg_id'] })
|
||||||
|
|
||||||
create_posts(rows, total: total_count, offset: offset) do |row|
|
create_posts(rows, total: total_count, offset: offset) do |row|
|
||||||
|
begin
|
||||||
if row['email_date'].blank?
|
if row['email_date'].blank?
|
||||||
puts "Date is missing. Skipping #{row['msg_id']}"
|
puts "Date is missing. Skipping #{row['msg_id']}"
|
||||||
nil
|
nil
|
||||||
@ -101,6 +102,9 @@ module ImportScripts::Mbox
|
|||||||
else
|
else
|
||||||
map_reply(row)
|
map_reply(row)
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
puts "Failed to map post for #{row['msg_id']}", e, e.backtrace.join("\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user