diff --git a/gossamer_forums.rb b/gossamer_forums.rb index f79c0e0..f652e5c 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1,5 +1,5 @@ # gossamer threads migration-import code -# v0.16.1 +# v0.16.2 require 'mysql2' require 'open-uri' @@ -479,9 +479,15 @@ class GossamerForumsImporter < ImportScripts::Base resized_upload = upload_attachment(user, resized_temp_file, file['File_Name'], file_url) next if resized_upload.nil? - # Set the avatar usign the resized image - user.user_avatar = UserAvatar.create!(user_id: user.id, custom_upload_id: resized_upload.id) - user.save! + # Ensure the upload ID is valid and exists + if resized_upload && UserAvatar.exists?(custom_upload_id: resized_upload.id) + # Set the avatar using the resized image + user.user_avatar = UserAvatar.create!(user_id: user.id, custom_upload_id: resized_upload.id) + user.save! + puts "Avatar set for user #{user.username} with upload ID #{resized_upload.id}" + else + puts "Failed to set avatar for user #{user.username}" + end # Set the Profile Header UserProfile.find_by(user_id: user.id).update!(profile_background_upload_id: upload.id)