瀏覽代碼

Bug fixes to dbxref/prop/rel api

Lacey Sanderson 11 年之前
父節點
當前提交
1013abb11c

+ 33 - 31
tripal_core/api/tripal_core.database_references.api.inc

@@ -560,39 +560,41 @@ function tripal_core_additional_dbxrefs_form_retreive($node) {
  */
 function tripal_core_additional_dbxrefs_form_update_dbxrefs($node, $linking_table, $foreignkey_name, $foreignkey_value) {
 
-  // First remove existing dbxref links
-  tripal_core_chado_delete($linking_table, array($foreignkey_name => $foreignkey_value));
-
-  // Add back in dbxref links and insert dbxrefs as needed
-  $dbxrefs = tripal_core_additional_dbxrefs_form_retreive($node);
-  foreach ($dbxrefs as $db_id => $versions) {
-    foreach ($versions as $version => $elements) {
-      foreach ($elements as $dbxref_id => $accession) {
-        // If there is no dbxref then we have to create that first
-        if ($dbxref_id == 'NONE') {
-          $version = ($version == 'NONE') ? '' : $version;
-          $success = tripal_db_add_dbxref(
-            $db_id,
-            $accession,
-            $version,
-            NULL
-          );
-          if ($success) {
-            $dbxref_id = $success->dbxref_id;
-          }
-          else {
-            $dbxref_id = FALSE;
+  if (isset($node->dbxref_table) AND ($foreignkey_value > 0)) {
+    // First remove existing dbxref links
+    tripal_core_chado_delete($linking_table, array($foreignkey_name => $foreignkey_value));
+
+    // Add back in dbxref links and insert dbxrefs as needed
+    $dbxrefs = tripal_core_additional_dbxrefs_form_retreive($node);
+    foreach ($dbxrefs as $db_id => $versions) {
+      foreach ($versions as $version => $elements) {
+        foreach ($elements as $dbxref_id => $accession) {
+          // If there is no dbxref then we have to create that first
+          if ($dbxref_id == 'NONE') {
+            $version = ($version == 'NONE') ? '' : $version;
+            $success = tripal_db_add_dbxref(
+              $db_id,
+              $accession,
+              $version,
+              NULL
+            );
+            if ($success) {
+              $dbxref_id = $success->dbxref_id;
+            }
+            else {
+              $dbxref_id = FALSE;
+            }
           }
-        }
 
-        // add _dbxref linker
-        if ($dbxref_id) {
-          $success_link = tripal_db_add_dbxref_link(
-            $linking_table,
-            $dbxref_id,
-            $foreignkey_name,
-            $foreignkey_value
-          );
+          // add _dbxref linker
+          if ($dbxref_id) {
+            $success_link = tripal_db_add_dbxref_link(
+              $linking_table,
+              $dbxref_id,
+              $foreignkey_name,
+              $foreignkey_value
+            );
+          }
         }
       }
     }

+ 32 - 33
tripal_core/api/tripal_core.properties.api.inc

@@ -701,9 +701,6 @@ function chado_node_properties_form(&$form, &$form_state, $details) {
       array('property_table')  // Validate all fields within $form_state['values']['property_table']
     )
   );
-
-  ddl($form, 'form');
-  ddl($form_state, 'form state');
 }
 
 /**
@@ -794,8 +791,6 @@ function chado_node_properties_form_remove_button_submit(&$form, &$form_state) {
     chado_node_properties_form_create_property_formstate_array($form, $form_state);
   }
 
-  ddl($form_state, 'form state in remove');
-
   // remove the specified property from the form property table
   if(preg_match('/property_remove-([^-]+-[^-]+)/',$form_state['triggering_element']['#name'],$match)) {
     $key = $match[1];
@@ -944,38 +939,42 @@ function chado_node_properties_form_retreive($node) {
  */
 function chado_node_properties_form_update_properties($node, $details, $retrieved_properties = FALSE) {
 
-  // First remove existing property links
-  tripal_core_chado_delete($details['property_table'], array($details['foreignkey_name'] => $details['foreignkey_value']));
+  $details['foreignkey_value'] = (isset($details['foreignkey_value'])) ? $details['foreignkey_value'] : 0;
 
-  // Add back in property links and insert properties as needed
-  if ($retrieved_properties) {
-    $properties = $retrieved_properties;
-  }
-  else {
-    $properties = chado_node_properties_form_retreive($node);
-  }
-  foreach ($properties as $type_id => $ranks) {
-    foreach ($ranks as $rank => $value) {
-
-      $success = tripal_core_chado_insert(
-        $details['property_table'],
-        array(
-          $details['foreignkey_name'] => $details['foreignkey_value'],
-          'type_id' => $type_id,
-          'value' => $value,
-          'rank' => $rank
-        )
-      );
+  if (isset($node->property_table) AND ($details['foreignkey_value'] > 0)) {
+    // First remove existing property links
+    tripal_core_chado_delete($details['property_table'], array($details['foreignkey_name'] => $details['foreignkey_value']));
 
-      if (!$success) {
-        watchdog(
-          'tripal_' . $details['base_table'],
-          $details['base_table'] . ' Insert: Unable to insert property type_id %cvterm with value %value.',
-          array('%cvterm' => $type_id, '%value' => $value),
-          WATCHDOG_ERROR
+    // Add back in property links and insert properties as needed
+    if ($retrieved_properties) {
+      $properties = $retrieved_properties;
+    }
+    else {
+      $properties = chado_node_properties_form_retreive($node);
+    }
+    foreach ($properties as $type_id => $ranks) {
+      foreach ($ranks as $rank => $value) {
+
+        $success = tripal_core_chado_insert(
+          $details['property_table'],
+          array(
+            $details['foreignkey_name'] => $details['foreignkey_value'],
+            'type_id' => $type_id,
+            'value' => $value,
+            'rank' => $rank
+          )
         );
-      }
 
+        if (!$success) {
+          watchdog(
+            'tripal_' . $details['base_table'],
+            $details['base_table'] . ' Insert: Unable to insert property type_id %cvterm with value %value.',
+            array('%cvterm' => $type_id, '%value' => $value),
+            WATCHDOG_ERROR
+          );
+        }
+
+      }
     }
   }
 }

+ 21 - 19
tripal_core/api/tripal_core.relationships.api.inc

@@ -698,26 +698,28 @@ function tripal_core_relationships_form_retreive($node) {
  */
 function tripal_core_relationships_form_update_relationships($node, $relationship_table, $current_id) {
 
-  // First remove existing relationships links
-  tripal_core_chado_delete($relationship_table, array('subject_id' => $current_id));
-  tripal_core_chado_delete($relationship_table, array('object_id' => $current_id));
-
-  // Add back in dbxref links and insert dbxrefs as needed
-  $relationships = tripal_core_relationships_form_retreive($node);
-  foreach ($relationships as $type_id => $ranks) {
-    foreach ($ranks as $rank => $element) {
-
-      // add relationship
-      $success_link = tripal_core_chado_insert(
-        $relationship_table,
-        array(
-          'subject_id' => $element['subject_id'],
-          'type_id' => $type_id,
-          'object_id' => $element['object_id'],
-          'rank' => $rank
-        )
-      );
+  if (isset($node->rel_table) AND ($current_id > 0)) {
+    // First remove existing relationships links
+    tripal_core_chado_delete($relationship_table, array('subject_id' => $current_id));
+    tripal_core_chado_delete($relationship_table, array('object_id' => $current_id));
+
+    // Add back in dbxref links and insert dbxrefs as needed
+    $relationships = tripal_core_relationships_form_retreive($node);
+    foreach ($relationships as $type_id => $ranks) {
+      foreach ($ranks as $rank => $element) {
+
+        // add relationship
+        $success_link = tripal_core_chado_insert(
+          $relationship_table,
+          array(
+            'subject_id' => $element['subject_id'],
+            'type_id' => $type_id,
+            'object_id' => $element['object_id'],
+            'rank' => $rank
+          )
+        );
 
+      }
     }
   }
 }

+ 2 - 1
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -228,7 +228,8 @@ function chado_pub_form($node, $form_state) {
     'property_table' => 'pubprop',
     'base_foreign_key' => 'pub_id',
     'base_key_value' => $pub_id,
-    'cv_name' => 'tripal_pub'
+    'cv_name' => 'tripal_pub',
+    'exclude'=> array('Citation')
   );
   chado_node_properties_form($form, $form_state, $details);
   // get publication properties list

+ 17 - 31
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -166,9 +166,11 @@ function chado_stock_form($node, $form_state) {
     $type_id = $node->stock->type_id->cvterm_id;
     $organism_id = $node->stock->organism_id->organism_id;
     $sdescription = $node->stock->description;
-    $dbxref_accession = $node->stock->dbxref_id->accession;
-    $dbxref_description = $node->stock->dbxref_id->description;
-    $dbxref_database = $node->stock->dbxref_id->db_id->db_id;
+    if (isset($node->stock->dbxref_id->db_id)) {
+      $dbxref_accession = $node->stock->dbxref_id->accession;
+      $dbxref_description = $node->stock->dbxref_id->description;
+      $dbxref_database = $node->stock->dbxref_id->db_id->db_id;
+    }
   }
 
   // 2) if we are re constructing the form from a failed validation or ajax callback
@@ -199,6 +201,11 @@ function chado_stock_form($node, $form_state) {
     $dbxref_database = $form_state['input']['database'];
   }
 
+  $form['manually_edit_chado'] = array(
+    '#type' => 'hidden',
+    '#value' => TRUE,
+  );
+
   $form['names'] = array(
     '#type' => 'fieldset',
     '#title' => t('Stock Name')
@@ -457,26 +464,10 @@ function chado_stock_validate(&$node, $form, &$form_state) {
  */
 function chado_stock_insert($node) {
 
-  // If the chado stock exists (e.g. this is only a syncing operation)
-  // then don't create but simply link to node
-  if (isset($node->chado_stock_exists)) {
-    if ($node->chado_stock_exists) {
-      if (!empty($node->stock_id)) {
-        db_insert('chado_stock')->fields(array(
-          'nid' => $node->nid,
-          'vid' => $node->vid,
-          'stock_id' => $node->stock_id
-        ));
-      }
-
-      return $node;
-    }
-  }
-
   // if there is an stock_id in the $node object then this must be a sync so
   // we can skip adding the stock to chado as it is already there, although
   // we do need to proceed with the rest of the insert
-  if (!property_exists($node, 'stock_id')) {
+  if (property_exists($node, 'manually_edit_chado')) {
 
     // before we can add the stock, we must add the dbxref if one has been
     // provided by the user.
@@ -536,14 +527,15 @@ function chado_stock_insert($node) {
 
     if (is_array($stock)) {
       $stock_added = TRUE;
+      $stock_id = $stock['stock_id'];
     }
     else {
       $stock_added = FALSE;
     }
 
-    // Now add properties
     if ($stock_added) {
 
+      // Now add properties
       $details = array(
         'property_table' => 'stockprop',
         'base_table' => 'stock',
@@ -552,21 +544,15 @@ function chado_stock_insert($node) {
       );
       chado_node_properties_form_update_properties($node, $details);
 
-    }
-
-    // Now add the additional references
-    if ($stock_added) {
-      tripal_core_relationships_form_update_relationships(
+      // Now add the additional references
+      tripal_core_additional_dbxrefs_form_update_dbxrefs(
         $node,
         'stock_dbxref',
         'stock_id',
         $stock_id
       );
-    }
-
-    // Now add in relationships
-    if ($stock_added) {
-      tripal_core_relationships_form_update_dbxrefs(
+      // Now add in relationships
+      tripal_core_relationships_form_update_relationships(
         $node,
         'stock_relationship',
         $stock_id