v0.25 Post image handling tweaks
This commit is contained in:
		| @@ -1,5 +1,5 @@ | |||||||
| # gossamer threads migration-import code | # gossamer threads migration-import code | ||||||
| # v0.24 | # v0.25 | ||||||
|  |  | ||||||
| require 'mysql2' | require 'mysql2' | ||||||
| require 'open-uri' | require 'open-uri' | ||||||
| @@ -351,21 +351,25 @@ class GossamerForumsImporter < ImportScripts::Base | |||||||
| # #        Error -- non-existent method    upload.ensure_consistency! | # #        Error -- non-existent method    upload.ensure_consistency! | ||||||
|  |  | ||||||
|       # Use the correct content type and SHA1 hash for the upload |       # Use the correct content type and SHA1 hash for the upload | ||||||
|       content_type = `file --brief --mime-type #{file.path}`.strip | #      content_type = `file --brief --mime-type #{file.path}`.strip | ||||||
|       sha1 = Digest::SHA1.file(file.path).hexdigest | #      sha1 = Digest::SHA1.file(file.path).hexdigest | ||||||
|    |    | ||||||
|       upload = Upload.create!( | #      upload = Upload.create!( | ||||||
|  |       upload = Upload.new( | ||||||
|         user_id: user_id, |         user_id: user_id, | ||||||
|         original_filename: filename, |         original_filename: filename, | ||||||
|         filesize: file.size, |         filesize: file.size, | ||||||
|         content_type: content_type, |         sha1: Digest::SHA1.file(file.path).hexdigest | ||||||
|         sha1: sha1, | #        content_type: content_type, | ||||||
|         origin: 'composer', | #        origin: 'composer', | ||||||
|         retain_hours: nil | #        retain_hours: nil | ||||||
|       ) |       ) | ||||||
|  |  | ||||||
|       # Move the file to the correct location |       # Move the file to the correct location | ||||||
|       FileUtils.mv(file.path, upload.path) |       upload_path = Upload.get_path_for_file(upload.sha1) | ||||||
|  |       FileUtils.mkdir_p(File.dirname(upload_path)) | ||||||
|  |       FileUtils.mv(file.path, upload_path) | ||||||
|  | #      FileUtils.mv(file.path, upload.path) | ||||||
|  |  | ||||||
|       upload.save! |       upload.save! | ||||||
|       upload |       upload | ||||||
| @@ -384,6 +388,7 @@ class GossamerForumsImporter < ImportScripts::Base | |||||||
|       next unless attachment_data |       next unless attachment_data | ||||||
|    |    | ||||||
|       mime_type = att_row['postatt_content'] |       mime_type = att_row['postatt_content'] | ||||||
|  |  | ||||||
|       temp_file = Tempfile.new(['attachment', File.extname(att_row['postatt_filename'])]) |       temp_file = Tempfile.new(['attachment', File.extname(att_row['postatt_filename'])]) | ||||||
|       temp_file.binmode |       temp_file.binmode | ||||||
|       temp_file.write(attachment_data) |       temp_file.write(attachment_data) | ||||||
| @@ -393,11 +398,9 @@ class GossamerForumsImporter < ImportScripts::Base | |||||||
|       upload = upload_attachment(user_id, temp_file, att_row['postatt_filename'], attachment_url) |       upload = upload_attachment(user_id, temp_file, att_row['postatt_filename'], attachment_url) | ||||||
|       next unless upload |       next unless upload | ||||||
|    |    | ||||||
| # BAD |  | ||||||
| #      upload_url = upload.url |  | ||||||
|  |  | ||||||
|       # Get the URL of the uploaded file from Discourse |       # Get the URL of the uploaded file from Discourse | ||||||
|       upload_url = Upload.get_from_url(upload.url).url | #      upload_url = Upload.get_from_url(upload.url).url | ||||||
|  |       upload_url = upload.url | ||||||
|        |        | ||||||
|       puts "Appending to post.raw...  #{upload_url}  MIME type:  #{mime_type}" |       puts "Appending to post.raw...  #{upload_url}  MIME type:  #{mime_type}" | ||||||
|       if mime_type.start_with?('image/') |       if mime_type.start_with?('image/') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user