【问题标题】:Merge multivalue field then remove duplicated nodes合并多值字段,然后删除重复的节点
【发布时间】:2016-05-19 21:35:59
【问题描述】:

我愿意接受有关如何解决以下问题的建议:

  • Drupal 7 网站,我创建了一个包含多值字段的内容 (复选框)。
  • 我使用提要从 csv 文件导入数据。导入了超过 2 万条记录,其中包含重复的行,但多值字段除外。
  • Feeds 导入器不会附加多值字段,而是覆盖该值。这就是我决定导入所有行(包括重复行)的原因。
  • 我使用计算域创建了一个唯一键,方法是连接每个记录共有的一些文本域。此键可能有助于稍后合并节点。

如何遍历所有节点,找到具有相同键的节点,合并多值字段的值,然后删除重复项?

如何创建一个临时内容、相同的字段来保存新合并的节点?解决这个问题最简单的方法是什么?

Multivalue field (checkboxes)
A
B
C
etc

内容:

Key, NID, Title, Other fields, Multivalue field
key1, 1, title1, others1, A
key1, 2, title1, others1, B
key2, 3, title2, others2, A
key1, 4, title1, others1, C

预期结果,将多值文本字段合并为一个节点: NID可以在临时节点创建过程中生成。

NID, Title, Other fields, Multivalue field (checkboxes checked)
x, title1, others1, "A, B, C"
x, title2, others2, A

【问题讨论】:

    标签: drupal drupal-7 drupal-modules


    【解决方案1】:

    我终于想出了如何删除重复项,同时使用提要导入数据,并使用规则来合并多值字段。以下视频对最终解决方案非常有用:

    https://vimeo.com/28659739

    解决方案(根据定制需求):

    1. 为 csv 文件中的每条记录创建一个键(我有很多 重复且没有键,数据未合并)。
    2. 创建一个临时字段(单选按钮,一个值),该字段是术语参考字段。
    3. 导入 csv 文件,utf8 编码,使用键作为唯一值(field_validation 模块)。

    节点处理器设置

    • 插入新节点
    • 更新现有节点
    • 跳过不存在的节点

    Importer 使用相同的 key 更新节点,消除重复并合并具有相同信息的记录。

    在更新节点后执行了一条规则,以将值添加到多值字段。

    **Events**
    After updating existing content of type Course
    Before saving content of type Course
    
    **Conditions**
    Data comparison
    Selected data: node:field-temp
    value: equals
    the value to compare
    
    **Actions** 
    Fetch entity by id
    Value: taxonomy term
    value: term id of the term you want to add to the multivalue field
    Variable label: term name here
    Variable name: custom_var_name
    
    Add an item to a list
    Selected list: node:field-multivaluefield
    Data selector: custom_var_name
    Enforce uniqueness: True.
    
    Save entity
    node:field-multivaluefield:0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      • 2019-08-08
      • 2012-10-29
      • 1970-01-01
      相关资源
      最近更新 更多