http://drupal.org/project/node_import_update

I know NIU doesn't have a stable release, but it works pretty well if you can get past the configuration. I'd been hoping that I could simply use Node Import Via Cron with Node Import Update, but it seems that using "via cron" somehow sidesteps the Node Import Update functionality.

It would be great to have both automation and update of existing nodes without deleting and rebuilding them each time. Tracking sales of products in Ubercart is impossible if every time someone corrects a typo it becomes a brand new product.

Wouldn't it be awesome?

Comments

jvdurme’s picture

Subscribe.

CMangrum’s picture

I'll second this request. I have 65000 nodes that I need to update regularly. Node Import Update allows me to do that without deleting old nodes and creating new ones. It would be even better if I could schedule the import, know that it would update existing nodes and create any that don't exist.

I am also not sure if it's even possible to do what I need since I have the cron limit set to 100 records per run. 2400 records per day will take a while to get to 65000.

julianmancera’s picture

Hi all,

Here is a hook function that can be added to the node_import_update module to have the update desired functionality:

function node_import_update_node_import_values_alter($values, $type, $defaults, $options, $fields, $preview) {

		$IMPORT_UNIQUE_ID_NAME   = 'my_cck_unique_field';  // Import field that holds the unique identifier
	    $IMPORT_UNIQUE_ID_IS_CCK = TRUE;    // Is the identifier a CCK field?
	
	    $IMPORT_NTYPE            = 'my_cck_id';   // Node type to be imported
	    $IMPORT_UPDATE_DATETIME  = TRUE;        // Settting: update date/time value?
	
	
	    // Alter node edit form
	
	
	      // Check if item already exists
	      if ($IMPORT_UNIQUE_ID_IS_CCK) {
	        // get unique id from cck fields
	        $unique_id_value = $values['cck:' . $IMPORT_UNIQUE_ID_NAME . ':value'][0];;
	        // build query
	        $query = 'SELECT c.nid, c.vid FROM {content_type_%s} c WHERE c.%s = "%s"';
	      }
	      else {
	        // get unique id for node values
	        $unique_id_value = $values[$IMPORT_UNIQUE_ID_NAME];
	        // build query
	        $query = 'SELECT n.nid, n.vid FROM {node} n WHERE n.type = "%s" AND n.%s = "%s"';
	      }
	
	      // Check if we have a unique id
	      if ($unique_id_value){
	
	        // execute query
	        $row = db_fetch_array(db_query($query, $IMPORT_NTYPE, $IMPORT_UNIQUE_ID_NAME . '_value', $unique_id_value));
	
	        // Destroy so we don't pass an array on next iteration
	        unset($query);
	
	        // If already exists (non empty result)
	        if (!empty($row['nid'])) {
	
	          //drupal_set_message('update in effect!');
	
	          // Set nid and vid to that node
	          $values['nid'] =  intval($row['nid']);
	          
	
	         
	          
	        }
	      }
	    
    
}

Depending on the complexity of the CCK field the query should be modified, in case the field has an additional table.

Not sure if the node import via cron maintainer is willing to add this hook to the module core or we should maintain it in the node_import_udpate module.

Willing to hear from your testing so it can become a patch

Julian Mancera