Browse Source

Changed how optinal select works when too many matches are found

spficklin 12 years ago
parent
commit
112d5d3a8d

+ 2 - 2
tripal_bulk_loader/tripal_bulk_loader.admin.templates.inc

@@ -771,8 +771,8 @@ function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
   );
   $form['edit_record']['select_optional'] = array(
      '#type' => 'checkbox',
-     '#title' => t('Continue if no record exists.'),
-     '#description' => t('By default if a select does not find a match the loader will fail.  Check here to allow the loader to continue when no match is found.'),
+     '#title' => t('Continue if no record exists or too many exist.'),
+     '#description' => t('By default if a select does not find a match the loader will fail, or if it finds too many matches it will fail.  Check here to allow the loader to continue when no match is found. In either case no value is passed on.'),
      '#default_value' => $select_optional
   );
   

+ 17 - 8
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -607,9 +607,11 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
     }
 
     if (!$record) {
-      $msg = "\nLine " . $addt->line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Unable to insert record into ' . $table . ' where values:' . print_r($values, TRUE);
+      $msg = "\nLine " . $addt->line_num . ' ' . $table_data['record_id'] . ' (' . 
+        $table_data['mode'] . ') Unable to insert record into ' . $table . 
+        ' where values:' . print_r($values, TRUE);
+        
       watchdog('T_bulk_loader', $msg, array(), WATCHDOG_ERROR);
-      print "ERROR: " . $msg . "\n";
       $data[$priority]['error'] = TRUE;
       $no_errors = FALSE;
     }
@@ -679,12 +681,19 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
         $data[$priority]['values_array'] = NULL;
       }
     }
-    // if we have more than one record matching then this isn't good. We have to error out.
-    if(count($matches) > 1){
-      $msg = "\nLine " . $addt->line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Too many matching records in ' . $table . ' where values:' . print_r($values, TRUE);
-      watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING);
-      $data[$priority]['error'] = TRUE;
-      $no_errors = FALSE;
+    // if we have more than one record matching and this select isn't optional then fail
+    if (count($matches) > 1) { 
+      if ($table_data['select_optional'] != 1) {
+        $msg = "\nLine " . $addt->line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Too many matching records in ' . $table . ' where values:' . print_r($values, TRUE);
+        watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING);
+        $data[$priority]['error'] = TRUE;
+        $no_errors = FALSE;
+      } 
+      // there are too many matches and this is an optional select so set
+      // the values to empty for any records with an FK relationship on this one
+      else {
+        $data[$priority]['values_array'] = NULL;
+      }
     } 
   }
   return $no_errors;