Browse Source

Fixed bug when adding a custom table that already exists. It wouldn't let it happen despite that the code was smart enough to handle it correctly.

spficklin 12 years ago
parent
commit
b8257936dc

+ 1 - 1
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -498,7 +498,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
   // get the table description
   $table_desc = tripal_core_get_chado_table_schema($table);
   if (!$table_desc) {
-    watchdog('T_bulk_loader', "Failure: Tripal does not know about the table named %table. If this is a custom table, 
+    watchdog('T_bulk_loader', "Failure: Tripal does not know about the table named '%table'. If this is a custom table, 
       please define it first", array('%table' => $table), WATCHDOG_ERROR);
     $data[$priority]['error'] = TRUE;
     return;  

+ 0 - 11
tripal_core/includes/custom_tables.php

@@ -268,17 +268,6 @@ function tripal_custom_tables_form_validate($form, &$form_state) {
         form_set_error($form_state['values']['schema'],
           t("The schema array must have key named 'table'"));
       }
-      // check to see if the table name matches an existing table
-      // if this is an add
-      if ($action == 'Add') {
-        $previous_db = tripal_db_set_active('chado');
-        $exists = db_table_exists($schema_array['table']);
-        tripal_db_set_active($previous_db);        
-        if ($exists) {
-          form_set_error($form_state['values']['schema'],
-            t("The table name already exists, please choose a different name."));  
-        }
-      } 
       if ($action == 'Edit') {
         // see if the table name has changed. If so, then check to make sure
         // it doesn't already exists. We don't want to drop a table we didn't mean to

+ 28 - 40
tripal_pub/includes/pub_form.inc

@@ -1,21 +1,5 @@
 <?php 
 
-/**
- * Because we are using AJAX with a node form we need to provide a callback
- * for the chado_pub node form.  This callback is different from the 
- * default 'chado_pub_form' callback
- */
-function tripal_pub_forms($form_id, $args) {
-  $forms = array();
-  if($form_id == 'chado_pub_node_form') {
-    $forms[$form_id] = array(
-      'callback' => 'chado_pub_node_form',
-      'callback arguments' => array($args)
-    );
-  }
-  return $forms;
-}
-
 /**
  * This is the chado_pub node form callback. The arguments
  * are out of order from a typical form because it's a defined callback 
@@ -23,6 +7,7 @@ function tripal_pub_forms($form_id, $args) {
 function chado_pub_node_form($form_state, $node) {   
   tripal_core_ahah_init_form();
   $form = array();
+  dpm($form_state);
 
   $type = node_get_types('type', $node);
   $pub = $node->pub;
@@ -135,27 +120,27 @@ function chado_pub_node_form($form_state, $node) {
     // if any of the properties match the fields in the pub table then we want to include those 
     // automatically
     if($prop->name == 'Volume' and $d_volume) {
-      $d_properties[$num_properties][0]['name'] =  $prop->name;     
-      $d_properties[$num_properties][0]['id'] = $prop->cvterm_id;
-      $d_properties[$num_properties][0]['value'] = $d_volume;
+      $d_properties[$prop->cvterm_id][0]['name']  =  $prop->name;     
+      $d_properties[$prop->cvterm_id][0]['id']    = $prop->cvterm_id;
+      $d_properties[$prop->cvterm_id][0]['value'] = $d_volume;
       $num_properties++;
     }
     if($prop->name == 'Volume Title' and $d_volumetitle) {
-      $d_properties[$num_properties][0]['name'] =  $prop->name;
-      $d_properties[$num_properties][0]['id'] = $prop->cvterm_id;
-      $d_properties[$num_properties][0]['value'] = $d_volumetitle;
+      $d_properties[$prop->cvterm_id][0]['name']  =  $prop->name;
+      $d_properties[$prop->cvterm_id][0]['id']    = $prop->cvterm_id;
+      $d_properties[$prop->cvterm_id][0]['value'] = $d_volumetitle;
       $num_properties++;
     }
     if($prop->name == 'Issue' and $d_issue) {
-      $d_properties[$num_properties][0]['name'] =  $prop->name;
-      $d_properties[$num_properties][0]['id'] = $prop->cvterm_id;
-      $d_properties[$num_properties][0]['value'] = $d_issue;
+      $d_properties[$prop->cvterm_id][0]['name']  =  $prop->name;
+      $d_properties[$prop->cvterm_id][0]['id']    = $prop->cvterm_id;
+      $d_properties[$prop->cvterm_id][0]['value'] = $d_issue;
       $num_properties++;
     }
     if($prop->name == 'Pages' and $d_pages) {
-      $d_properties[$num_properties][0]['name'] =  $prop->name;
-      $d_properties[$num_properties][0]['id'] = $prop->cvterm_id;
-      $d_properties[$num_properties][0]['value'] = $d_pages;
+      $d_properties[$prop->cvterm_id][0]['name']  =  $prop->name;
+      $d_properties[$prop->cvterm_id][0]['id']    = $prop->cvterm_id;
+      $d_properties[$prop->cvterm_id][0]['value'] = $d_pages;
       $num_properties++;
     }
   }
@@ -179,18 +164,20 @@ function chado_pub_node_form($form_state, $node) {
       }
       // add new properties that weren't handled yet
       if(array_key_exists($prop->cvterm_id, $properties)) {
-        $d_properties[$num_properties][$prop->rank]['name']  =  $prop->name;
-        $d_properties[$num_properties][$prop->rank]['id']    = $prop->cvterm_id;
-        $d_properties[$num_properties][$prop->rank]['value'] = $prop->value;
+        $d_properties[$prop->cvterm_id][$prop->rank]['name']  = $prop->name;
+        $d_properties[$prop->cvterm_id][$prop->rank]['id']    = $prop->cvterm_id;
+        $d_properties[$prop->cvterm_id][$prop->rank]['value'] = $prop->value;
         $num_properties++; 
       }
     }
   }
-    
+
+  
   // build the fields for the properties  
-  for ($i = 0; $i < $num_properties; $i++) {
-    foreach ($d_properties[$i] as $rank => $d_property) {
-      $form['properties'][$i][$rank]["prop_id-$i-$rank"] = array(
+  $i = 0;
+  foreach ($d_properties as $type_id => $ranks) {
+    foreach ($ranks as $rank => $d_property) {
+      $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
         '#type'          => 'select',
         '#options'       => $properties,
         '#default_value' => $d_property['id']
@@ -199,7 +186,7 @@ function chado_pub_node_form($form_state, $node) {
       if  (preg_match('/Abstract/', $d_property['name'])) {
         $rows = 10;
       }
-      $form['properties'][$i][$rank]["prop_value-$i-$rank"] = array(
+      $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
         '#type'          => 'textarea',
         '#options'       => $properties,
         '#default_value' => $d_property['value'],
@@ -207,12 +194,12 @@ function chado_pub_node_form($form_state, $node) {
         '#rows'          => $rows
       );
       
-      $form['properties'][$i][$rank]["remove-$i-$rank"] = array(
+      $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
         '#type'         => 'image_button',
         '#value'        => t('Remove'),
         '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
         '#ahah' => array(
-          'path'    => "tripal_pub/properties/minus/$i",
+          'path'    => "tripal_pub/properties/minus/$type_id/$rank",
           'wrapper' => 'chado-pub-details',
           'event'   => 'click',
           'method'  => 'replace',
@@ -220,12 +207,12 @@ function chado_pub_node_form($form_state, $node) {
         '#attributes' => array('onClick' => 'return false;'),
       );
       if($i == $num_properties - 1) {
-        $form['properties'][$i][$rank]["add-$i-$rank"] = array(
+        $form['properties'][$type_id][$rank]["add-$type_id-$rank"] = array(
           '#type'         => 'image_button',      
           '#value'        => t('Add'),
           '#src'          => drupal_get_path('theme', 'tripal') . '/images/add.png',
           '#ahah' => array(
-            'path'    => "tripal_pub/properties/add/$i",
+            'path'    => "tripal_pub/properties/add/$type_id",
             'wrapper' => 'chado-pub-details',
             'event'   => 'click',
             'method'  => 'replace',          
@@ -233,6 +220,7 @@ function chado_pub_node_form($form_state, $node) {
           '#attributes' => array('onClick' => 'return false;'),
         );
       }
+      $i++;
     }
   }
   /*

+ 18 - 2
tripal_pub/tripal_pub.module

@@ -125,9 +125,9 @@ function tripal_pub_menu() {
     'type ' => MENU_CALLBACK,
   );
   
-  $items['tripal_pub/properties/minus/%'] = array(    
+  $items['tripal_pub/properties/minus/%/%'] = array(    
     'page callback' => 'tripal_pub_property_delete',
-    'page arguments' => array(3),
+    'page arguments' => array(3,4),
     'access arguments' => array('edit chado_pub content'),
     'type ' => MENU_CALLBACK,
   );
@@ -404,6 +404,22 @@ function chado_pub_delete(&$node) {
   chado_query("DELETE FROM {pub} WHERE pub_id = %d", $pub_id);
 }
 
+/**
+ * Because we are using AJAX with a node form we need to provide a callback
+ * for the chado_pub node form.  This callback is different from the 
+ * default 'chado_pub_form' callback
+ */
+function tripal_pub_forms($form_id, $args) {
+  $forms = array();
+  if($form_id == 'chado_pub_node_form') {
+    $forms[$form_id] = array(
+      'callback' => 'chado_pub_node_form',
+      'callback arguments' => array($args)
+    );
+  }
+  return $forms;
+}
+
 /*
  * 
  */