mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:40:00 +08:00
Merge pull request #3924 from mikhailvink/master
Updating Jive import script with images/attachments uploader
This commit is contained in:
commit
a7605b4e25
|
@ -287,6 +287,37 @@ class ImportScripts::Jive < ImportScripts::Base
|
||||||
|
|
||||||
thread_map[thread.threadid] = thread.messageid
|
thread_map[thread.threadid] = thread.messageid
|
||||||
|
|
||||||
|
#IMAGE UPLOADER
|
||||||
|
if thread.imagecount
|
||||||
|
Dir.foreach("/var/www/discourse/script/import_scripts/jive/img/#{thread.messageid}") do |item|
|
||||||
|
next if item == '.' or item == '..' or item == '.DS_Store'
|
||||||
|
photo_path = "/var/www/discourse/script/import_scripts/jive/img/#{thread.messageid}/#{item}"
|
||||||
|
upload = create_upload(thread.userid, photo_path, File.basename(photo_path))
|
||||||
|
if upload.persisted?
|
||||||
|
puts "Image upload is successful for #{photo_path}, new path is #{upload.url}!"
|
||||||
|
thread.body.gsub!(item,upload.url)
|
||||||
|
else
|
||||||
|
puts "Error: Image upload is not successful for #{photo_path}!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#ATTACHMENT UPLOADER
|
||||||
|
if thread.attachmentcount
|
||||||
|
Dir.foreach("/var/www/discourse/script/import_scripts/jive/attach/#{thread.messageid}") do |item|
|
||||||
|
next if item == '.' or item == '..' or item == '.DS_Store'
|
||||||
|
attach_path = "/var/www/discourse/script/import_scripts/jive/attach/#{thread.messageid}/#{item}"
|
||||||
|
upload = create_upload(thread.userid, attach_path, File.basename(attach_path))
|
||||||
|
if upload.persisted?
|
||||||
|
puts "Attachment upload is successful for #{attach_path}, new path is #{upload.url}!"
|
||||||
|
thread.body.gsub!(item,upload.url)
|
||||||
|
thread.body << "<br/><br/> #{attachment_html(upload,item)}"
|
||||||
|
else
|
||||||
|
puts "Error: Attachment upload is not successful for #{attach_path}!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
topic_map[thread.messageid] = {
|
topic_map[thread.messageid] = {
|
||||||
id: thread.messageid,
|
id: thread.messageid,
|
||||||
topic_id: thread.messageid,
|
topic_id: thread.messageid,
|
||||||
|
@ -315,6 +346,38 @@ class ImportScripts::Jive < ImportScripts::Base
|
||||||
next unless CATEGORY_IDS.include?(thread.containerid.to_i)
|
next unless CATEGORY_IDS.include?(thread.containerid.to_i)
|
||||||
|
|
||||||
if thread.parentmessageid
|
if thread.parentmessageid
|
||||||
|
|
||||||
|
#IMAGE UPLOADER
|
||||||
|
if thread.imagecount
|
||||||
|
Dir.foreach("/var/www/discourse/script/import_scripts/jive/img/#{thread.messageid}") do |item|
|
||||||
|
next if item == '.' or item == '..' or item == '.DS_Store'
|
||||||
|
photo_path = "/var/www/discourse/script/import_scripts/jive/img/#{thread.messageid}/#{item}"
|
||||||
|
upload = create_upload(thread.userid, photo_path, File.basename(photo_path))
|
||||||
|
if upload.persisted?
|
||||||
|
puts "Image upload is successful for #{photo_path}, new path is #{upload.url}!"
|
||||||
|
thread.body.gsub!(item,upload.url)
|
||||||
|
else
|
||||||
|
puts "Error: Image upload is not successful for #{photo_path}!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#ATTACHMENT UPLOADER
|
||||||
|
if thread.attachmentcount
|
||||||
|
Dir.foreach("/var/www/discourse/script/import_scripts/jive/attach/#{thread.messageid}") do |item|
|
||||||
|
next if item == '.' or item == '..' or item == '.DS_Store'
|
||||||
|
attach_path = "/var/www/discourse/script/import_scripts/jive/attach/#{thread.messageid}/#{item}"
|
||||||
|
upload = create_upload(thread.userid, attach_path, File.basename(attach_path))
|
||||||
|
if upload.persisted?
|
||||||
|
puts "Attachment upload is successful for #{attach_path}, new path is #{upload.url}!"
|
||||||
|
thread.body.gsub!(item,upload.url)
|
||||||
|
thread.body << "<br/><br/> #{attachment_html(upload,item)}"
|
||||||
|
else
|
||||||
|
puts "Error: Attachment upload is not successful for #{attach_path}!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
row = {
|
row = {
|
||||||
id: thread.messageid,
|
id: thread.messageid,
|
||||||
topic_id: thread_map["#{thread.threadid}"],
|
topic_id: thread_map["#{thread.threadid}"],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user