Browse Source

Merge branch '7.x-2.x' of git.drupal.org:project/tripal into 7.x-2.x

Ficklin 10 years ago
parent
commit
2c0d0c771d

+ 5 - 2
tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -290,8 +290,11 @@ function chado_analysis_validate($node, $form, &$form_state) {
  */
 function tripal_analysis_validate($node, $form, &$form_state) {
 
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 6 - 2
tripal_contact/includes/tripal_contact.chado_node.inc

@@ -245,8 +245,12 @@ function chado_contact_form(&$node, $form_state) {
  * @ingroup tripal_contact
  */
 function chado_contact_validate($node, $form, &$form_state) {
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 20 - 3
tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -647,7 +647,8 @@ function chado_add_node_form_properties_add_button_submit(&$form, &$form_state)
     'rank' => '0',
   );
 
-  // get max rank
+  // Determine the rank for the new property based on the the data already
+  // stored in the properties table.
   $rank = chado_get_table_max_rank(
     $details['property_table'],
     array(
@@ -656,9 +657,25 @@ function chado_add_node_form_properties_add_button_submit(&$form, &$form_state)
     )
   );
   $property['rank'] = strval($rank + 1);
-
   $key = $property['type_id'] . '-' . $property['rank'];
-  $form_state['chado_properties'][$key] = (object) $property;
+
+  // Now check to make sure a property doesn't already exist with that rank
+  // (which happens when 2+ properties of the same type are added within the
+  // same save).
+  if (isset($form_state['chado_properties'][$key])) {
+    // Then keep iterating the rank until you find there is no property in
+    // the properties list with the same type/rank combination.
+    do {
+      $property['rank']++;
+      $key = $property['type_id'] . '-' . $property['rank'];
+    } while (isset($form_state['chado_properties'][$key]));
+
+    // And then set the property to that free space.
+    $form_state['chado_properties'][$key] = (object) $property;
+  }
+  else {
+    $form_state['chado_properties'][$key] = (object) $property;
+  }
 
   // we don't want the new element to pick up the values from the previous element so wipe them out
   unset($form_state['input']['property_table']['new']['type']);

+ 20 - 22
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -126,11 +126,11 @@
  */
 function chado_add_node_form_relationships(&$form, &$form_state, $details) {
 
-  // make sure the property table exists before proceeding.
+  // make sure the relationship table exists before proceeding.
   if (!chado_table_exists($details['relationship_table'])) {
     drupal_set_message("Cannot add relationship elements to the form. The relationship table, '" .
       $details['relationship_table'] . "', does not exists", "error");
-    tripal_report_error('tcprops_form', TRIPAL_ERROR, "Cannot add relationship elements to the form.
+    tripal_report_error('tcrel_form', TRIPAL_ERROR, "Cannot add relationship elements to the form.
       The relationship table, '%name', cannot be found.", array('%name' => $details['relationship_table']));
     return;
   }
@@ -142,7 +142,7 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
     if (count($result) == 0) {
       drupal_set_message("Cannot add relationship elements to the form. The CV name, '" .
           $details['cv_name'] . "', does not exists", "error");
-          tripal_report_error('tcprops_form', TRIPAL_ERROR, "Cannot add relationship elements to the form.
+          tripal_report_error('tcrel_form', TRIPAL_ERROR, "Cannot add relationship elements to the form.
         The CV named, '%name', cannot be found.", array('%name' => $details['cv_name']));
           return;
     }
@@ -155,7 +155,7 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
     if (count($result) == 0) {
       drupal_set_message("Cannot add relationship elements to the form. The CV ID, '" .
           $details['cv_id'] . "', does not exist", "error");
-          tripal_report_error('tcprops_form', TRIPAL_ERROR, "Cannot add relationship elements
+          tripal_report_error('tcrel_form', TRIPAL_ERROR, "Cannot add relationship elements
         to the form. The CV ID, '%id', cannot be found.", array('%id' => $details['cv_id']));
           return;
     }
@@ -181,7 +181,7 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
       $message = "There is not a default vocabulary set for $table Releationship Types. Please set one using the  $default_form_link.";
 
       tripal_set_message($message, TRIPAL_WARNING);
-      tripal_report_error('tcprops_form', TRIPAL_ERROR, "Please provide either a
+      tripal_report_error('tcrel_form', TRIPAL_ERROR, "Please provide either a
         'cv_name' or 'cv_id' as an option for adding relationship to the form", array());
 
       return;
@@ -205,14 +205,14 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
   $table_schema = chado_get_schema($details['relationship_table']);
   $details['table_has_rank'] = (isset($table_schema['fields']['rank'])) ? TRUE : FALSE;
 
-  // Get Property Types for the Select List
+  // Get Relationship Types for the Select List
   if (isset($details['select_options'])) {
     $type_options = $details['select_options'];
   }
   else {
     if (isset($details['cv_name'])) {
       $type_options = array();
-      $type_options[] = 'Select a Property';
+      $type_options[] = 'Select a Type';
       $sql = "
         SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition, CV.cv_id as cv_id
         FROM  {cvterm} CVT
@@ -222,15 +222,15 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
           NOT CVT.is_obsolete = 1
         ORDER BY CVT.name ASC
       ";
-      $prop_types = chado_query($sql, array(':cv_name' => $details['cv_name']));
-      while ($prop = $prop_types->fetchObject()) {
-        $type_options[$prop->cvterm_id] = $prop->name;
-        $details['cv_id'] = $prop->cv_id;
+      $cvterms = chado_query($sql, array(':cv_name' => $details['cv_name']));
+      while ($term = $cvterms->fetchObject()) {
+        $type_options[$term->cvterm_id] = $term->name;
+        $details['cv_id'] = $term->cv_id;
       }
     }
     elseif (isset($details['cv_id'])) {
       $type_options = array();
-      $type_options[] = 'Select a Property';
+      $type_options[] = 'Select a Type';
       $sql = "
         SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition, CV.name AS cv_name
         FROM  {cvterm} CVT
@@ -240,18 +240,18 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
           NOT CVT.is_obsolete = 1
         ORDER BY CVT.name ASC
       ";
-      $prop_types = chado_query($sql, array(':cv_id' => $details['cv_id']));
-      while ($prop = $prop_types->fetchObject()) {
-        $type_options[$prop->cvterm_id] = $prop->name;
-        $details['cv_name'] = $prop->cv_name;
+      $cvterms = chado_query($sql, array(':cv_id' => $details['cv_id']));
+      while ($term = $cvterms->fetchObject()) {
+        $type_options[$term->cvterm_id] = $term->name;
+        $details['cv_name'] = $term->cv_name;
       }
     }
   }
 
-  // Tell tripal administrators how to add terms to the property types drop down.
+  // Tell tripal administrators how to add terms to the relationship types drop down.
   if (empty($type_options)) {
     $tripal_message = tripal_set_message(
-      t('There are currently no property types! To add additional properties to the drop
+      t('There are currently no relationship types! To add additional relationship types to the drop
         down list, you need to <a href="@cvtermlink">add a controlled vocabulary term</a>
         to the %cv_name controlled vocabulary.',
         array(
@@ -265,7 +265,7 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
   }
   else {
     $tripal_message = tripal_set_message(
-      t('To add additional properties to the drop down list, you need to <a href="@cvtermlink">add
+      t('To add additional relationship types to the drop down list, you need to <a href="@cvtermlink">add
         a controlled vocabulary term</a> to the %cv_name controlled vocabulary.',
         array(
           '%cv_name' => $details['cv_name'],
@@ -734,9 +734,7 @@ function chado_add_node_form_relationships_remove_button_submit(&$form, &$form_s
 
   // if the chado_relationships array is not set then this is the first time modifying the
   // relationship table. this means we need to include all the relationships from the db
-  if (!isset($form_state['chado_relationships'])) {
-    chado_add_node_form_relationships_create_relationship_formstate_array($form, $form_state);
-  }
+  chado_add_node_form_relationships_create_relationship_formstate_array($form, $form_state);
 
   // remove the specified relationship from the form relationship table
   if(preg_match('/rel_remove-([^-]+-[^-]+)/',$form_state['triggering_element']['#name'],$match)) {

+ 5 - 2
tripal_example/includes/tripal_example.chado_node.inc

@@ -290,8 +290,11 @@ function chado_example_form($node, &$form_state) {
  */
 function chado_example_validate($node, $form, &$form_state) {
 
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 5 - 2
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -264,8 +264,11 @@ function chado_feature_form($node, &$form_state) {
  */
 function chado_feature_validate($node, $form, &$form_state) {
 
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 4 - 4
tripal_feature/includes/tripal_feature.gff_loader.inc

@@ -1161,8 +1161,8 @@ function tripal_feature_load_gff3_dbxref($feature, $dbxrefs) {
 
     // get the database name from the reference.  If it doesn't exist then create one.
     $ref = explode(":", $dbxref);
-    $dbname = $ref[0];
-    $accession = $ref[1];
+    $dbname = trim($ref[0]);
+    $accession = trim($ref[1]);
 
     // first look for the database name if it doesn't exist then create one.
     // first check for the fully qualified URI (e.g. DB:<dbname>. If that
@@ -1253,8 +1253,8 @@ function tripal_feature_load_gff3_ontology($feature, $dbxrefs) {
 
     // get the database name from the reference.  If it doesn't exist then create one.
     $ref = explode(":", $dbxref);
-    $dbname = $ref[0];
-    $accession = $ref[1];
+    $dbname = trim($ref[0]);
+    $accession = trim($ref[1]);
 
     // first look for the database name
     $db = chado_select_record('db', array('db_id'), array('name' => "DB:$dbname"));

+ 5 - 2
tripal_featuremap/includes/tripal_featuremap.chado_node.inc

@@ -155,8 +155,11 @@ function chado_featuremap_form($node, &$form_state) {
  */
 function chado_featuremap_validate($node, $form, &$form_state) {
 
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 6 - 2
tripal_library/includes/tripal_library.chado_node.inc

@@ -217,8 +217,12 @@ function chado_library_form($node, &$form_state) {
  * @ingroup tripal_library
  */
 function chado_library_validate($node, $form, &$form_state) {
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 6 - 2
tripal_organism/includes/tripal_organism.chado_node.inc

@@ -215,8 +215,12 @@ function chado_organism_form($node, $form_state) {
  * @ingroup tripal_organism
  */
 function chado_organism_validate($node, $form, &$form_state) {
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 6 - 4
tripal_project/includes/tripal_project.chado_node.inc

@@ -179,8 +179,7 @@ function chado_project_form(&$node, $form_state) {
     'cv_id' => $cv_id,                              // the cv.cv_id of the cv governing example_relationship.type_id
     'base_name_field' => 'name',                    // the base table field you want to be used as the name
     'subject_field_name' => 'subject_project_id',
-    'object_field_name' => 'object_project_id',
-    'select_options' => $select_options
+    'object_field_name' => 'object_project_id'
   );
   // Adds the form elements to your current form
   chado_add_node_form_relationships($form, $form_state, $details);
@@ -197,8 +196,11 @@ function chado_project_form(&$node, $form_state) {
  */
 function chado_project_validate($node, $form, &$form_state) {
 
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

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

@@ -333,8 +333,11 @@ function chado_pub_form($node, $form_state) {
  */
 function chado_pub_validate($node, $form, &$form_state) {
 
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 6 - 1
tripal_pub/includes/tripal_pub.pub_search.inc

@@ -14,6 +14,11 @@
  */
 function tripal_pub_search_page() {
 
+  // This line may not be required, but on some sites the $_SESSION
+  // variable wasn't being set for anonymous users. This line solves that
+  // problem 
+  drupal_session_start();
+
   $limit = 25;
 
   // generate the search form
@@ -680,4 +685,4 @@ function tripal_search_publications($search_array, $offset, $limit, &$total_reco
   $results = chado_query($sql, $args);
 
   return $results;
-}
+}

+ 5 - 2
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -319,8 +319,11 @@ function chado_stock_form($node, $form_state) {
  */
 function chado_stock_validate(&$node, $form, &$form_state) {
 
-  // if this is a delete then don't validate
-  if($node->op == 'Delete') {
+  // We only want to validate when the node is saved.
+  // Since this validate can be called on AJAX and Deletion of the node
+  // we need to make this check to ensure queries are not executed
+  // without the proper values.
+  if($node->op != 'Save') {
     return;
   }
 

+ 1 - 1
tripal_stock/theme/templates/tripal_organism_stocks.tpl.php

@@ -47,7 +47,7 @@ if (count($stocks) > 0) { ?>
     if (!$name) {
       $name = $stock->uniquename;
     }
-    if ($node->nid) {
+    if (property_exists($stock, 'nid')) {
       $name = l($name, "node/$stock->nid", array('attributes' => array('target' => '_blank')));
     }