v0.16.1 Tweak for rogue image handling
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
				
			|||||||
# gossamer threads migration-import code
 | 
					# gossamer threads migration-import code
 | 
				
			||||||
# v0.16
 | 
					# v0.16.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require 'mysql2'
 | 
					require 'mysql2'
 | 
				
			||||||
require 'open-uri'
 | 
					require 'open-uri'
 | 
				
			||||||
@@ -387,6 +387,9 @@ class GossamerForumsImporter < ImportScripts::Base
 | 
				
			|||||||
    png_path = file_path.sub('.tiff', '.png').sub('.tif', '.png')
 | 
					    png_path = file_path.sub('.tiff', '.png').sub('.tif', '.png')
 | 
				
			||||||
    system("convert #{file_path} #{png_path}")
 | 
					    system("convert #{file_path} #{png_path}")
 | 
				
			||||||
    png_path
 | 
					    png_path
 | 
				
			||||||
 | 
					  rescue => e
 | 
				
			||||||
 | 
					    puts "Failed to convert image #{file_path}: #{e.message}"
 | 
				
			||||||
 | 
					    nil
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Helper method to resize an image to specified dimensions
 | 
					  # Helper method to resize an image to specified dimensions
 | 
				
			||||||
@@ -394,6 +397,9 @@ class GossamerForumsImporter < ImportScripts::Base
 | 
				
			|||||||
    resized_path = file_path.sub(File.extname(file_path), "_resized#{File.extname(file_path)}")
 | 
					    resized_path = file_path.sub(File.extname(file_path), "_resized#{File.extname(file_path)}")
 | 
				
			||||||
    system("convert #{file_path} -resize #{max_width}x#{max_height} #{resized_path}")
 | 
					    system("convert #{file_path} -resize #{max_width}x#{max_height} #{resized_path}")
 | 
				
			||||||
    resized_path
 | 
					    resized_path
 | 
				
			||||||
 | 
					  rescue => e
 | 
				
			||||||
 | 
					    puts "Failed to resize image #{file_path}: #{e.message}"
 | 
				
			||||||
 | 
					    nil
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Import user files (profile images) from Gossamer Forums to Discourse
 | 
					  # Import user files (profile images) from Gossamer Forums to Discourse
 | 
				
			||||||
@@ -439,12 +445,25 @@ class GossamerForumsImporter < ImportScripts::Base
 | 
				
			|||||||
  
 | 
					  
 | 
				
			||||||
      # Convert TIFF to PNG if necessary
 | 
					      # Convert TIFF to PNG if necessary
 | 
				
			||||||
      if file['File_MimeType'] == 'image/tiff'
 | 
					      if file['File_MimeType'] == 'image/tiff'
 | 
				
			||||||
 | 
					        converted_tiff_to_png_path = convert_tiff_to_png(temp_file.path)
 | 
				
			||||||
 | 
					        if converted_tiff_to_png_path.nil?
 | 
				
			||||||
 | 
					          puts "Skipping image due to convert failure: #{temp_file.path}"
 | 
				
			||||||
          temp_file.close
 | 
					          temp_file.close
 | 
				
			||||||
        temp_file = File.open(convert_tiff_to_png(temp_file.path))
 | 
					          temp_file.unlink
 | 
				
			||||||
 | 
					          next
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					        temp_file.close
 | 
				
			||||||
 | 
					        temp_file = File.open(converted_tiff_to_png_path)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      # Resize the image for the avatar / profile picture (200x200)
 | 
					      # Resize the image for the avatar / profile picture (200x200)
 | 
				
			||||||
      resized_image_path = resize_image(temp_file.path, 200, 200)
 | 
					      resized_image_path = resize_image(temp_file.path, 200, 200)
 | 
				
			||||||
 | 
					      if resized_image_path.nil?
 | 
				
			||||||
 | 
					        puts "Skipping image due to resize failure: #{temp_file.path}"
 | 
				
			||||||
 | 
					        temp_file.close
 | 
				
			||||||
 | 
					        temp_file.unlink
 | 
				
			||||||
 | 
					        next
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
      resized_temp_file = Tempfile.new(['user_image_resized', '.png'])
 | 
					      resized_temp_file = Tempfile.new(['user_image_resized', '.png'])
 | 
				
			||||||
      FileUtils.copy_file(resized_image_path, resized_temp_file.path)
 | 
					      FileUtils.copy_file(resized_image_path, resized_temp_file.path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user