使用 import_scripts Ruby 导入用户自定义字段


我已经从用户字段创建了 DrupalID 字段,现在想将数据导入其中

create_users(@users_json) do |u|
      {
#        id: u["uid"],
#        name: u["name"],
#        email: u["mail"],#
#       custom_fields: {
#          '1':u["uid"],
#          'DrupalID':u["uid"]
#        },


        id: 2037,
        name: "Test 7",
        email: "test7@gmail.com",
        custom_fields: {
          '1':"test",
          'DrupalID':"test"
        },

        created_at: Time.zone.at(u["created"].to_i),
      }

这是问题还是答案?您是在说您的代码有效吗?

代码可以工作,但不能用于自定义字段。我想更新自定义字段。

在其他导入器脚本中搜索“custom_field”。我确定有示例;我相当确定我以前做过。

1 个赞

是的,我检查过了,但我们没有提供任何 JSON 文件和字段名称(我们需要使用什么)的示例。

我也尝试使用 CSV 导入,但遇到了同样的问题(缺少示例文件)

找到任何导入自定义用户字段的脚本,并将其添加到你的脚本中

1 个赞

我也尝试了来自 discourse/script/import_scripts/csv_importer.rb at main · discourse/discourse · GitHub 的 custom_fields.csv
字段名 DrupalID

id,user_field_1,DrupalID,Drupal ID,custom_field_DrupalID,drupalid
23456,John,John,Doe,example,johndoe
23457,Jane,Jane,Smith,example1,janesmith

它不起作用,显示字段为空

Looks like discourse/script/import_scripts/csv_importer.rb at main · discourse/discourse · GitHub 应该能用,但你必须定义 discourse/script/import_scripts/csv_importer.rb at main · discourse/discourse · GitHub 中看到的 ENV。

1 个赞