Index: pimport.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pimport/pimport.module,v
retrieving revision 1.30
diff -u -p -r1.30 pimport.module
--- pimport.module	26 Aug 2010 17:42:28 -0000	1.30
+++ pimport.module	9 Nov 2010 12:49:12 -0000
@@ -278,7 +278,10 @@ function pimport_batch_process($user, $t
 
   // Use the profile ID to determine the unique ID field ... Should be system by default so no need to catch an error
   // if any field_match is system ID then we're using system IDs.
-  $unique_id_field = db_result(db_query("SELECT field_match FROM {pimport_profile_data} WHERE pid = %d && field_match = 'system_id'", $pid));
+  $unique_id_heading = db_result(db_query("SELECT heading FROM {pimport_profile_data} WHERE pid = %d && field_match = 'system_id'", $pid));
+  if ($unique_id_heading) {
+    $unique_id_column = array_search($unique_id_heading, $header);
+  }
 
   // Get an array of headings, columns in the CSV, and respective fields from which to construct the unique ID per line.
   $result = db_query("SELECT heading, field_match FROM {pimport_profile_data} WHERE unique_id_part = %d && pid = %d ORDER BY weight ASC", 1, $pid);
@@ -317,10 +320,11 @@ function pimport_batch_process($user, $t
       // Load the node if we've already got the unique ID in the system.
       $unique_id = "";
       // For system generated ids load a node for the nid if it exists...
-      if ($unique_id_field == "system_id") {
-        $unique_id = $line['system_id'];
+      if ($unique_id_heading) {
+        $unique_id = $line[$unique_id_column];
         if (is_numeric($unique_id)) {
           $edit = node_load($unique_id, NULL, TRUE); // Pass TRUE to $reset parameter else 1, increases memory usage 2, "content modified by another user" error.
+          // TODO: what does it mean if you can't load a node by unique ID at this point - should it be an error?
           $edit->revision = 1;
         }
       }
@@ -1305,4 +1309,4 @@ function _pimport_user_reference_process
 
 /**
  * @} End of "defgroup pimport_core".
- */
\ No newline at end of file
+ */
