--- node.inc 2008-03-18 00:02:50.000000000 +1100 +++ node.inc.updatenodes 2008-06-18 13:17:14.000000000 +1000 @@ -185,10 +185,21 @@ function node_node_import_prepare(&$node if ($type_info->has_title && (!isset($node->title) || empty($node->title))) { $errors[] = t('You need to provide a non-empty title.'); } - else if ($unique_title) { - $count = db_fetch_object(db_query("SELECT count(*) cnt FROM {node} WHERE title = '%s' AND type = '%s'", $node->title, $node->type)); - if ($count->cnt > 0) { - $errors[] = t('The node title %title is not unique for this node type.', array('%title' => $node->title)); + else { + switch ($unique_title) { + case "don't import": + $count = db_fetch_object(db_query("SELECT count(*) cnt FROM {node} WHERE title = '%s' AND type = '%s'", $node->title, $node->type)); + if ($count->cnt > 0) { + $errors[] = t('The node title %title is not unique for this node type.', array('%title' => $node->title)); + } + break; + case "update values": + $current_nodes = db_query("SELECT nid FROM {node} WHERE title = '%s' AND type = '%s'", $node->title, $node->type); + if (db_num_rows($current_nodes) == 1) + $node->nid = db_fetch_object($current_nodes)->nid; + else if (db_num_rows($current_nodes) > 1) + $errors[] = t('There are more than one nodes with title %title for node type %type.', array('%title' => $node->title, '%type' => $node->type)); + break; } } @@ -264,10 +275,14 @@ function node_node_import_global($type, // Unique titles? $form['node_import_node']['unique_title'] = array( - '#type' => 'checkbox', - '#title' => t('Titles must be unique for this node type.'), - '#description' => t('Check this box if you do not want to import nodes if there is already a node with the same title.'), + '#type' => 'select', + '#title' => t('Action to take for existing/duplicate node titles'), + '#description' => t("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)."), '#default_value' => $globals['unique_title'], + '#options' => array("don't import" => t("Don't import"), + "create new" => t("Create new node"), + "update values" => t("Update existing node"), + ) ); return $form;