This patch changes the "Titles must be unique for this node type" checkbox in supported/node.inc to a select box with the options:
- Don't import
- Create new node
- Update existing node
And description:
Select Don't import if you don't want to import nodes which have the same title as an existing node, Create new node if you want all imported nodes to be created as new nodes, or Update existing node if you want existing nodes with the same title as nodes to import to be updated with the imported node data, creating a new revision for those nodes (if more than one node with the same title and of the same type is found none of them will be updated).

The update existing nodes option is handled by setting the node object nid field to that of the existing nodes nid (if there's only one with the same title and type, otherwise an error is generated). This is then picked up by save_node which updates the existing node instead of creating a new one.

CommentFileSizeAuthor
node.inc_.diff2.71 KBOliverColeman
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zeezhao’s picture

Thanks for the patch. I tried it out, and I discovered that when there are duplicate titles, and "Update existing node" has been selected, even though the preview rightly highlights the errors, the duplicate nodes get re-imported anyway...

also no error file gets created.

looks like there may be an existing bug in node_import with unique nodes?

the reason I say so it that I also tried a very similar patch to yours, see http://drupal.org/node/150397

and i had the same error with the unique nodes being duplicated even though preview had pointed out the error.

Could be because the title had an apostrophe within it e.g. "ABC's title"?

By the way, the only way to verify the bug is to check the database table {node} or via web page admin/content/node, since the message given on web page after import does not tally with what actually happened in the database.

OliverColeman’s picture

Status: Needs review » Closed (duplicate)

Feature request a duplicate of http://drupal.org/node/150397

This feature request has been linked to from the original issue thread to make the patch available (although a very similar patch already exists in the original). Any updates of the patch given in this issue will be posted in the original issue.

OliverColeman’s picture

There's a new post regarding the error mentioned in #1 at http://drupal.org/node/150397#comment-893706