v0.16.2 Profile image handling improvement

This commit is contained in:
David Sainty 2024-06-27 02:35:15 +10:00
parent 96cb9e7664
commit b38e2853bb

View File

@ -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
# 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)