From 460def739be5a46e1d970973e019fa3859244d70 Mon Sep 17 00:00:00 2001 From: Mikhail Vink Date: Tue, 15 Dec 2015 22:39:08 +0100 Subject: [PATCH] Updating Jive import script with images/attachments uploader --- script/import_scripts/jive.rb | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/script/import_scripts/jive.rb b/script/import_scripts/jive.rb index bb5cedd85..16e7a4d86 100644 --- a/script/import_scripts/jive.rb +++ b/script/import_scripts/jive.rb @@ -288,6 +288,37 @@ class ImportScripts::Jive < ImportScripts::Base 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 << "

#{attachment_html(upload,item)}" + else + puts "Error: Attachment upload is not successful for #{attach_path}!" + end + end + end + topic_map[thread.messageid] = { id: thread.messageid, topic_id: thread.messageid, @@ -316,6 +347,38 @@ class ImportScripts::Jive < ImportScripts::Base next unless CATEGORY_IDS.include?(thread.containerid.to_i) 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 << "

#{attachment_html(upload,item)}" + else + puts "Error: Attachment upload is not successful for #{attach_path}!" + end + end + end + row = { id: thread.messageid, topic_id: thread_map["#{thread.threadid}"],