I’m trying to import from a Vanilla forum using the instructions posted here. However, I get the following error when I run the vanilla.rb import script:
Loading existing groups...
Loading existing users...
Loading existing categories...
Loading existing posts...
Loading existing topics...
parsing file...
reading file...
Traceback (most recent call last):
5: from script/import_scripts/vanilla.rb:254:in `<main>'
4: from /var/www/discourse/script/import_scripts/base.rb:47:in `perform'
3: from script/import_scripts/vanilla.rb:17:in `execute'
2: from script/import_scripts/vanilla.rb:37:in `parse_file'
1: from script/import_scripts/vanilla.rb:72:in `read_file'
script/import_scripts/vanilla.rb:72:in `gsub': invalid byte sequence in UTF-8 (ArgumentError)
I’ve tried changing the MySQL database character set to UTF8 following the instructions here and then re-exporting the porter file, but that didn’t resolve the issue. Any suggestions?
You can google stuff about UTF-8 encoding. You need to do something that will coerce the table into UTF-8. The time that I did it, there were further complications because some rows were in one format and others in another format. I think that I did some nonsense where I coerced things on a value-by-value basis.
Oh. It’s aweful. You best bet, based on a vague recollection of a single time I did this over a year ago, is to play around with as many different conversions as you can until you can finally hit on one that works for all or most data. I think that I did a bunch of one-by-one transformations that ended up being a waste of time when I stumbled on some conversion that worked for all (most?) data.
Here is what I did. Use at your own risk. (This was vbulletin, FWIW).
def char_map(raw_original)
raw = raw_original.dup
debug = false # (raw.length > 50)
# windows 1252
all = ''
win_encoded = ''
### WIN1252 encoding
win_encoded = ''
begin
win_encoded = raw.force_encoding('utf-8').encode("Windows-1252",
invalid: :replace, undef: :replace, replace: ""
).force_encoding('utf-8').scrub
rescue => e
puts "\n#{'-'*50}\nWin1252 failed for \n\n#{raw}\n\n"
win_encoded = ''
end
### ISO 8859 encoding
iso_encoded = ''
if all.length == 0 && win_encoded.length > 0 && win_encoded != raw
all = (debug ? "Win1252--" : '') + win_encoded
else
all = raw
end
all = old_char_map(all)
all
end
لقد مررت بهذه العملية قبل شهرين فقط (وأنا لست مطورًا ) وتمكنت من ترحيل منتدى Vanilla مستضاف ذاتيًا بنجاح إلى Discourse مستضاف ذاتيًا. كان أحد الأشياء الرئيسية بالنسبة لي هو التأكد عند تصدير البيانات باستخدام Vanilla Porter، من تحديد “Vanilla 2” كـ Source Forum Type في القائمة المنسدلة الأولى.
إذا كنت أتذكر بشكل صحيح، لم أواجه خطأ UTF-8 مرة أخرى عند استخدام نص Vanilla Porter الأحدث ونوع المنتدى “Vanilla 2”.
إذا لم تحدث هذين الاقتراحين فرقًا في استيرادك، فيرجى تقديم بعض التفاصيل حول الخطوات التي اتخذتها حتى الآن وما تراه بالضبط. في بعض الأحيان تكون هناك اختلافات طفيفة في “نفس الخطأ” يمكن أن تحدث فرقًا كبيرًا عند استكشاف الأخطاء وإصلاحها.