dpkoch
(Daniel Koch)
1
我尝试按照此处发布的说明从 Vanilla 论坛导入数据。但是,当我运行 vanilla.rb 导入脚本时,出现了以下错误:
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)
我已尝试按照此处的说明将 MySQL 数据库字符集更改为 UTF8,然后重新导出 porter 文件,但这并未解决问题。有什么建议吗?
1 个赞
pfaffman
(Jay Pfaffman)
2
You either need to keep trying to get it to really be UTF-8 or modify the import script to do it. It is a frustrating problem.
2 个赞
pfaffman
(Jay Pfaffman)
5
您可以搜索有关 UTF-8 编码的内容。您需要执行某些操作以将表格强制转换为 UTF-8 格式。我上次操作时遇到了更多复杂情况,因为某些行采用一种格式,而其他行采用另一种格式。我认为我进行了一些无意义的操作,即以逐个值的方式对内容进行了强制转换。
1 个赞
听起来很糟糕……我们得调整一下表格编码,看看会发生什么。谢谢!
pfaffman
(Jay Pfaffman)
7
哦,这太糟糕了。根据我对一年多前做过一次此事的模糊记忆,最好的办法是尝试尽可能多的不同转换,直到找到一个适用于所有或大多数数据的方案。我认为我当时做了一系列逐一转换,结果却浪费了时间,直到偶然发现某个转换对所有(大多数?)数据都有效。
以下是我所做的操作。请自行承担风险。(顺便一提,这是 vbulletin 的情况。)
def char_map(raw_original)
raw = raw_original.dup
debug = false # (raw.length > 50)
# windows 1252
all = ''
win_encoded = ''
### WIN1252 编码
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 对以下数据失败:\n\n#{raw}\n\n"
win_encoded = ''
end
### ISO 8859 编码
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
该代码是用于导入脚本中,还是用于服务器/数据库端?
pfaffman
(Jay Pfaffman)
9
在导入脚本中。我不喜欢直接操作数据库。
你在某处调用了这个函数来处理 raw,以修复 raw(可能还有标题?)。
好的,非常感谢!这应该能让我在调试这个问题上获得巨大的先发优势。
1 个赞
我们通过添加一个简单的命令来解决这个问题,该命令在读取文件时将其编码为 UTF-8,例如在 vanilla.rb 导入脚本的第 76-80 行使用 encode\"UTF-8\"。
我正在等待提供该命令的人确认确切的语法。收到后我会更新此信息。
1 个赞
这是他用来修复此问题的方法,从 vanilla.rb 的第 76 行开始
def read_file
puts "reading file..."
string = [File.read](http://file.read/)(@vanilla_file)
.force_encoding('UTF-8').encode("UTF-8").gsub("\\N", "")
.force_encoding('UTF-8').encode("UTF-8").gsub(/\\$\n/m, "\\n")
.force_encoding('UTF-8').encode("UTF-8").gsub("\\,", ",")
.force_encoding('UTF-8').encode("UTF-8").gsub(/(?<!\\)\\"/, '""')
.force_encoding('UTF-8').encode("UTF-8").gsub(/\\\\\\"/, '\\\"\"')
[StringIO.new](http://stringio.new/)(string)
end
1 个赞
Canapin
(Coin-coin le Canapin)
拆分了此话题
13
pfaffman
(Jay Pfaffman)
16
您需要搜索有关编码的资料,找出如何修复损坏的编码。
southpaw
(Southpaw)
17
您好 @ddeveloper,
几个月前我也经历过这个过程(我不是开发者
),并成功地将自托管的 Vanilla 论坛迁移到了自托管的 Discourse。对我来说,关键的一点是,在使用 Vanilla Porter 导出数据时,确保在第一个下拉菜单中选择“Vanilla 2”作为 Source Forum Type(源论坛类型)。
我使用的是在这里作为 zip 文件提供的 Vanilla Porter 2.6 版本:Vanilla Porter 2.6 RC1 — Vanilla Forums Migrate a Vanilla forum to Discourse 中链接的 2.5 版本。
如果我没记错的话,当我使用较新的 Vanilla Porter 脚本和“Vanilla 2”论坛类型时,我没有再遇到 UTF-8 错误。
如果这两个建议对您的导入没有帮助,请提供一些关于您到目前为止所采取步骤的详细信息,以及您具体看到的情况。有时,“相同的错误”之间会有细微的差别,这在故障排除时可能会产生很大的影响。
5 个赞
我已经遵循了相同的指南,只是使用了 porter 2.6 版本。我将从 2.6 版本导出文件并在此处更新。
好的,我已经尝试了 porter 2.6,结果出现了同样的 UTF-8 错误:
到目前为止,我一直遵循这个指南:Migrate a Vanilla forum to Discourse
一切都很顺利,直到出现这个 UTF-8 编码错误。有些人已经解决了这个问题。我尝试了他们的方法,但对我来说不起作用。
我尝试了 @Nick_Chomey 上面的解决方案;尝试在读取 txt 文件时强制使用 utf-8 编码,但徒劳无功,也没有奏效。
southpaw
(Southpaw)
20
为了确保万无一失,您在 Vanilla Porter 下拉菜单中选择了哪种 Source Forum Type?
您能告诉我们您使用的是哪种类型的计算机吗?将文件转换为 UTF-8 编码的说明会有所不同。
1 个赞
感谢您花时间帮助另一位论坛用户。
我在“源论坛类型”中选择了“Vanilla 2”。
我可以使用基于 Windows 和 Linux 的设备,并且可以访问两者。