I would like to be able to export data from my Drupal site using Views Bonus Pack CSV feed. Then change the data in Excel. Then use Feeds with a CSV Importer to update the data.

The problem is that there does not seem to be a way to sync up the nodes via a unique value and new nodes are created instead.
When I export the data I can't get a GUID.
When I try to use either the path alias or /node/nid as the URL that doesn't work.
When I try to map the NID to GUID that doesn't work.

Am I missing something or is this a feature request?

Comments

alex_b’s picture

Category: feature » support
Status: Active » Postponed (maintainer needs more info)

What you'll have to do is establish some existing property of your nodes as a unique identifier - what would that be in your case?

This could be a feature request, let's assume this is a support request for now.

stephenj’s picture

Thanks for responding. I am not sure whether this was a support issue or a feature request. I have looked everywhere for anwers before I posted anything.

The safest information to use as a unique identifier in my case is the NID. The NID is easy to export. I do have other things like SKUs for some of my content type but NIDs are universal and always unique. As I mentioned I tried mapping the NID to the GUID but that didn't help.

alex_b’s picture

Title: Updating Existing Content not created with Feeds » Mapping target nid
Category: support » feature
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.48 KB

You could create a mapping target 'nid' and make it optionally unique.

stephenj’s picture

alex_b: Thank you for the code!

I will attempt to do this and report back in a few days so that anyone following this thread can get this. I think my problem must be shared by others.

stephenj’s picture

OK - I have installed the patch and done a preliminary test with one record.

I exported a number of fields including the Title, NID and a CCK field using a Views Bonus pack Feed - CSV view.

I converted the CSV file into a Windows CSV file (I have found that format has normally worked best for instance in Node Import)

Then I created a Feed Importer with a CSV parser and mapped to the correct node type, mapping only the NID to Node ID as a unique value and the CCK field that I wanted to update.

I had "Update existing nodes (slower than replacing them)" checked with Default Format

I got this message:

user warning: Duplicate entry 'node-' for key 2 query: INSERT INTO path_redirect (source, redirect, query, fragment, language, type, last_used) VALUES ('node', 'hardware-old-style-stand-leg', '', '', '', 301, 1283301073) in /var/www/hotkilns_dev/includes/common.inc on line 3477.

It created a new node with a new node ID and added a "-0" to the end of the path name. The node is an updated version of the old node but the old node does exist.

Any suggestions?

stephenj’s picture

Further comment from stephenj:

I noticed that the screen of the importer form (where you specify which importer to use) sent back a message as follows: "Updated 1 Parts node."

So the importer thinks it is updating the node - and in fact it is. However, probably because of the special nature of the NID is has to create a node when it does this.

It would be a trivial matter to create a computed CCK field, perhaps something that is automatically generated from the NID and maybe a date, that could be used as a unique value. I can understand that this could be dangerous for some users because it would be dependent on the user really understanding and making sure that the value is unique. Another thought would be to use the Path. I tried doing this with no luck earlier by mapping the Path to the URL in a Feeds Importer.

trevorbradley’s picture

Subscribe: I'm trying to do something quite similar. I've managed to apply the nid patch, and feeds claims to be updating nodes, but new nodes are being created.

EDIT: Just a bit of info for those people who were similarly confused as I was: The GUID and URL are terms brought over from RSS feed import. They don't have anything to do with your site's Drupal nid, or with the URL the page was loaded from.

Frustratingly, setting a GUID in uploaded CSV data works just great for duplicate entries. I'm pondering hacking the feeds system so that nodes exported to be edited in CSV have a GUID generated for them.

An alternative may be Ubercart, which also has a CSV importer. I think I like Feeds better so far though, even with the glitches.

stephenj’s picture

Does anyone know of any system for exporting data as a csv file, updating it in Excel as a csv and then using that data to update? I was looking at some posts for Ubercart but I agree with TrevorBradley that Feeds seems to offer the best hope. I would consider using XML export/import (even though I am not familiar with it) if one would easily edit those files in mass like one can with a csv file. Node Import and Node_Import_Update do not seem like they are getting the attention that Feeds is getting.

The hopeful thing is that at least the node is being updated - even if it is then recreated as a new node.

trevorbradley’s picture

@stephenj: Having a look around I think this is still the best bet. Let's see if we can figure out how to get unique nid import working.

I've been doing some debugging. I can verify that the nid is no longer set after this line is run:

$this->map($item, $node);

$this->nid is still fine just before this line is run...

More info as it comes...

EDIT: The fault is somewhere in FeedsProcessor.inc. These lines are unsetting nid...

      elseif (isset($target_item->{$mapping['target']})) {
        unset($target_item->{$mapping['target']});
      }
trevorbradley’s picture

I think I found it...

Back to FeedsNodeProcessor.inc:

  /**
   * Override setTargetElement to operate on a target item that is a node.
   */
  public function setTargetElement($target_node, $target_element, $value) {
    if (in_array($target_element, array('url', 'guid'))) {
      $target_node->feeds_node_item->$target_element = $value;
    }
    elseif ($target_element == 'body') {
      $target_node->teaser = node_teaser($value);
      $target_node->body = $value;
    }
    elseif (in_array($target_element, array('title', 'status', 'created'))) {
      $target_node->$target_element = $value;
    }
  }

What's happening is that FeedsProcessor unmaps the nid, and then comes back to reset it (which is OK in theory). FeedsNodeProcessor comes back to re-set the nid, but the setTargetElement function is overwritten, and nid is ignored.

The following fix works...

  /**
   * Override setTargetElement to operate on a target item that is a node.
   */
  public function setTargetElement($target_node, $target_element, $value) {
    if (in_array($target_element, array('url', 'guid'))) {
      $target_node->feeds_node_item->$target_element = $value;
    }
    elseif ($target_element == 'body') {
      $target_node->teaser = node_teaser($value);
      $target_node->body = $value;
    }
    elseif (in_array($target_element, array('title', 'status', 'created','nid'))) {
      $target_node->$target_element = $value;
    }
  }

I'll try to read up on patches and see if I can add one here.

trevorbradley’s picture

StatusFileSize
new1.45 KB

My first patch! Hope it works... (You'll need to apply this to the original file, not the one you've already patched...)

trevorbradley’s picture

StatusFileSize
new1.45 KB

EDIT: Fixed the spacing in the array of names.

stephenj’s picture

Thanks! I will give it a try and report back.

stephenj’s picture

I have tried RevorBradley's patch and I can report that it seems to be working fine.

I was learning how to install a patch and apparently this patch needs to be installed right int he directory where the file to patched is if that helps anyone else. It will not install from the Feeds directory.

Anyway I tested it out on an image field and a text field. On the text field I had html (some A refs) and that worked. The image field worked when I exported the whole path of the file plus of course the file name. I know there is more stuff int he array but I assume none of it is too important.

In any case I think this is a great success. I updated almost 300 records in about 1/2 hour including the time to populate and change the csv.

I change the format of the csv file that comes out of the Bonus Views Feed to a Windows CSV - (only because I have found with other importers like Node Import that that seems to work best. I'm not sure if it necessary with this and I have not tested that.

Now if I could only get the Node References and multi-value fields to export and import with Feeds....

alex_b’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.84 KB

That's because the patch is not rolled right - trevor, check out http://drupal.org/patch

Here's a re roll, will commit asap.

alex_b’s picture

Status: Reviewed & tested by the community » Fixed
stephenj’s picture

alex_b:

Thank you for helping with this. Quick question: should I reinstall the patch?

alex_b’s picture

reinstall the patch?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.