mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Attachments can be not found
This commit is contained in:
@ -199,28 +199,30 @@ class ImportScripts::Nabble < ImportScripts::Base
|
|||||||
def process_attachments(txt, postid)
|
def process_attachments(txt, postid)
|
||||||
txt.gsub!(/<nabble_img src="(.*?)" (.*?)>/m) do |match|
|
txt.gsub!(/<nabble_img src="(.*?)" (.*?)>/m) do |match|
|
||||||
basename = Regexp.last_match[1]
|
basename = Regexp.last_match[1]
|
||||||
fn = File.join('/tmp/nab', basename)
|
get_attachment_upload(basename, postid) do |upload|
|
||||||
|
@uploader.embedded_image_html(upload)
|
||||||
binary = @client.exec("SELECT content FROM file_node WHERE name='#{basename}' AND node_id = #{postid}")[0]['content']
|
end
|
||||||
File.open(fn, 'wb') { |f|
|
|
||||||
f.write(PG::Connection.unescape_bytea(binary))
|
|
||||||
}
|
|
||||||
upload = @uploader.create_upload(0, fn, basename)
|
|
||||||
@uploader.embedded_image_html(upload)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
txt.gsub!(/<nabble_a href="(.*?)">(.*?)<\/nabble_a>/m) do |match|
|
txt.gsub!(/<nabble_a href="(.*?)">(.*?)<\/nabble_a>/m) do |match|
|
||||||
basename = Regexp.last_match[1]
|
basename = Regexp.last_match[1]
|
||||||
fn = File.join('/tmp/nab', basename)
|
get_attachment_upload(basename, postid) do |upload|
|
||||||
|
@uploader.attachment_html(upload, basename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
txt
|
||||||
|
end
|
||||||
|
|
||||||
binary = @client.exec("SELECT content FROM file_node WHERE name='#{basename}' AND node_id = #{postid}")[0]['content']
|
def get_attachment_upload(basename, postid)
|
||||||
|
contents = @client.exec("SELECT content FROM file_node WHERE name='#{basename}' AND node_id = #{postid}")
|
||||||
|
if contents.any?
|
||||||
|
binary = contents[0]['content']
|
||||||
|
fn = File.join('/tmp/nab', basename)
|
||||||
File.open(fn, 'wb') { |f|
|
File.open(fn, 'wb') { |f|
|
||||||
f.write(PG::Connection.unescape_bytea(binary))
|
f.write(PG::Connection.unescape_bytea(binary))
|
||||||
}
|
}
|
||||||
upload = @uploader.create_upload(0, fn, basename)
|
yield @uploader.create_upload(0, fn, basename)
|
||||||
@uploader.attachment_html(upload, basename)
|
|
||||||
end
|
end
|
||||||
txt
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def import_replies
|
def import_replies
|
||||||
|
Reference in New Issue
Block a user