谢谢 Justin,我也快速看了一下——你觉得这样行吗?(如果你愿意,可以把它添加到官方导入器中)
XENFORO_DB = "xenforo_db_3"
TABLE_PREFIX = "xf_"
BATCH_SIZE = 1000
ATTACHMENT_DIR = '/FULL/PATH/TO/attachments'
AVATAR_DIR = '/FULL/PATH/TO/avatars'
(最后一行是新增的^^——意味着你需要将头像复制到这里)
def execute
import_users
import_categories
import_posts
import_avatars
end
(最后一行是新增的^^)
def import_avatars
if AVATAR_DIR
users = User.all
users.each do |u|
unless u.custom_fields["import_id"].nil?
import_id = u.custom_fields["import_id"]
if import_id.to_i < 1000
dir_num = "0"
elsif import_id.to_i > 1000
dir_num = import_id.first
end
avatar_filename = "#{import_id}.jpg"
file_path = "#{AVATAR_DIR}/l/#{dir_num}"
file_path_and_name = "#{file_path}/#{avatar_filename}"
if File.exists?(file_path_and_name)
upload = create_upload(u.id, file_path_and_name, avatar_filename)
if upload.persisted?
u.import_mode = false
u.create_user_avatar
u.import_mode = true
u.user_avatar.update(custom_upload_id: upload.id)
u.update(uploaded_avatar_id: upload.id)
else
puts "Error: Upload did not persist for #{u.username} #{avatar_filename}!"
end
end
end
end
end
end
现在时间太晚了,我可能犯了一些错误或者遗漏了很多内容,但这里假设所有头像都是 .jpg 格式(看起来我的都是)。不过我对 u.import_mode 的切换不太确定,所以先把它注释掉了。
完全未经测试(这里都快凌晨 5 点了
)
我在开发机器上对拥有 10 万条帖子的论坛进行了测试,耗时 90 分钟。我要导入的那个论坛有几百万条帖子,所以时间可能是它的 10 倍?
太棒了!你们会与我们分享吗?大概什么时候?