Răsfoiți Sursa

Bulk loader now has configuration option to choose whether to use prepared statements or not.

Lacey Sanderson 13 ani în urmă
părinte
comite
bc8dbbed99

Fișier diff suprimat deoarece este prea mare
+ 179 - 143
tripal_bulk_loader/tripal_bulk_loader.admin.inc


+ 103 - 96
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -3,27 +3,27 @@
 /**
 /**
  * Add Loader Job Form
  * Add Loader Job Form
  *
  *
- * This form is meant to be included on the node page to allow users to submit/re-submit 
+ * This form is meant to be included on the node page to allow users to submit/re-submit
  * loading jobs
  * loading jobs
  */
  */
 function tripal_bulk_loader_add_loader_job_form ($form_state, $node) {
 function tripal_bulk_loader_add_loader_job_form ($form_state, $node) {
   $form = array();
   $form = array();
-  
+
   $form['nid'] = array(
   $form['nid'] = array(
     '#type' => 'hidden',
     '#type' => 'hidden',
     '#value' => $node->nid,
     '#value' => $node->nid,
-  ); 
-  
+  );
+
   $form['file'] = array(
   $form['file'] = array(
   	'#type' => 'hidden',
   	'#type' => 'hidden',
   	'#value' => $node->file
   	'#value' => $node->file
   );
   );
-  
+
   $form['job_id'] = array(
   $form['job_id'] = array(
     '#type' => 'hidden',
     '#type' => 'hidden',
     '#value' => $node->job_id,
     '#value' => $node->job_id,
   );
   );
-  
+
   $form['submit'] = array(
   $form['submit'] = array(
     '#type' => 'submit',
     '#type' => 'submit',
     '#value' => ($node->job_id) ? 'Re-Submit Job' : 'Submit Job',
     '#value' => ($node->job_id) ? 'Re-Submit Job' : 'Submit Job',
@@ -33,12 +33,12 @@ function tripal_bulk_loader_add_loader_job_form ($form_state, $node) {
     '#type' => ($node->job_id)? 'submit' : 'hidden',
     '#type' => ($node->job_id)? 'submit' : 'hidden',
     '#value' => 'Cancel Job',
     '#value' => 'Cancel Job',
   );
   );
-  
+
   $form['submit-revert'] = array(
   $form['submit-revert'] = array(
     '#type' => ($node->job_id) ? 'submit' : 'hidden',
     '#type' => ($node->job_id) ? 'submit' : 'hidden',
     '#value' => 'Revert',
     '#value' => 'Revert',
-  );  
-  
+  );
+
   return $form;
   return $form;
 }
 }
 
 
@@ -47,22 +47,22 @@ function tripal_bulk_loader_add_loader_job_form ($form_state, $node) {
  */
  */
 function tripal_bulk_loader_add_loader_job_form_submit ($form, $form_state) {
 function tripal_bulk_loader_add_loader_job_form_submit ($form, $form_state) {
   global $user;
   global $user;
-  
+
   if (preg_match('/Submit Job/', $form_state['values']['op'])) {
   if (preg_match('/Submit Job/', $form_state['values']['op'])) {
     //Submit Tripal Job
     //Submit Tripal Job
 		$job_args[1] = $form_state['values']['nid'];
 		$job_args[1] = $form_state['values']['nid'];
 		if (is_readable($form_state['values']['file'])) {
 		if (is_readable($form_state['values']['file'])) {
 			$fname = basename($form_state['values']['file']);
 			$fname = basename($form_state['values']['file']);
 			$job_id = tripal_add_job("Bulk Loading Job: $fname",'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
 			$job_id = tripal_add_job("Bulk Loading Job: $fname",'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
-			
+
 			// add job_id to bulk_loader node
 			// add job_id to bulk_loader node
       $success = db_query("UPDATE {tripal_bulk_loader} SET job_id=%d WHERE nid=%d", $job_id, $form_state['values']['nid']);
       $success = db_query("UPDATE {tripal_bulk_loader} SET job_id=%d WHERE nid=%d", $job_id, $form_state['values']['nid']);
-      
+
       // change status
       // change status
       db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Submitted to Queue', $form_state['values']['nid']);
       db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Submitted to Queue', $form_state['values']['nid']);
 		} else {
 		} else {
 			drupal_set_message("Can not open ".$form_state['values']['file'].". Job not scheduled.");
 			drupal_set_message("Can not open ".$form_state['values']['file'].". Job not scheduled.");
-		}    
+		}
   } elseif (preg_match('/Re-Submit Job/', $form_state['values']['op'])) {
   } elseif (preg_match('/Re-Submit Job/', $form_state['values']['op'])) {
     tripal_jobs_rerun($form_state['values']['job_id']);
     tripal_jobs_rerun($form_state['values']['job_id']);
     db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Submitted to Queue', $form_state['values']['nid']);
     db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Submitted to Queue', $form_state['values']['nid']);
@@ -70,7 +70,7 @@ function tripal_bulk_loader_add_loader_job_form_submit ($form, $form_state) {
     db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Job Cancelled', $form_state['values']['nid']);
     db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Job Cancelled', $form_state['values']['nid']);
     tripal_jobs_cancel($form_state['values']['job_id']);
     tripal_jobs_cancel($form_state['values']['job_id']);
   } elseif (preg_match('/Revert/', $form_state['values']['op'])) {
   } elseif (preg_match('/Revert/', $form_state['values']['op'])) {
-  
+
     // Remove the records from the database that were already inserted
     // Remove the records from the database that were already inserted
     $resource = db_query('SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d ORDER BY tripal_bulk_loader_inserted_id DESC', $form_state['values']['nid']);
     $resource = db_query('SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d ORDER BY tripal_bulk_loader_inserted_id DESC', $form_state['values']['nid']);
     while ($r = db_fetch_object($resource)) {
     while ($r = db_fetch_object($resource)) {
@@ -84,7 +84,7 @@ function tripal_bulk_loader_add_loader_job_form_submit ($form, $form_state) {
         drupal_set_message('Unable to remove data Inserted into the '.$r->table_inserted_into.' table!', 'error');
         drupal_set_message('Unable to remove data Inserted into the '.$r->table_inserted_into.' table!', 'error');
       }
       }
     }
     }
-    
+
     // reset status
     // reset status
     db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Reverted -Data Deleted', $form_state['values']['nid']);
     db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Reverted -Data Deleted', $form_state['values']['nid']);
   }
   }
@@ -97,30 +97,30 @@ function tripal_bulk_loader_add_loader_job_form_submit ($form, $form_state) {
  * This is the function that's run by tripal_launch_jobs to bulk load chado data.
  * This is the function that's run by tripal_launch_jobs to bulk load chado data.
  *
  *
  * @param $nid
  * @param $nid
- *   The Node ID of the bulk loading job node to be loaded. All other needed data is expected to be 
+ *   The Node ID of the bulk loading job node to be loaded. All other needed data is expected to be
  *   in the node (ie: template ID and file)
  *   in the node (ie: template ID and file)
  *
  *
  * Note: Instead of returning a value this function updates the tripal_bulk_loader.status.
  * Note: Instead of returning a value this function updates the tripal_bulk_loader.status.
  *   Errors are thrown through watchdog and can be viewed at admin/reports/dblog.
  *   Errors are thrown through watchdog and can be viewed at admin/reports/dblog.
  */
  */
 function tripal_bulk_loader_load_data($nid) {
 function tripal_bulk_loader_load_data($nid) {
-  
+
   // ensure no timeout
   // ensure no timeout
   set_time_limit(0);
   set_time_limit(0);
-  
+
   // set the status of the job (in the node not the tripal jobs)
   // set the status of the job (in the node not the tripal jobs)
   db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Loading...', $nid);
   db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Loading...', $nid);
 
 
-  
+
   $node = node_load($nid);
   $node = node_load($nid);
   print "Template: ".$node->template->name." (".$node->template_id.")\n";
   print "Template: ".$node->template->name." (".$node->template_id.")\n";
 
 
   $total_lines = trim(`wc --lines < $node->file`);
   $total_lines = trim(`wc --lines < $node->file`);
   print "File: ".$node->file." (".$total_lines." lines)\n";
   print "File: ".$node->file." (".$total_lines." lines)\n";
-  
+
   // Prep Work ==================================================================================
   // Prep Work ==================================================================================
   $loaded_without_errors = TRUE;
   $loaded_without_errors = TRUE;
-  
+
   // Generate default values array
   // Generate default values array
   $default_data = array();
   $default_data = array();
   $field2column = array();
   $field2column = array();
@@ -130,42 +130,42 @@ function tripal_bulk_loader_load_data($nid) {
     if (!is_array($record_array)) { continue; }
     if (!is_array($record_array)) { continue; }
 
 
     //watchdog('T_bulk_loader','1)'.$record_array['record_id']." => \n<pre>".print_r($record_array,TRUE).'</pre>', array(), WATCHDOG_NOTICE);
     //watchdog('T_bulk_loader','1)'.$record_array['record_id']." => \n<pre>".print_r($record_array,TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-    
+
     foreach ($record_array['fields'] as $field_index => $field_array) {
     foreach ($record_array['fields'] as $field_index => $field_array) {
-      
+
       $default_data[$priority]['table'] = $record_array['table'];
       $default_data[$priority]['table'] = $record_array['table'];
       $default_data[$priority]['mode'] = ($record_array['mode']) ? $record_array['mode'] : 'insert_unique';
       $default_data[$priority]['mode'] = ($record_array['mode']) ? $record_array['mode'] : 'insert_unique';
       $default_data[$priority]['record_id'] = $record_array['record_id'];
       $default_data[$priority]['record_id'] = $record_array['record_id'];
       $record2priority[$record_array['record_id']] = $priority;
       $record2priority[$record_array['record_id']] = $priority;
       $default_data[$priority]['required'][$field_array['field']] = $field_array['required'];
       $default_data[$priority]['required'][$field_array['field']] = $field_array['required'];
-      
+
       $one = $default_data[$priority];
       $one = $default_data[$priority];
       if (isset($field_array['regex'])) {
       if (isset($field_array['regex'])) {
         $default_data[$priority]['regex_transform'][$field_array['field']] = $field_array['regex'];
         $default_data[$priority]['regex_transform'][$field_array['field']] = $field_array['regex'];
       }
       }
-      
+
       $two = $default_data[$priority];
       $two = $default_data[$priority];
-      
+
       if (preg_match('/table field/', $field_array['type'])) {
       if (preg_match('/table field/', $field_array['type'])) {
         $default_data[$priority]['values_array'][$field_array['field']] = '';
         $default_data[$priority]['values_array'][$field_array['field']] = '';
         $default_data[$priority]['need_further_processing'] = TRUE;
         $default_data[$priority]['need_further_processing'] = TRUE;
         $field2column[$priority][$field_array['field']] = $field_array['spreadsheet column'];
         $field2column[$priority][$field_array['field']] = $field_array['spreadsheet column'];
-        
+
       } elseif (preg_match('/constant/', $field_array['type'])) {
       } elseif (preg_match('/constant/', $field_array['type'])) {
         $default_data[$priority]['values_array'][$field_array['field']] = $field_array['constant value'];
         $default_data[$priority]['values_array'][$field_array['field']] = $field_array['constant value'];
-        
+
       } elseif (preg_match('/foreign key/', $field_array['type'])) {
       } elseif (preg_match('/foreign key/', $field_array['type'])) {
         $default_data[$priority]['values_array'][$field_array['field']] = array();
         $default_data[$priority]['values_array'][$field_array['field']] = array();
         $default_data[$priority]['values_array'][$field_array['field']]['foreign record'] = $field_array['foreign key'];
         $default_data[$priority]['values_array'][$field_array['field']]['foreign record'] = $field_array['foreign key'];
         $default_data[$priority]['need_further_processing'] = TRUE;
         $default_data[$priority]['need_further_processing'] = TRUE;
-        
+
       } else {
       } else {
         print 'WARNING: Unsupported type: '. $field_array['type'] . ' for ' . $table . '.' . $field_array['field']."!\n";
         print 'WARNING: Unsupported type: '. $field_array['type'] . ' for ' . $table . '.' . $field_array['field']."!\n";
-      }   
-      
+      }
+
       $three = $default_data[$priority];
       $three = $default_data[$priority];
       //watchdog('T_bulk_loader','A)'.$field_index.':<pre>Field Array =>'.print_r($field_array,TRUE)."Initial => \n".print_r($one, TRUE)."\nAfter Regex =>".print_r($two, TRUE)."Final =>\n".print_r($three,TRUE).'</pre>', array(), WATCHDOG_NOTICE);
       //watchdog('T_bulk_loader','A)'.$field_index.':<pre>Field Array =>'.print_r($field_array,TRUE)."Initial => \n".print_r($one, TRUE)."\nAfter Regex =>".print_r($two, TRUE)."Final =>\n".print_r($three,TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-      
+
     } // end of foreach field
     } // end of foreach field
     //watchdog('T_bulk_loader','2)'.$record_array['record_id'].':<pre>'.print_r($default_data[$priority], TRUE).'</pre>', array(), WATCHDOG_NOTICE);
     //watchdog('T_bulk_loader','2)'.$record_array['record_id'].':<pre>'.print_r($default_data[$priority], TRUE).'</pre>', array(), WATCHDOG_NOTICE);
   } //end of foreach record
   } //end of foreach record
@@ -180,15 +180,15 @@ function tripal_bulk_loader_load_data($nid) {
     // revert default data array for next set of constants
     // revert default data array for next set of constants
     $default_data = $original_default_data;
     $default_data = $original_default_data;
     $group_index++;
     $group_index++;
-    
+
     // Add constants
     // Add constants
     if (!empty($set)) {
     if (!empty($set)) {
       print "Constants:\n";
       print "Constants:\n";
       foreach ($set as $priority => $record) {
       foreach ($set as $priority => $record) {
         foreach ($record as $field_id => $field) {
         foreach ($record as $field_id => $field) {
-        
+
           print "\t- ".$field['chado_table'].'.'.$field['chado_field'].' = '.$field['value']."\n";
           print "\t- ".$field['chado_table'].'.'.$field['chado_field'].' = '.$field['value']."\n";
-          
+
           if ($default_data[$priority]['table'] == $field['chado_table']) {
           if ($default_data[$priority]['table'] == $field['chado_table']) {
             if (isset($default_data[$priority]['values_array'][$field['chado_field']])) {
             if (isset($default_data[$priority]['values_array'][$field['chado_field']])) {
               if (isset($field2column[$priority][$field['chado_field']])) {
               if (isset($field2column[$priority][$field['chado_field']])) {
@@ -209,13 +209,13 @@ function tripal_bulk_loader_load_data($nid) {
         }
         }
       }
       }
     }
     }
-    
+
     //print "Default Data:".print_r($default_data,TRUE)."\n";
     //print "Default Data:".print_r($default_data,TRUE)."\n";
     //watchdog('T_bulk_loader','Default Data:<pre>'.print_r($default_data, TRUE).'</pre>', array(), WATCHDOG_NOTICE);
     //watchdog('T_bulk_loader','Default Data:<pre>'.print_r($default_data, TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-    
+
     //print "\nDefault Values Array: ".print_r($default_data, TRUE)."\n";
     //print "\nDefault Values Array: ".print_r($default_data, TRUE)."\n";
     //print "\nField to Column Mapping: ".print_r($field2column, TRUE)."\n";
     //print "\nField to Column Mapping: ".print_r($field2column, TRUE)."\n";
-    
+
     // Parse File adding records as we go ========================================================
     // Parse File adding records as we go ========================================================
     $file_handle = fopen($node->file, 'r');
     $file_handle = fopen($node->file, 'r');
     if (preg_match('/(t|true|1)/', $node->file_has_header)) { fgets($file_handle, 4096); }
     if (preg_match('/(t|true|1)/', $node->file_has_header)) { fgets($file_handle, 4096); }
@@ -225,55 +225,55 @@ function tripal_bulk_loader_load_data($nid) {
     $interval = intval($total_lines * 0.10);
     $interval = intval($total_lines * 0.10);
     if($interval == 0){ $interval = 1; }
     if($interval == 0){ $interval = 1; }
     while (!feof($file_handle)) {
     while (!feof($file_handle)) {
-  
+
       // Clear variables
       // Clear variables
       // Was added to fix memory leak
       // Was added to fix memory leak
       unset($line);                     unset($raw_line);
       unset($line);                     unset($raw_line);
       unset($data);                     unset($data_keys);
       unset($data);                     unset($data_keys);
       unset($priority);                 unset($sql);
       unset($priority);                 unset($sql);
-      unset($result);                   
-      
+      unset($result);
+
       $raw_line = fgets($file_handle, 4096);
       $raw_line = fgets($file_handle, 4096);
       $raw_line = trim($raw_line);
       $raw_line = trim($raw_line);
       if (empty($raw_line)) { continue; } // skips blank lines
       if (empty($raw_line)) { continue; } // skips blank lines
       $line = explode("\t", $raw_line);
       $line = explode("\t", $raw_line);
       $num_lines++;
       $num_lines++;
-      
+
       // update the job status every 10% of lines processed for the current group
       // update the job status every 10% of lines processed for the current group
       if($node->job_id and $num_lines % $interval == 0){
       if($node->job_id and $num_lines % $interval == 0){
         // percentage of lines processed for the current group
         // percentage of lines processed for the current group
         $group_progress = round(($num_lines/$total_lines)*100);
         $group_progress = round(($num_lines/$total_lines)*100);
-        
+
         // percentage of lines processed for all groups
         // percentage of lines processed for all groups
         // <previous group index> * 100 + <current group progress>
         // <previous group index> * 100 + <current group progress>
         // --------------------------------------------------------
         // --------------------------------------------------------
         //               <total number of groups>
         //               <total number of groups>
-        // For example, if you were in the third group of 3 constant sets 
+        // For example, if you were in the third group of 3 constant sets
         // and had a group percentage of 50% then the job progress would be
         // and had a group percentage of 50% then the job progress would be
         // (2*100 + 50%) / 3 = 250%/3 = 83%
         // (2*100 + 50%) / 3 = 250%/3 = 83%
         $job_progress = round(((($group_index-1)*100)+$group_progress)/$total_num_groups);
         $job_progress = round(((($group_index-1)*100)+$group_progress)/$total_num_groups);
-        
+
         /**
         /**
           print "\nProgress Update:\n"
           print "\nProgress Update:\n"
             ."\t- ".$num_lines." lines have been processed for the current constant set.\n"
             ."\t- ".$num_lines." lines have been processed for the current constant set.\n"
             ."\t- ".$group_progress."% of the lines in the file have been processed for the current constant set.\n"
             ."\t- ".$group_progress."% of the lines in the file have been processed for the current constant set.\n"
             ."\t- ".$job_progress."% of the current job has been completed.\n";
             ."\t- ".$job_progress."% of the current job has been completed.\n";
         */
         */
-         
+
         tripal_job_set_progress($node->job_id,$job_progress);
         tripal_job_set_progress($node->job_id,$job_progress);
-      }    
-  
+      }
+
       $data = $default_data;
       $data = $default_data;
-  
-      $data_keys = array_keys($data); 
+
+      $data_keys = array_keys($data);
       foreach ($data_keys as $priority) {
       foreach ($data_keys as $priority) {
         $status = process_data_array_for_line($priority, $data, $default_data, $field2column, $record2priority, $line, $nid, $num_lines, $group_index);
         $status = process_data_array_for_line($priority, $data, $default_data, $field2column, $record2priority, $line, $nid, $num_lines, $group_index);
         if (!$status ) { $loaded_without_errors = FALSE; }
         if (!$status ) { $loaded_without_errors = FALSE; }
       } // end of foreach table in default data array
       } // end of foreach table in default data array
-      
+
     } //end of foreach line of file
     } //end of foreach line of file
   } //end of foreach constant set
   } //end of foreach constant set
-    
+
   // check that data was inserted and update job_status
   // check that data was inserted and update job_status
   $sql = 'SELECT count(*) as num_tables FROM {tripal_bulk_loader_inserted} WHERE nid=%d GROUP BY nid';
   $sql = 'SELECT count(*) as num_tables FROM {tripal_bulk_loader_inserted} WHERE nid=%d GROUP BY nid';
   $result = db_fetch_object(db_query($sql, $nid));
   $result = db_fetch_object(db_query($sql, $nid));
@@ -281,7 +281,7 @@ function tripal_bulk_loader_load_data($nid) {
     $node->job_status = 'Data Inserted';
     $node->job_status = 'Data Inserted';
     drupal_write_record('node',$node,'nid');
     drupal_write_record('node',$node,'nid');
   }
   }
-  
+
   // set the status of the job (in the node not the tripal jobs)
   // set the status of the job (in the node not the tripal jobs)
   if ($loaded_without_errors) { $status = 'Loading Completed Successfully'; } else { $status = 'Errors Encountered'; }
   if ($loaded_without_errors) { $status = 'Loading Completed Successfully'; } else { $status = 'Errors Encountered'; }
   db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",$status, $nid);
   db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",$status, $nid);
@@ -289,7 +289,7 @@ function tripal_bulk_loader_load_data($nid) {
 }
 }
 
 
 /**
 /**
- * 
+ *
  *
  *
  */
  */
 function process_data_array_for_line ($priority, &$data, &$default_data, $field2column, $record2priority, $line, $nid, $line_num, $group_index) {
 function process_data_array_for_line ($priority, &$data, &$default_data, $field2column, $record2priority, $line, $nid, $line_num, $group_index) {
@@ -299,16 +299,16 @@ function process_data_array_for_line ($priority, &$data, &$default_data, $field2
 
 
   $table = $table_data['table'];
   $table = $table_data['table'];
   $values = $table_data['values_array'];
   $values = $table_data['values_array'];
-  
+
   //watchdog('T_bulk_loader','Original:<pre>'.print_r($table_data, TRUE).'</pre>', array(), WATCHDOG_NOTICE);
   //watchdog('T_bulk_loader','Original:<pre>'.print_r($table_data, TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-  
+
   //print 'default values:'.print_r($values,TRUE)."\n";
   //print 'default values:'.print_r($values,TRUE)."\n";
   if ($table_data['need_further_processing']) {
   if ($table_data['need_further_processing']) {
     $values = tripal_bulk_loader_add_spreadsheetdata_to_values ($values, $line, $field2column[$priority]);
     $values = tripal_bulk_loader_add_spreadsheetdata_to_values ($values, $line, $field2column[$priority]);
     if (!$values) {
     if (!$values) {
       watchdog('T_bulk_loader','Line '.$line_num.' Spreadsheet Added:'.print_r($values, TRUE), array(), WATCHDOG_NOTICE);
       watchdog('T_bulk_loader','Line '.$line_num.' Spreadsheet Added:'.print_r($values, TRUE), array(), WATCHDOG_NOTICE);
     }
     }
-    
+
     $values = tripal_bulk_loader_add_foreignkey_to_values($values, $data, $record2priority);
     $values = tripal_bulk_loader_add_foreignkey_to_values($values, $data, $record2priority);
     if (!$values) {
     if (!$values) {
       watchdog('T_bulk_loader','Line '.$line_num.' FK Added:<pre>'.print_r($values, TRUE).print_r($data[$priority],TRUE).'</pre>', array(), WATCHDOG_NOTICE);
       watchdog('T_bulk_loader','Line '.$line_num.' FK Added:<pre>'.print_r($values, TRUE).print_r($data[$priority],TRUE).'</pre>', array(), WATCHDOG_NOTICE);
@@ -321,12 +321,12 @@ function process_data_array_for_line ($priority, &$data, &$default_data, $field2
 
 
   if (!$values) {
   if (!$values) {
     $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Aborted due to error in previous record. Values of current record:'.print_r($table_data['values_array'],TRUE);
     $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Aborted due to error in previous record. Values of current record:'.print_r($table_data['values_array'],TRUE);
-    watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING); 
+    watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING);
     print "ERROR: ".$msg."\n";
     print "ERROR: ".$msg."\n";
     $data[$priority]['error'] = TRUE;
     $data[$priority]['error'] = TRUE;
     $no_errors = FALSE;
     $no_errors = FALSE;
   }
   }
-  
+
   $table_desc = module_invoke_all('chado_'.$table.'_schema');
   $table_desc = module_invoke_all('chado_'.$table.'_schema');
   if (preg_match('/optional/', $table_array['mode'])) {
   if (preg_match('/optional/', $table_array['mode'])) {
     // Check all db required fields are set
     // Check all db required fields are set
@@ -336,44 +336,44 @@ function process_data_array_for_line ($priority, &$data, &$default_data, $field2
       // value for it or it is of type 'serial'
       // value for it or it is of type 'serial'
       if($def['not null'] == 1 and !array_key_exists($field,$insert_values) and !isset($def['default']) and strcmp($def['type'],serial)!=0){
       if($def['not null'] == 1 and !array_key_exists($field,$insert_values) and !isset($def['default']) and strcmp($def['type'],serial)!=0){
          $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Missing Database Required Value: '.$table.'.'.$field;
          $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Missing Database Required Value: '.$table.'.'.$field;
-         watchdog('T_bulk_loader', $msg, array(), WATCHDOG_NOTICE); 
+         watchdog('T_bulk_loader', $msg, array(), WATCHDOG_NOTICE);
          $data[$priority]['error'] = TRUE;
          $data[$priority]['error'] = TRUE;
       }
       }
     }
     }
   } //end of if optional record
   } //end of if optional record
-  
+
   // Check required fields are present
   // Check required fields are present
   foreach ($table_data['required'] as $field => $required) {
   foreach ($table_data['required'] as $field => $required) {
     if ($required) {
     if ($required) {
       if (!isset($values[$field])) {
       if (!isset($values[$field])) {
         $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Missing Template Required Value: '.$table.'.'.$field;
         $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Missing Template Required Value: '.$table.'.'.$field;
-        watchdog('T_bulk_loader', $msg, array(), WATCHDOG_NOTICE); 
-        $data[$priority]['error'] = TRUE;  
+        watchdog('T_bulk_loader', $msg, array(), WATCHDOG_NOTICE);
+        $data[$priority]['error'] = TRUE;
       }
       }
     }
     }
   }
   }
-  
+
   // add new values array into the data array
   // add new values array into the data array
   $data[$priority]['values_array'] = $values;
   $data[$priority]['values_array'] = $values;
-  
+
   // check if it is already inserted
   // check if it is already inserted
   if ($table_data['inserted']) {
   if ($table_data['inserted']) {
     //watchdog('T_bulk_loader','Already Inserted:'.print_r($values,TRUE),array(),WATCHDOG_NOTICE);
     //watchdog('T_bulk_loader','Already Inserted:'.print_r($values,TRUE),array(),WATCHDOG_NOTICE);
     return $no_errors;
     return $no_errors;
   }
   }
-  
+
   // if there was an error already -> don't insert
   // if there was an error already -> don't insert
   if ($data[$priority]['error']) {
   if ($data[$priority]['error']) {
     return $no_errors;
     return $no_errors;
   }
   }
-  
+
   $header = '';
   $header = '';
   if (isset($values['feature_id'])) {
   if (isset($values['feature_id'])) {
     $header = $values['feature_id']['uniquename'] .' '. $table_data['record_id'];
     $header = $values['feature_id']['uniquename'] .' '. $table_data['record_id'];
   } else {
   } else {
     $header = $values['uniquename'] .' '. $table_data['record_id'];
     $header = $values['uniquename'] .' '. $table_data['record_id'];
   }
   }
-  
+
   // if insert unique then check to ensure unique
   // if insert unique then check to ensure unique
   if (preg_match('/insert_unique/',$table_data['mode'])) {
   if (preg_match('/insert_unique/',$table_data['mode'])) {
     $unique = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, array('has_record'=>TRUE));
     $unique = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, array('has_record'=>TRUE));
@@ -384,31 +384,38 @@ function process_data_array_for_line ($priority, &$data, &$default_data, $field2
       return $no_errors;
       return $no_errors;
     }
     }
   }
   }
-  
-    
+
+
   if (!preg_match('/select/',$table_data['mode'])) {
   if (!preg_match('/select/',$table_data['mode'])) {
     //watchdog('T_bulk_loader',$header.': Inserting:'.print_r($values, TRUE), array(), WATCHDOG_NOTICE);
     //watchdog('T_bulk_loader',$header.': Inserting:'.print_r($values, TRUE), array(), WATCHDOG_NOTICE);
-    $options = array('statement_name' => $priority);
-    if ($line_num == 1 && $group_index == 1) {
-      $options['prepare'] = TRUE;
+    if (variable_get('tripal_bulk_loader_prepare',TRUE)) {
+      $options = array('statement_name' => $priority);
+      if ($line_num == 1 && $group_index == 1) {
+        $options['prepare'] = TRUE;
+      }
     }
     }
+    else {
+      $options = array();
+    }
+
     $record = tripal_core_chado_insert($table, $values, $options);
     $record = tripal_core_chado_insert($table, $values, $options);
+
     if (!$record) {
     if (!$record) {
       $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Unable to insert record into '.$table.' where values:'.print_r($values,TRUE);
       $msg = 'Line '.$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";  
+      watchdog('T_bulk_loader', $msg, array(), WATCHDOG_ERROR);
+      print "ERROR: ".$msg."\n";
       $data[$priority]['error'] = TRUE;
       $data[$priority]['error'] = TRUE;
       $no_errors = FALSE;
       $no_errors = FALSE;
     } else {
     } else {
       //add changes back to values array
       //add changes back to values array
       $data[$priority]['values_array'] = $record;
       $data[$priority]['values_array'] = $record;
       $values = $record;
       $values = $record;
-      
+
       // if mode=insert_once then ensure we only insert it once
       // if mode=insert_once then ensure we only insert it once
       if (preg_match('/insert_once/',$table_data['mode'])) {
       if (preg_match('/insert_once/',$table_data['mode'])) {
         $default_data[$priority]['inserted'] = TRUE;
         $default_data[$priority]['inserted'] = TRUE;
       }
       }
-      
+
       // add to tripal_bulk_loader_inserted
       // add to tripal_bulk_loader_inserted
       $insert_record = db_fetch_object(db_query(
       $insert_record = db_fetch_object(db_query(
         "SELECT * FROM {tripal_bulk_loader_inserted} WHERE table_inserted_into='%s' AND nid=%d",
         "SELECT * FROM {tripal_bulk_loader_inserted} WHERE table_inserted_into='%s' AND nid=%d",
@@ -431,15 +438,15 @@ function process_data_array_for_line ($priority, &$data, &$default_data, $field2
         $success = drupal_write_record('tripal_bulk_loader_inserted', $insert_record);
         $success = drupal_write_record('tripal_bulk_loader_inserted', $insert_record);
         return $no_errors;
         return $no_errors;
       }//end of if insert record
       }//end of if insert record
-      
+
     } //end of if insert was successful
     } //end of if insert was successful
   } else {
   } else {
     $exists = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, array('has_record'=>TRUE));
     $exists = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, array('has_record'=>TRUE));
     if (!$exists) {
     if (!$exists) {
       // No record on select
       // No record on select
       $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') No Matching record in '.$table.' where values:'.print_r($values,TRUE);
       $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') No Matching record in '.$table.' where values:'.print_r($values,TRUE);
-      watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING); 
-      $data[$priority]['error'] = TRUE;  
+      watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING);
+      $data[$priority]['error'] = TRUE;
     }
     }
   }
   }
   return $no_errors;
   return $no_errors;
@@ -454,24 +461,24 @@ function process_data_array_for_line ($priority, &$data, &$default_data, $field2
  *   An array of values for the current line
  *   An array of values for the current line
  * @param $field2column
  * @param $field2column
  *   An array mapping values fields to line columns
  *   An array mapping values fields to line columns
- * @return 
+ * @return
  *   Supplemented values array
  *   Supplemented values array
  */
  */
 function tripal_bulk_loader_add_spreadsheetdata_to_values ($values, $line, $field2column) {
 function tripal_bulk_loader_add_spreadsheetdata_to_values ($values, $line, $field2column) {
 
 
   foreach ($values as $field => $value) {
   foreach ($values as $field => $value) {
     if (is_array($value)) { continue; }
     if (is_array($value)) { continue; }
-    
+
     $column = $field2column[$field] - 1;
     $column = $field2column[$field] - 1;
     if ($column < 0) { continue; }
     if ($column < 0) { continue; }
-    
+
     if (preg_match('/\S+/',$line[$column])) {
     if (preg_match('/\S+/',$line[$column])) {
       $values[$field] = $line[$column];
       $values[$field] = $line[$column];
     } else {
     } else {
       unset($values[$field]);
       unset($values[$field]);
     }
     }
   }
   }
-  
+
   return $values;
   return $values;
 }
 }
 
 
@@ -490,7 +497,7 @@ function tripal_bulk_loader_add_foreignkey_to_values($values, $data, $record2pri
       $foreign_record = $value['foreign record'];
       $foreign_record = $value['foreign record'];
       $foreign_priority = $record2priority[$foreign_record];
       $foreign_priority = $record2priority[$foreign_record];
       $foreign_values = $data[$foreign_priority]['values_array'];
       $foreign_values = $data[$foreign_priority]['values_array'];
-      
+
       // add to current values array
       // add to current values array
       $values[$field] = $foreign_values;
       $values[$field] = $foreign_values;
     }
     }
@@ -510,16 +517,16 @@ function tripal_bulk_loader_add_foreignkey_to_values($values, $data, $record2pri
 function tripal_bulk_loader_regex_tranform_values ($values, $table_data, $line) {
 function tripal_bulk_loader_regex_tranform_values ($values, $table_data, $line) {
 
 
   if (empty($table_data['regex_transform']) OR !is_array($table_data['regex_transform'])) { return $values; }
   if (empty($table_data['regex_transform']) OR !is_array($table_data['regex_transform'])) { return $values; }
-  
+
   //watchdog('T_bulk_loader','Regex Transformation:<pre>'.print_r($table_data['regex_transform'], TRUE).'</pre>', array(), WATCHDOG_NOTICE);
   //watchdog('T_bulk_loader','Regex Transformation:<pre>'.print_r($table_data['regex_transform'], TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-  
+
   foreach ($table_data['regex_transform'] as $field => $regex_array) {
   foreach ($table_data['regex_transform'] as $field => $regex_array) {
     if (!is_array($regex_array['replace'])) { continue; }
     if (!is_array($regex_array['replace'])) { continue; }
-    
+
     //print 'Match:'.print_r($regex_array['pattern'],TRUE)."\n";
     //print 'Match:'.print_r($regex_array['pattern'],TRUE)."\n";
     //print 'Replace:'.print_r($regex_array['replace'],TRUE)."\n";
     //print 'Replace:'.print_r($regex_array['replace'],TRUE)."\n";
     //print 'Was:'.$values[$field]."\n";
     //print 'Was:'.$values[$field]."\n";
-    
+
     // Check for <#column:\d+#> notation
     // Check for <#column:\d+#> notation
     // if present replace with that column in the current line
     // if present replace with that column in the current line
     foreach ($regex_array['replace'] as $key => $replace) {
     foreach ($regex_array['replace'] as $key => $replace) {
@@ -530,19 +537,19 @@ function tripal_bulk_loader_regex_tranform_values ($values, $table_data, $line)
         $regex_array['replace'][$key] = $replace;
         $regex_array['replace'][$key] = $replace;
       }
       }
     }
     }
-    
+
     // do the full replacement
     // do the full replacement
     $old_value = $values[$field];
     $old_value = $values[$field];
     $new_value = preg_replace($regex_array['pattern'], $regex_array['replace'], $old_value);
     $new_value = preg_replace($regex_array['pattern'], $regex_array['replace'], $old_value);
     $values[$field] = $new_value;
     $values[$field] = $new_value;
-    
+
     if ($values[$field] === '') {
     if ($values[$field] === '') {
-      unset($values[$field]); 
+      unset($values[$field]);
     }
     }
     //print 'Now:'.$values[$field]."\n";
     //print 'Now:'.$values[$field]."\n";
   }
   }
-  
-  
+
+
 
 
   return $values;
   return $values;
 }
 }
@@ -553,7 +560,7 @@ function tripal_bulk_loader_regex_tranform_values ($values, $table_data, $line)
  */
  */
 function tripal_bulk_loader_flatten_array ($values) {
 function tripal_bulk_loader_flatten_array ($values) {
   $flattened_values = array();
   $flattened_values = array();
-  
+
   foreach ($values as $k => $v) {
   foreach ($values as $k => $v) {
     if (is_array($v)) {
     if (is_array($v)) {
       $vstr = array();
       $vstr = array();
@@ -570,6 +577,6 @@ function tripal_bulk_loader_flatten_array ($values) {
     }
     }
     $flattened_values[] = $k .'=>'. $v;
     $flattened_values[] = $k .'=>'. $v;
   }
   }
-  
+
   return implode(', ',$flattened_values);
   return implode(', ',$flattened_values);
 }
 }

+ 68 - 57
tripal_bulk_loader/tripal_bulk_loader.module

@@ -33,7 +33,7 @@ function tripal_bulk_loader_menu() {
     	'page callback' => 'drupal_get_form',
     	'page callback' => 'drupal_get_form',
     	'page arguments' => array('tripal_bulk_loader_edit_constant_set_form',1,3),
     	'page arguments' => array('tripal_bulk_loader_edit_constant_set_form',1,3),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,   
+      'type' => MENU_CALLBACK,
 		  'file' => 'tripal_bulk_loader.constants.inc',
 		  'file' => 'tripal_bulk_loader.constants.inc',
    );
    );
    $items['node/%node/constants/%/delete'] = array(
    $items['node/%node/constants/%/delete'] = array(
@@ -42,18 +42,29 @@ function tripal_bulk_loader_menu() {
     	'page callback' => 'drupal_get_form',
     	'page callback' => 'drupal_get_form',
     	'page arguments' => array('tripal_bulk_loader_delete_constant_set_form',1,3),
     	'page arguments' => array('tripal_bulk_loader_delete_constant_set_form',1,3),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,   
+      'type' => MENU_CALLBACK,
 		  'file' => 'tripal_bulk_loader.constants.inc',
 		  'file' => 'tripal_bulk_loader.constants.inc',
    );
    );
+
    // Admin page to create the template
    // Admin page to create the template
    $items['admin/tripal/tripal_bulk_loader_template'] = array(
    $items['admin/tripal/tripal_bulk_loader_template'] = array(
       'title' => 'Bulk Loader Template',
       'title' => 'Bulk Loader Template',
       'description' => 'Templates for loading tab-delimited data',
       'description' => 'Templates for loading tab-delimited data',
     	'page callback' => 'tripal_bulk_loader_admin_template',
     	'page callback' => 'tripal_bulk_loader_admin_template',
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,   
+      'type' => MENU_NORMAL_ITEM,
+		  'file' => 'tripal_bulk_loader.admin.inc',
+	);
+   $items['admin/tripal/tripal_bulk_loader_template/configure'] = array(
+      'title' => 'Configuration',
+      'description' => 'Configure the Tripal Bulk Loader Module',
+    	'page callback' => 'drupal_get_form',
+    	'page arguments' => array('tripal_bulk_loader_configuration_form'),
+      'access arguments' => array('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM,
 		  'file' => 'tripal_bulk_loader.admin.inc',
 		  'file' => 'tripal_bulk_loader.admin.inc',
 	);
 	);
+
 	// Create/Edit Template -------
 	// Create/Edit Template -------
   $items['admin/tripal/tripal_bulk_loader_template/create'] = array(
   $items['admin/tripal/tripal_bulk_loader_template/create'] = array(
       'title' => 'Create Bulk Loader Template',
       'title' => 'Create Bulk Loader Template',
@@ -61,7 +72,7 @@ function tripal_bulk_loader_menu() {
       'page callback' => 'drupal_get_form',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'create'),
       'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'create'),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,   
+      'type' => MENU_NORMAL_ITEM,
 		'file' => 'tripal_bulk_loader.admin.inc',
 		'file' => 'tripal_bulk_loader.admin.inc',
   );
   );
   $items['admin/tripal/tripal_bulk_loader_template/edit'] = array(
   $items['admin/tripal/tripal_bulk_loader_template/edit'] = array(
@@ -70,8 +81,8 @@ function tripal_bulk_loader_menu() {
       'page callback' => 'drupal_get_form',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'edit'),
       'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'edit'),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,   
-		  'file' => 'tripal_bulk_loader.admin.inc',  
+      'type' => MENU_NORMAL_ITEM,
+		  'file' => 'tripal_bulk_loader.admin.inc',
   );
   );
 	$items['admin/tripal/tripal_bulk_loader_template/edit_record'] = array(
 	$items['admin/tripal/tripal_bulk_loader_template/edit_record'] = array(
       'title' => 'Edit Template Record',
       'title' => 'Edit Template Record',
@@ -79,7 +90,7 @@ function tripal_bulk_loader_menu() {
       'page callback' => 'drupal_get_form',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_bulk_loader_edit_template_record_form'),
       'page arguments' => array('tripal_bulk_loader_edit_template_record_form'),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,   
+      'type' => MENU_CALLBACK,
 		'file' => 'tripal_bulk_loader.admin.inc',
 		'file' => 'tripal_bulk_loader.admin.inc',
 	);
 	);
 	$items['admin/tripal/tripal_bulk_loader_template/add_field'] = array(
 	$items['admin/tripal/tripal_bulk_loader_template/add_field'] = array(
@@ -88,7 +99,7 @@ function tripal_bulk_loader_menu() {
       'page callback' => 'drupal_get_form',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_bulk_loader_add_template_field_form'),
       'page arguments' => array('tripal_bulk_loader_add_template_field_form'),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,   
+      'type' => MENU_CALLBACK,
 		'file' => 'tripal_bulk_loader.admin.inc',
 		'file' => 'tripal_bulk_loader.admin.inc',
 	);
 	);
 	$items['admin/tripal/tripal_bulk_loader_template/edit_field'] = array(
 	$items['admin/tripal/tripal_bulk_loader_template/edit_field'] = array(
@@ -97,7 +108,7 @@ function tripal_bulk_loader_menu() {
       'page callback' => 'drupal_get_form',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_bulk_loader_edit_template_field_form'),
       'page arguments' => array('tripal_bulk_loader_edit_template_field_form'),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,   
+      'type' => MENU_CALLBACK,
 		'file' => 'tripal_bulk_loader.admin.inc',
 		'file' => 'tripal_bulk_loader.admin.inc',
 	);
 	);
 	// Delete Template -----
 	// Delete Template -----
@@ -107,7 +118,7 @@ function tripal_bulk_loader_menu() {
       'page callback' => 'drupal_get_form',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_bulk_loader_delete_template_base_form'),
       'page arguments' => array('tripal_bulk_loader_delete_template_base_form'),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,   
+      'type' => MENU_NORMAL_ITEM,
 		'file' => 'tripal_bulk_loader.admin.inc',
 		'file' => 'tripal_bulk_loader.admin.inc',
 	);
 	);
 	// Import/Export ---------
 	// Import/Export ---------
@@ -117,32 +128,32 @@ function tripal_bulk_loader_menu() {
       'page callback' => 'drupal_get_form',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'import'),
       'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'import'),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,   
-		  'file' => 'tripal_bulk_loader.admin.inc',  
-  );	
+      'type' => MENU_NORMAL_ITEM,
+		  'file' => 'tripal_bulk_loader.admin.inc',
+  );
   $items['admin/tripal/tripal_bulk_loader_template/export'] = array(
   $items['admin/tripal/tripal_bulk_loader_template/export'] = array(
       'title' => 'Export Bulk Loader Template',
       'title' => 'Export Bulk Loader Template',
       'description' => 'Export Loaders',
       'description' => 'Export Loaders',
       'page callback' => 'drupal_get_form',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'export'),
       'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'export'),
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,   
-		  'file' => 'tripal_bulk_loader.admin.inc',  
-  );	
+      'type' => MENU_NORMAL_ITEM,
+		  'file' => 'tripal_bulk_loader.admin.inc',
+  );
 	// AHAH ---------
 	// AHAH ---------
 	$items['admin/tripal/tripal_bulk_loader_template/add_field_ahah'] = array(
 	$items['admin/tripal/tripal_bulk_loader_template/add_field_ahah'] = array(
       'page callback' => 'tripal_bulk_loader_add_field_ahah',
       'page callback' => 'tripal_bulk_loader_add_field_ahah',
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,   
-		  'file' => 'tripal_bulk_loader.admin.inc',	
+      'type' => MENU_CALLBACK,
+		  'file' => 'tripal_bulk_loader.admin.inc',
 	);
 	);
 	$items['admin/tripal/tripal_bulk_loader_template/edit_field_ahah'] = array(
 	$items['admin/tripal/tripal_bulk_loader_template/edit_field_ahah'] = array(
       'page callback' => 'tripal_bulk_loader_edit_field_ahah',
       'page callback' => 'tripal_bulk_loader_edit_field_ahah',
       'access arguments' => array('administer site configuration'),
       'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,   
-		  'file' => 'tripal_bulk_loader.admin.inc',	
+      'type' => MENU_CALLBACK,
+		  'file' => 'tripal_bulk_loader.admin.inc',
 	);
 	);
-	
+
   return $items;
   return $items;
 }
 }
 
 
@@ -219,10 +230,10 @@ function tripal_bulk_loader_perm(){
 function tripal_bulk_loader_list () {
 function tripal_bulk_loader_list () {
   $num_results_per_page = 50;
   $num_results_per_page = 50;
   $output = '';
   $output = '';
-  
+
   $header = array('','Status','Loader','File');
   $header = array('','Status','Loader','File');
   $rows = array();
   $rows = array();
-  
+
   $query = 'SELECT * FROM {tripal_bulk_loader} l '
   $query = 'SELECT * FROM {tripal_bulk_loader} l '
     .'LEFT JOIN {node} n ON n.nid = l.nid '
     .'LEFT JOIN {node} n ON n.nid = l.nid '
     .'LEFT JOIN {tripal_bulk_loader_template} t ON t.template_id = cast(l.template_id as integer)';
     .'LEFT JOIN {tripal_bulk_loader_template} t ON t.template_id = cast(l.template_id as integer)';
@@ -236,10 +247,10 @@ function tripal_bulk_loader_list () {
     );
     );
     $rows[] = $row;
     $rows[] = $row;
   }
   }
-  
+
   $output .= theme('table', $header, $rows);
   $output .= theme('table', $header, $rows);
   return $output;
   return $output;
-  
+
 }
 }
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////
@@ -268,34 +279,34 @@ function tripal_bulk_loader_node_info() {
  */
  */
 function tripal_bulk_loader_form ($node, $form_state){
 function tripal_bulk_loader_form ($node, $form_state){
   $form = array();
   $form = array();
-  
+
   if (isset($form_state['values'])) {
   if (isset($form_state['values'])) {
     $node = $form_state['values'] + (array)$node;
     $node = $form_state['values'] + (array)$node;
     $node = (object) $node;
     $node = (object) $node;
   }
   }
-  
+
   $sql = "SELECT * FROM {tripal_bulk_loader_template}";
   $sql = "SELECT * FROM {tripal_bulk_loader_template}";
   $results = db_query($sql);
   $results = db_query($sql);
   $templates = array ();
   $templates = array ();
   while ($template = db_fetch_object ($results)) {
   while ($template = db_fetch_object ($results)) {
     $templates [$template->template_id] = $template->name;
     $templates [$template->template_id] = $template->name;
   }
   }
-  
+
   if (!$templates) {
   if (!$templates) {
     $form['label'] = array(
     $form['label'] = array(
     '#type' => 'item',
     '#type' => 'item',
       '#description' => t("Loader template needs to be created before any bulk loader can be added. Go to 'Tripal Management > Bulk Loader Template' to create the template."),
       '#description' => t("Loader template needs to be created before any bulk loader can be added. Go to 'Tripal Management > Bulk Loader Template' to create the template."),
       '#weight'        => -10,
       '#weight'        => -10,
     );
     );
-    
+
     return $form;
     return $form;
   }
   }
-  
+
   $form['loader'] = array(
   $form['loader'] = array(
     '#type' => 'fieldset',
     '#type' => 'fieldset',
     '#title' => t('Basic Details'),
     '#title' => t('Basic Details'),
   );
   );
-  
+
   $form['loader']['loader_name'] = array(
   $form['loader']['loader_name'] = array(
     '#type'          => 'textfield',
     '#type'          => 'textfield',
     '#title'         => t('Loading Job Name'),
     '#title'         => t('Loading Job Name'),
@@ -303,7 +314,7 @@ function tripal_bulk_loader_form ($node, $form_state){
     '#required'      => TRUE,
     '#required'      => TRUE,
     '#default_value' => $node->loader_name
     '#default_value' => $node->loader_name
   );
   );
-  
+
   $form['loader']['template_id'] = array(
   $form['loader']['template_id'] = array(
     '#type' => 'select',
     '#type' => 'select',
     '#title' => t('Template'),
     '#title' => t('Template'),
@@ -313,7 +324,7 @@ function tripal_bulk_loader_form ($node, $form_state){
     '#required'      => TRUE,
     '#required'      => TRUE,
     '#default_value' => $node->template_id,
     '#default_value' => $node->template_id,
   );
   );
-  
+
   $form['loader']['file']= array(
   $form['loader']['file']= array(
     '#type'          => 'textfield',
     '#type'          => 'textfield',
     '#title'         => t('Data File'),
     '#title'         => t('Data File'),
@@ -321,7 +332,7 @@ function tripal_bulk_loader_form ($node, $form_state){
     '#weight'        => -8,
     '#weight'        => -8,
     '#default_value' => $node->file
     '#default_value' => $node->file
   );
   );
-  
+
   $form['loader']['has_header'] = array(
   $form['loader']['has_header'] = array(
     '#type' => 'radios',
     '#type' => 'radios',
     '#title' => t('File has a Header'),
     '#title' => t('File has a Header'),
@@ -329,7 +340,7 @@ function tripal_bulk_loader_form ($node, $form_state){
     '#weight' => -7,
     '#weight' => -7,
     '#default_value' => $node->file_has_header,
     '#default_value' => $node->file_has_header,
   );
   );
-  
+
   return $form;
   return $form;
 }
 }
 
 
@@ -342,7 +353,7 @@ function tripal_bulk_loader_load($node){
 	$node = db_fetch_object(db_query($sql, $node->nid));
 	$node = db_fetch_object(db_query($sql, $node->nid));
 
 
 	$node->title = 'Bulk Loading Job: '.$node->loader_name;
 	$node->title = 'Bulk Loading Job: '.$node->loader_name;
-	
+
 	// Add the loader template
 	// Add the loader template
 	$sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
 	$sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
 	$results = db_fetch_object(db_query($sql, $node->template_id));
 	$results = db_fetch_object(db_query($sql, $node->template_id));
@@ -354,7 +365,7 @@ function tripal_bulk_loader_load($node){
   $sql = 'SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d';
   $sql = 'SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d';
   $resource = db_query($sql,$node->nid);
   $resource = db_query($sql,$node->nid);
   while ($r = db_fetch_object($resource)) {
   while ($r = db_fetch_object($resource)) {
-    $r->num_inserted = sizeof(preg_split('/,/',$r->ids_inserted)); 
+    $r->num_inserted = sizeof(preg_split('/,/',$r->ids_inserted));
     $node->inserted_records->{$r->table_inserted_into} = $r;
     $node->inserted_records->{$r->table_inserted_into} = $r;
   }
   }
 
 
@@ -372,13 +383,13 @@ function tripal_bulk_loader_load($node){
         }
         }
       }
       }
     }
     }
-    
+
     if (empty($node->exposed_fields)) {
     if (empty($node->exposed_fields)) {
       $node->exposed_fields[] = array();
       $node->exposed_fields[] = array();
     }
     }
   }
   }
 
 
-  
+
   // Add constants
   // Add constants
   $sql = 'SELECT * FROM {tripal_bulk_loader_constants} WHERE nid=%d ORDER BY group_id, record_id, field_id';
   $sql = 'SELECT * FROM {tripal_bulk_loader_constants} WHERE nid=%d ORDER BY group_id, record_id, field_id';
   $resource = db_query($sql,$node->nid);
   $resource = db_query($sql,$node->nid);
@@ -386,17 +397,17 @@ function tripal_bulk_loader_load($node){
     $node->constants[$r->group_id][$r->record_id][$r->field_id] = array(
     $node->constants[$r->group_id][$r->record_id][$r->field_id] = array(
       'constant_id' => $r->constant_id,
       'constant_id' => $r->constant_id,
       'group_id' => $r->group_id,
       'group_id' => $r->group_id,
-      'chado_table'=>$r->chado_table, 
-      'chado_field'=>$r->chado_field, 
-      'record_id'=>$r->record_id, 
-      'field_id'=>$r->field_id, 
+      'chado_table'=>$r->chado_table,
+      'chado_field'=>$r->chado_field,
+      'record_id'=>$r->record_id,
+      'field_id'=>$r->field_id,
       'value'=>$r->value
       'value'=>$r->value
     );
     );
   }
   }
   if (!$node->constants) {
   if (!$node->constants) {
     $node->constants[] = array();
     $node->constants[] = array();
   }
   }
-  
+
 	return $node;
 	return $node;
 }
 }
 
 
@@ -405,18 +416,18 @@ function tripal_bulk_loader_load($node){
  * Insert the data from the node form on Create content
  * Insert the data from the node form on Create content
  */
  */
 function tripal_bulk_loader_insert ($node) {
 function tripal_bulk_loader_insert ($node) {
-  
+
   // Insert into tripal_bulk_loader
   // Insert into tripal_bulk_loader
   $sql = "INSERT INTO {tripal_bulk_loader} (nid, loader_name, template_id, file, file_has_header, job_status) VALUES (%d, '%s', %d, '%s', %d, '%s')";
   $sql = "INSERT INTO {tripal_bulk_loader} (nid, loader_name, template_id, file, file_has_header, job_status) VALUES (%d, '%s', %d, '%s', %d, '%s')";
   db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, 'Initialized');
   db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, 'Initialized');
-	
+
 	// Update title
 	// Update title
 	$node->title =$node->loader_name;
 	$node->title =$node->loader_name;
 	drupal_write_record('node',$node,'nid');
 	drupal_write_record('node',$node,'nid');
-	drupal_write_record('node_revision',$node,'nid');	
-  
+	drupal_write_record('node_revision',$node,'nid');
+
   drupal_set_message('After reviewing the details, please Submit this Job (by clicking the "Submit Job" button below). No data will be loaded until the submitted job is reached in the queue.');
   drupal_set_message('After reviewing the details, please Submit this Job (by clicking the "Submit Job" button below). No data will be loaded until the submitted job is reached in the queue.');
-  
+
 }
 }
 
 
 /**
 /**
@@ -433,11 +444,11 @@ function tripal_bulk_loader_delete ($node) {
  * Updates the data submitted by the node form on edit
  * Updates the data submitted by the node form on edit
  */
  */
 function tripal_bulk_loader_update ($node) {
 function tripal_bulk_loader_update ($node) {
-  
+
   // Update tripal_bulk_loader
   // Update tripal_bulk_loader
 	$sql = "UPDATE {tripal_bulk_loader} SET nid = %d, loader_name = '%s', template_id = %d, file = '%s', file_has_header = '%s' WHERE nid = %d";
 	$sql = "UPDATE {tripal_bulk_loader} SET nid = %d, loader_name = '%s', template_id = %d, file = '%s', file_has_header = '%s' WHERE nid = %d";
 	db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, $node->nid);
 	db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, $node->nid);
-	
+
 	// Add a job if the user want to load the data
 	// Add a job if the user want to load the data
 	global $user;
 	global $user;
 	if($node->job) {
 	if($node->job) {
@@ -451,7 +462,7 @@ function tripal_bulk_loader_update ($node) {
 			drupal_set_message("Can not open $node->file. Job not scheduled.");
 			drupal_set_message("Can not open $node->file. Job not scheduled.");
 		}
 		}
 	}
 	}
-  
+
 }
 }
 
 
 ///////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////
@@ -463,9 +474,9 @@ function tripal_bulk_loader_preprocess_tripal_bulk_loader_template (&$variables)
 
 
 	$sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
 	$sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
 	$template = db_fetch_object(db_query($sql, $variables['template_id']));
 	$template = db_fetch_object(db_query($sql, $variables['template_id']));
-	$template->template_array = unserialize($template->template_array);	
+	$template->template_array = unserialize($template->template_array);
 	$variables['template'] = $template;
 	$variables['template'] = $template;
-	
+
 }
 }
 
 
 /**
 /**
@@ -476,8 +487,8 @@ function tripal_bulk_loader_preprocess_tripal_bulk_loader_template (&$variables)
  *   The callback passed into tripal_add_job()
  *   The callback passed into tripal_add_job()
  * @param $args
  * @param $args
  *   The arguements passed into tripal_add_job()
  *   The arguements passed into tripal_add_job()
- * @return 
- *   An array where keys are the human readable headers describing each arguement 
+ * @return
+ *   An array where keys are the human readable headers describing each arguement
  *   and the value is the aguement passed in after formatting
  *   and the value is the aguement passed in after formatting
  */
  */
 function tripal_bulk_loader_job_describe_args($callback,$args){
 function tripal_bulk_loader_job_describe_args($callback,$args){
@@ -489,6 +500,6 @@ function tripal_bulk_loader_job_describe_args($callback,$args){
     $new_args['Bulk Loading Job'] = l($node->title, 'node/'.$args[0]);
     $new_args['Bulk Loading Job'] = l($node->title, 'node/'.$args[0]);
     return $new_args;
     return $new_args;
   }
   }
-  
+
 }
 }
 
 

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff