合并多值字段,然后删除重复的节点

时间:2016-05-19 21:36:00

标签: drupal drupal-7 drupal-modules

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

  • Drupal 7网站,我创建了一个包含多值字段的内容 (复选框)。
  • 我使用Feed从csv文件导入数据。导入了超过20K的记录,除了多值字段外,还有重复的行。
  • Feed导入器不会附加多值字段,而是覆盖该值。这就是我决定导入包括重复项在内的所有行的原因。
  • 我使用计算字段创建了一个唯一键,通过连接每个记录共有的一些文本字段。此密钥可能有助于以后合并节点。

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

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

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

1 个答案:

答案 0 :(得分:1)

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

https://vimeo.com/28659739

解决方案(根据客户需求):

  1. 为csv文件中的每条记录创建一个密钥(我有很多 重复且没有密钥,数据未合并。)
  2. 创建一个临时字段(单选按钮,一个值),该字段是Term引用字段。
  3. 使用密钥作为唯一值(field_validation模块)导入csv文件,utf8编码。
  4. 节点处理器的设置

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

    导入器使用相同的密钥更新节点,消除重复并使用相同的信息合并记录。

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

    **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