Bläddra i källkod

Added disabled checkbox to bulk loader; Separated unique checkbox to bulk loader; Fixed bug in integration of custom tables with views integration

spficklin 12 år sedan
förälder
incheckning
3f6c4f5d1b

+ 69 - 7
tripal_bulk_loader/tripal_bulk_loader.admin.templates.inc

@@ -134,6 +134,32 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
 
         $form['records']['no_records']['#value'] = FALSE;
 
+        // for backwards compatibility we want to convert insert_unique to be 'insert'
+        if (strcmp($table_array['mode'],'insert_unique')==0) {
+          $mode_value = 'insert or select if duplicate';
+        } 
+        elseif (strcmp($table_array['mode'],'optional')==0) {
+          $mode_value = 'optional insert';
+        } 
+        elseif (strcmp($table_array['mode'],'insert_once')==0) {
+          $mode_value = 'insert once';
+        } 
+        elseif ($table_array['mode']) {
+          $mode_value = $table_array['mode'];
+        }
+        else {
+          $mode_value = 'insert';
+        }
+        
+        // add in the select if duplicate 
+        if ($table_array['select_if_duplicate']) {
+          $mode_value .= ' or select if duplicate';
+        } 
+        
+        if ($table_array['disable']) {
+          $mode_value .= '. <font color="Red">DISABLED</font>';
+        } 
+        
         $form['records']['records-data'][$priority] = array(
           'title' => array(
             '#type' => 'markup',
@@ -145,7 +171,7 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
           ),
           'mode' => array(
             '#type' => 'item',
-            '#value' => ($table_array['mode']) ? $table_array['mode'] : 'insert_unique',
+            '#value' => $mode_value,
           ),
           'new_priority' => array(
             '#type' => 'select',
@@ -612,13 +638,34 @@ function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
 
 
   // Tables and default table
-  $tables = tripal_core_get_chado_tables();
+  $tables = tripal_core_get_chado_tables(TRUE);
   if ($form_state['values']['chado_table']) {
     $table = $form_state['values']['chado_table'];
   }
   else {
     $table = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['table'];
   }
+  
+  // get the default of the mode
+  $mode = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['mode'];
+  if(!$mode){
+     $mode = 'insert';
+  }
+  // get default for the select if duplicate
+  $select_if_duplicate = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['select_if_duplicate'];
+  if(!isset($select_if_duplicate)){
+    $select_if_duplicate = 1;
+  }
+
+  // get the default for disabling the record
+  $disable = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['disable'];
+
+  // this is just for backwards compatibility. the insert_unique mode type is no longer available
+  if(strcmp($mode,'insert_unique')==0){
+     $mode = 'insert';
+     $select_if_duplicate = 1;
+  }
+  
 
   //dpm($form_state, 'form state');
 
@@ -675,11 +722,24 @@ function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
     '#options' => array(
       'select' => 'SELECT: Don\'t insert this record: it\'s used to define a foreign key in another record',
       'insert' => 'INSERT: Insert the record',
-      'optional' => 'OPTIONAL: Record will only be inserted if all required data is filled in',
+      'optional' => 'INSERT OPTIONAL: Record will only be inserted if all required data is filled in',
       'insert_once' => 'INSERT ONCE: Record will be inserted once for the entire file',
-      'insert_unique' => 'INSERT UNIQUE: Only insert record if there isn\'t a record with the same values',
     ),
-    '#default_value' => 'insert_unique'
+    '#default_value' => $mode
+  );
+  
+  $form['edit_record']['select_if_duplicate'] = array(
+     '#type' => 'checkbox',
+     '#title' => t('Do INSERT, or SELECT if Duplicate'),
+     '#description' => t('Perform the insert as selected above. If this is the first time this record has been added then perform an insert. Otherwise, perform a select.  The unique constraint for the table will be checked prior to insert.'),
+     '#default_value' => $select_if_duplicate
+  );
+  
+  $form['edit_record']['disable'] = array(
+     '#type' => 'checkbox',
+     '#title' => t('Disable this record'),
+     '#description' => t("Check this box to ignore this record (not perform select or insert) during template loading.  Uncheck to re-enable the record"),
+     '#default_value' => $disable,
   );
 
   $form['edit_record']['submit-edit_record'] = array(
@@ -717,6 +777,8 @@ function tripal_bulk_loader_edit_template_record_form_submit($form, &$form_state
       $record['record_id'] = $form_state['values']['record_name'];
       $record['mode'] = $form_state['values']['mode'];
       $record['table'] = $form_state['values']['chado_table'];
+      $record['select_if_duplicate'] = $form_state['values']['select_if_duplicate'];
+      $record['disable'] = $form_state['values']['disable'];
 
       if ($form_state['storage']['original_priority'] != $form_state['values']['field_group']) {
         $record['fields'] = array_merge($record['fields'], $template[ $form_state['values']['field_group'] ]['fields']);
@@ -816,7 +878,7 @@ function tripal_bulk_loader_add_template_field_form(&$form_state = NULL) {
   $field_type = ($form_state['values']['field_type'])? $form_state['values']['field_type'] : 'table field';
 
   // Tables and default table
-  $tables = tripal_core_get_chado_tables();
+  $tables = tripal_core_get_chado_tables(TRUE);
   if ($form_state['values']) {
     if (!preg_match('/^' . current($tables) . '$/', $form_state['values']['chado_table'])) {
       $table = $form_state['values']['chado_table'];
@@ -1451,7 +1513,7 @@ function tripal_bulk_loader_edit_template_field_form(&$form_state = NULL) {
   $field_type = ($form_state['values']['field_type'])? $form_state['values']['field_type'] : $template_field['type'];
 
   // Tables and default table
-  $tables = tripal_core_get_chado_tables();
+  $tables = tripal_core_get_chado_tables(TRUE);
   if ($form_state['values']) {
     $table = $form_state['values']['chado_table'];
   }

+ 16 - 4
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -162,7 +162,9 @@ function tripal_bulk_loader_load_data($nid, $job_id) {
     foreach ($record_array['fields'] as $field_index => $field_array) {
 
       $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';
+      $default_data[$priority]['select_if_duplicate'] = ($record_array['select_if_duplicate']) ? $record_array['select_if_duplicate'] : 1;
+      $default_data[$priority]['disabled'] = ($record_array['disable']) ? $record_array['disable'] : 0;
       $default_data[$priority]['record_id'] = $record_array['record_id'];
       $record2priority[$record_array['record_id']] = $priority;
       $default_data[$priority]['required'][$field_array['field']] = $field_array['required'];
@@ -354,7 +356,14 @@ function tripal_bulk_loader_load_data($nid, $job_id) {
           'node' => $node,
           'nid' => $node->nid,
         );
-        $status = process_data_array_for_line($priority, $data, $default_data, $options);
+        // execute all records that are not disabled
+        if ($data[$priority]['disabled'] == 0) {
+          $status = process_data_array_for_line($priority, $data, $default_data, $options);
+        } 
+        else {
+          // set status to true for skipped records
+          $status = TRUE;
+        }
         tripal_bulk_loader_progress_file_track_job($job_id, $status);
         if (!$status ) {
           // Encountered an error
@@ -509,8 +518,11 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
     $header = $values['uniquename'] . ' ' . $table_data['record_id'];
   }
 
-  // if insert unique then check to ensure unique
-  if (preg_match('/insert_unique/', $table_data['mode'])) {
+  // if select if duplicate then check to ensure unique constraint is met.  If so,
+  // then return. We don't want to do any inserts.  We check for insert_unique for backwards compatibilty but that
+  // mode no longer exists
+  if (!preg_match('/insert_unique/', $table_data['mode']) or
+      (isset($table_data['select_if_duplicate']) and $table_data['select_if_duplicate'] == 1)) {
     $unique = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, array('has_record' => TRUE));
     //print 'Unique?'.print_r(array('table' => $table, 'columns' => array_keys($table_desc['fields']), 'values' => $values),TRUE).' returns '.$unique."\n";
     if ($unique > 0) {

+ 1 - 1
tripal_views/api/tripal_views.api.inc

@@ -390,7 +390,7 @@ function tripal_views_integration_remove_entry_by_setup_id($setup_id) {
  */
 function tripal_views_integrate_all_chado_tables() {
 
-  $tables = tripal_core_get_chado_tables();
+  $tables = tripal_core_get_chado_tables(TRUE);
   foreach ($tables as $tablename) {
     if (!tripal_views_is_integrated($tablename, 10)) {
       $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, 10);

+ 2 - 2
tripal_views/includes/tripal_views_integration.inc

@@ -282,7 +282,7 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
   );
 
   // build the form element for the Chado tables
-  $chado_tables = tripal_core_get_chado_tables();
+  $chado_tables = tripal_core_get_chado_tables(TRUE);
   $chado_tables = array_merge(array('Select'), $chado_tables);
   $form['base_table_type']['table_name'] = array(
     '#title' => t('Chado/Custom Table'),
@@ -436,7 +436,7 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
     $data['field_types'] = array();
 
     // get the list of chado tables to join on
-    $chado_join_tables = tripal_core_get_chado_tables();
+    $chado_join_tables = tripal_core_get_chado_tables(TRUE);
     $chado_join_tables = array_merge(array('Select a Join Table'), $chado_join_tables);
 
     // get list of all handlers