I had a problem importing nodes and mapping them to their original NID from a D5 installation. I needed this to work for node referencing.

To fix the node ID problem I had to import the nodes via SQL and then running the import as a node replace. Also note that importing just the node table will result in broken nodes as it's missing the revisions. When you do import the nodes with their original NID and VID (Version ID) make sure you set the Auto Increment of that table to the highest VID in your node table. Then run the Feeds import and it should work fine.

I am not sure where this belongs but I hope it will help some people out there who are struggling with getting this to work.

Furthermore I think you should make people aware of that the GUID is a requirement. I had removed this and after several failed attempts realized it was causing the problem. I then mapped the GUID to the nid in my CSV file.

Comments

johnbarclay’s picture

Title: Importing nodes with their original NID fails » Importing nodes with their original NID fails because of ambiguity in node_save() in FeedsNodeProcessor
Version: 7.x-2.0-alpha3 » 7.x-2.0-alpha4

I ran against this also. In the entitySave function in the FeedsNodeProcessor.inc when importing nodes with nids, it doesn't set the $entity->is_new flag if the node doesn't exist. So the node_save() function thinks its updating an existing node, but doesn't have a node version id and throws the error: Notice: Undefined property: stdClass::$vid in drupal_write_record()

Its really an odd use case to be sending a nid into node_save but wanting to create a new node. But seems like a valid one when trying to preserve node relationships.

Adding

    if (@$entity->nid && !node_load($entity->nid)) { // has nid property but is a new node.  must be trying to preserve nids
      $entity->is_new = TRUE;
    }

to the beginning of function entitySave($entity) takes care of the is_new flag, but I'm not sure if it correctly solves the problem or even works, yet.

dgastudio’s picture

same problem here. subscribe

boztek’s picture

What are the restrictions on guid? Does it have to be in integer? If not are there any other restrictions on allowable strings? I am trying a unique string ID from a legacy system but the importer is not importing any nodes.

13rac1’s picture

Status: Active » Needs review
StatusFileSize
new512 bytes

Feeds gives you a success message. There are no nodes created. So frustrating. I had many tables (node, node_revision, field_revision_field_*, field_data_field_*, feeds_item) to manually clean up after multiple failed imports, but finally after making this change my data import completed.

Patch is attached for code in #1. It works for me. Thanks!

anewcomb’s picture

I have the same problem. I find this in the "Recent log message" ...

Undefined property: stdClass::$vid in drupal_write_record() (line 6855 of /var/www/thesourceshow.new/includes/common.inc)

Adding the code in #1 above to FeedsNodeProcessor.inc fixed the issue for me.

dave reid’s picture

Status: Needs review » Needs work
+++ b/plugins/FeedsNodeProcessor.incundefined
@@ -71,6 +71,9 @@ class FeedsNodeProcessor extends FeedsProcessor {
   public function entitySave($entity) {
+    if (@$entity->nid && !node_load($entity->nid)) { // has nid property but is a new node.  must be trying to preserve nids
+      $entity->is_new = TRUE;
+    }
     node_save($entity);
   }
 

Please use !empty($entity->nid) rather than @$entity->nid. Also make sure the comment is a real sentence and put it above the additions rather than shoved off to the right.

13rac1’s picture

Version: 7.x-2.0-alpha4 » 7.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new522 bytes

Good point. My original patch was exactly as #1. This version is cleaned up.

johnbarclay’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Bumping to major because without this patch, importing nodes with nids in the mapper simply won't work, without any obvious error messaging. Its really not such an edge case since on a new site build/import you want to preserver node ids in the imported data. I wrote this for a friend who was tearing his hair out. The patch worked for him and I've used it on a couple projects since. (the one in #7).

e2thex’s picture

I have test this patch with the below list csv file.

Pre patch says items are import but do not get new nodes

post patch import works get new nodes, also can update nodes if nid already exist

nid, title, body
1010,"baseball", "rocks"
1011,"softball", "rocks kind of"
e2thex’s picture

Status: Reviewed & tested by the community » Fixed

commit to 7.x-2.x
http://drupalcode.org/project/feeds.git/commit/1a60aa1
Thanks for the Patch

ditcheva’s picture

Patch works for me. Thanks so much!

Status: Fixed » Closed (fixed)

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

afagioli’s picture

with latest d7, you can create new nodes with node_save keeping original nid from previous drupal installations.

  $node->nid     = OLD_ID ;
  $node->is_new  = 1 ;
sidgrafix’s picture

Was having a GUID problem causing duplicate node creation with the same or duplicate GUID instead of updating the node when using feed import CSV to create and update nodes of a custom content type.

Looked to be an issue for many, wasn't sure where to post the results as I solved this in our situation. After having been dealing with this for several weeks, becoming increasingly frustrating - yet the answer was kinda simple!

In the basic settings we had set it to an import form we created in the "Attach to content type" drop down. Apparently this made it break however GUID should work (checked into the form couldn't figure out why it would cause this being it was a very basic content type) Title and body (originally intended for use as a means to track when we updated the feed)

Anyway long story short changed that to "Use standalone form" and our nodes updated based on GUID as they should. We only use GUID as the only unique field for this content importer because it's less of a headache to have to get the NID back and added to our CSV via spreadsheet for this particular case. " Now that it works as expected :) "

Just hope it helps someone else!
If there is a better place to have posted this please move it there!