我收到一位托管客户的 vBulletin 导入数据。头像已消失,现在显示为通用的空白人形图标,例如 this。
我相当确定它们曾经存在过。URL 看起来似乎应该包含某些内容。有什么方法可以找到它们吗?
我收到一位托管客户的 vBulletin 导入数据。头像已消失,现在显示为通用的空白人形图标,例如 this。
我相当确定它们曾经存在过。URL 看起来似乎应该包含某些内容。有什么方法可以找到它们吗?
Maybe related to that?
Do you have a backup where you can check the URL?
Are they in the tombstone?
I did a fresh import and all of the avatars are missing. Sidekiq still has 13M things to process, but I don’t see how that could be the problem. I did another import on another site with what I believe to be the same import script and the avatars are fine there.
pry(main)> User.find_by_username('MysteryManAvatar').uploaded_avatar
=> #<Upload:0x0000558a0d31b478
id: 97,
user_id: 114,
original_filename: "clevername.jpg",
filesize: 2028,
width: 90,
height: 67,
url: "/uploads/default/original/1X/080817dcf59ddc838054fba9716b62fce9ae3d83.jpg",
created_at: Thu, 19 Apr 2018 23:51:15 UTC +00:00,
updated_at: Thu, 19 Apr 2018 23:51:15 UTC +00:00,
sha1: "080817dcf59ddc838054fba9716b62fce9ae3d83",
origin: nil,
retain_hours: nil,
extension: "jpg">
But that file isn’t in uploads (or tombstone).
I looked at Avatars not showing after import and that didn’t seem to be related.
我已从备份恢复了数据库(旧版本有一些数据库迁移,而 backup.sql.gz 仅包含 SQL 文件,不包含上传的文件)。
不幸的是,网站上没有显示头像(仅显示默认占位符)。
它们似乎已正确存储在数据库中,URL 也正确,且 PNG 文件确实存在:
root@og-app:/var/www/discourse# rails c
[1] pry(main)> User.find_by_username('Overgrow').uploaded_avatar
=> #<Upload:0x0000565323a78880
id: 2936,
user_id: 1,
original_filename: "avatar.png",
filesize: 161585,
width: nil,
height: nil,
url: "/uploads/default/original/2X/f/fbba12aa89b1bc45676efcfa55affd4b7a76edf1.png",
created_at: Sat, 03 Sep 2016 10:26:23 UTC +00:00,
updated_at: Sat, 22 Feb 2020 11:57:35 UTC +00:00,
sha1: "fbbe22aa89b1bc45676efcfa55affd4b7a76edf1",
origin: nil,
retain_hours: nil,
extension: "unknown",
thumbnail_width: nil,
thumbnail_height: nil,
etag: nil,
secure: false,
access_control_post_id: nil,
original_sha1: nil>
请问接下来可以尝试哪些操作?提前感谢!
更新:
一些头像已在后台重新生成……能否加快此过程?或者手动运行?
根据我的观察,以下部分是否是问题的迹象?
extension: "unknown",
看起来那些已重新生成的头像现在该字段已填充:
extension: "JPG",
不知何故,我的数据库在备份还原并从 Discourse 1.6 迁移到 2.5 后,Upload 表(文件指针正确,文件也完好)中缺少了 width、height 和 extension 字段的值。
最终,我编写了一个脚本,遍历所有自定义上传的头像,修正扩展名和尺寸,并重新生成所有缺失的 version 2 缩略图(OptimizedImages)。
供感兴趣的朋友参考,脚本如下:
fix-avatars.rb
require File.expand_path("../../config/environment", __FILE__)
generated_count = 0
scope = UserAvatar.where("custom_upload_id > 0")
scope.find_each do |ua|
upload_id = ua.custom_upload_id
upload = Upload.find_by(id: upload_id)
unless upload
puts "\n未找到该用户头像对应的上传记录"
next
end
# 修复未知扩展名
if upload.extension === 'unknown'
upload.extension = nil
upload.save!
puts "\rupload_id #{upload.id} 扩展名 unknown -> nil"
end
if upload.extension.nil?
puts "\rupload_id #{upload.id} 正在修复扩展名"
upload.fix_image_extension
if upload.height == 0 || upload.width == 0
puts "\rupload_id #{upload.id} 正在修复尺寸"
upload.fix_dimensions!
end
# 检查优化版本
correct_optimized = OptimizedImage.where(upload_id: upload_id)
.where(version: 2)
if correct_optimized.count < 1
puts "\rupload_id #{upload.id} 缺少 version 2 缩略图"
# 销毁旧的优化图片
puts "\rupload_id #{upload.id} 正在删除头像"
optimized = OptimizedImage.where(upload_id: upload_id)
if optimized
optimized.destroy_all
end
# 生成优化图片
puts "\rupload_id #{upload.id} 正在创建头像"
Discourse.avatar_sizes.each {|size| OptimizedImage.create_for(upload, size, size, allow_animation: SiteSetting.allow_animated_avatars)}
generated_count += 1
puts "\r已生成 #{generated_count} 个头像(总计)"
end
end
end