spficklin 12 rokov pred
rodič
commit
f627849b77

+ 10 - 8
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -492,10 +492,11 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
 
   // get the table description
   $table_desc = tripal_core_get_chado_table_schema($table);  
-
+  
   // Check that template required fields are present. if a required field is 
   // missing and this
   // is an optional record then just return. otherwise raise an error
+  $skip_optional = 0;
   foreach ($table_data['required'] as $field => $required) {
     if ($required) {
       // check if the field has no value (or array is empty)
@@ -505,7 +506,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
         // check if the 'mode' is set to 'optional'
         if ($table_data['optional'] or preg_match('/optional/', $table_data['mode']) or 
             $table_data['select_optional'])  {
-            
+          $skip_optional = 1;
           // set the values array to be empty since we all required fields are
           // optional and we can't do a select/insert so we don't want to keep
           // the values if this record is used in a later FK relationship.
@@ -521,12 +522,12 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
       }
     }
   }
-
+  
   // for an insert, check that all database required fields are present in the values array
   // we check for 'optional' in the mode for backwards compatibility. The 'optional' 
   // mode used to be a type of insert
-  if (preg_match('/insert/', $table_data['mode']) or 
-      preg_match('/optional/', $table_data['mode'])) {
+  if (!$skip_optional and (preg_match('/insert/', $table_data['mode']) or 
+       preg_match('/optional/', $table_data['mode']))) {
     // Check all database table required fields are set
     $fields = $table_desc['fields'];
     foreach ($fields as $field => $def) { 	
@@ -556,13 +557,14 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
   if ($skip_optional) {
     return $no_errors;
   }
-
+  
   // check if it is already inserted
   if (array_key_exists('inserted',$table_data) and $table_data['inserted']) {
     //watchdog('T_bulk_loader','Already Inserted:'.print_r($values,TRUE),array(),WATCHDOG_NOTICE);
     return $no_errors;
   }
-
+         
+  
   // if "select if duplicate" is enabled then check to ensure unique constraint is not violoated.  
   // If it is violoated then simply return, the record already exists in the database.
   // We check for insert_unique for backwards compatibilty but that mode no longer exists
@@ -570,7 +572,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
       (array_key_exists('select_if_duplicate', $table_data) and 
        $table_data['select_if_duplicate'] == 1)) {
     $options = array('is_duplicate' => TRUE);
-    $duplicate = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, $options); 
+    $duplicate = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, $options);
     // if this is a duplicate then substitute the values in the table_data array so
     // that for future records that my depend on this one, they can get the values 
     // needed

+ 10 - 3
tripal_core/api/tripal_core.api.inc

@@ -970,10 +970,14 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
   // to remove all but unique keys
   if ($options['is_duplicate'] and array_key_exists('unique keys', $table_desc)) {
     $ukeys = $table_desc['unique keys'];
-
+    $has_results = 0;
+      
     // iterate through the unique constraints and reset the values and columns
     // arrays to only include these fields
     foreach ($ukeys as $cname => $fields) {
+    	if ($has_results) {
+    	   continue;
+    	}
       $new_values = array();
       $new_columns = array();
       $new_options = array();
@@ -1014,10 +1018,13 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
       $results = tripal_core_chado_select($table, $new_columns, $new_values, $new_options);
       // if we have a duplicate record then return the results
 			if (count($results) > 0) {
-        return $results;
+        $has_results = 1;
       } 
+      unset($new_columns);
+      unset($new_values);
+      unset($new_options);
     }
-    return FALSE;
+    return $results;
   }
 
   foreach ($values as $field => $value) {