0

I have used feeds to import some nodes with taxonomy term reference.

The source XML is the following one.

<items>
  <item>
    <title>Test 1</title>
    <body>Test body 1</body>
    <term>My_term_foo</term>
    </item>
</items>

First import is OK. I edited <term>My_term_bar</term>, and started importing a second feed. After the second time, the node has both "My_term_foo" and "My_term_bar," but I need only "My_term_bar" from the second import.

Is there any hook_feeds_node_item_presave() I can use to alter the values being imported?

EDIT:

My final code of hook_nodeapi inpired by sel_space:

switch ($op) {
      case 'presave':
        if ($old_node = node_load($node->nid)) {
          $taxonomy = array_diff_assoc((array) $node->taxonomy, (array) $old_node->taxonomy);
          if (!empty($taxonomy)) {
            $node->taxonomy = $taxonomy;
          }
        }
        break;
    }
1

If data needs to be modified before it is saved use this module : Feeds tamper

For advanced modification use hook_nodeapi in drupal 6 with the insert parameter , with hook_nodeapi load the old node like this :

$old_node = node_load(node->nid);
$node->taxonomy = array_diff($old_node->taxonomy,$node->taxonomy)

So now you are sure that the $node contain only the new value , Hope this will help

  • Thanks for answer. I know feeds tamper, but it only change source. And if I try use hook_nodeapi then in node->taxonomy are both terms My_term_foo and My_term_bar and I dont know which is from second import. – kubedan Apr 15 '12 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.