Browse Source

Fixed bug with syncing

Stephen Ficklin 11 years ago
parent
commit
abaec55897

+ 10 - 9
tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -264,15 +264,6 @@ function chado_analysis_validate($node, $form, &$form_state) {
  * @ingroup tripal_analysis
  */
 function tripal_analysis_validate($node, $form, &$form_state) {
-  // remove surrounding white-space on submitted values
-  $node->analysisname = trim($node->analysisname);
-  $node->description = trim($node->description);
-  $node->program = trim($node->program);
-  $node->programversion = trim($node->programversion);
-  $node->algorithm = trim($node->algorithm);
-  $node->sourcename = trim($node->sourcename);
-  $node->sourceversion = trim($node->sourceversion);
-  $node->sourceuri = trim($node->sourceuri);
 
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
@@ -285,6 +276,16 @@ function tripal_analysis_validate($node, $form, &$form_state) {
     return;
   }
 
+  // remove surrounding white-space on submitted values
+  $node->analysisname = trim($node->analysisname);
+  $node->description = trim($node->description);
+  $node->program = trim($node->program);
+  $node->programversion = trim($node->programversion);
+  $node->algorithm = trim($node->algorithm);
+  $node->sourcename = trim($node->sourcename);
+  $node->sourceversion = trim($node->sourceversion);
+  $node->sourceuri = trim($node->sourceuri);
+  
   // Validating for an update
   if (!is_null($node->nid)) {
 

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

@@ -238,10 +238,6 @@ function chado_contact_form(&$node, $form_state) {
  * @ingroup tripal_contact
  */
 function chado_contact_validate($node, $form, &$form_state) {
-  // remove surrounding white-space on submitted values
-  $node->contactname          = trim($node->contactname);
-  $node->description    = trim($node->description);
-
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
@@ -253,6 +249,11 @@ function chado_contact_validate($node, $form, &$form_state) {
     return;
   }
 
+  // remove surrounding white-space on submitted values
+  $node->contactname    = trim($node->contactname);
+  $node->description    = trim($node->description);
+  
+  
   // Validating for an update
   if (property_exists($node, 'nid')) {
     // get the existing node
@@ -610,11 +611,11 @@ function tripal_contact_node_presave($node) {
     case 'chado_contact':
       // for a form submission the 'contactname' field will be set,
       // for a sync, we must pull from the contact object
-      if(property_exists($node, 'contactname')) {
+      if (property_exists($node, 'contactname')) {
         // set the title
         $node->title = $node->contactname;
       }
-      else {
+      else if (property_exists($node, 'contact')) {
         $node->title = $node->contact->name;
       }
       break;

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

@@ -201,8 +201,6 @@ function chado_example_form($node, &$form_state) {
  * @ingroup tripal_example
  */
 function chado_example_validate($node, $form, &$form_state) {
-  // be sure to always trim text fields
-  // $node->uniquename   = trim($node->uniquename);
 
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
@@ -215,6 +213,9 @@ function chado_example_validate($node, $form, &$form_state) {
     return;
   }
 
+  // be sure to always trim text fields
+  // $node->uniquename   = trim($node->uniquename);
+  
   // Validating for an update. If the 'nid' property is present in the node then
   // this is an update and validation can be different for updates
   if (property_exists($node, 'nid')) {
@@ -484,11 +485,11 @@ function tripal_example_node_presave($node) {
     case 'chado_example':
       // for a form submission the 'examplename' field will be set,
       // for a sync, we must pull from the example object
-      if(property_exists($node, 'examplename')) {
+      if (property_exists($node, 'examplename')) {
         // set the title
         $node->title = $node->examplename;
       }
-      else {
+      else if (property_exists($node, 'example')) {
         $node->title = $node->example->name;
       }
       break;

+ 7 - 6
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -244,11 +244,6 @@ function chado_feature_form($node, &$form_state) {
  * @ingroup tripal_feature
  */
 function chado_feature_validate($node, $form, &$form_state) {
-  // remove surrounding white-space on submitted values
-  $node->uniquename   = trim($node->uniquename);
-  $node->fname        = trim($node->fname);
-  $node->feature_type = trim($node->feature_type);
-  $node->residues     = trim($node->residues);
 
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
@@ -261,6 +256,12 @@ function chado_feature_validate($node, $form, &$form_state) {
     return;
   }
 
+  // remove surrounding white-space on submitted values
+  $node->uniquename   = trim($node->uniquename);
+  $node->fname        = trim($node->fname);
+  $node->feature_type = trim($node->feature_type);
+  $node->residues     = trim($node->residues);
+  
   // Validating for an update
   if (property_exists($node, 'nid')) {
 
@@ -723,7 +724,7 @@ function tripal_feature_node_presave($node) {
         $uname       = $node->uniquename;
         $type        = $node->feature_type;
       }
-      else {
+      else if (property_exists($node, 'feature')) {
         $organism_id = $node->feature->organism_id;
         $name        = $node->feature->name;
         $uname       = $node->feature->uniquename;

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

@@ -161,8 +161,6 @@ function chado_featuremap_form($node, &$form_state) {
  * @ingroup tripal_featuremap
  */
 function chado_featuremap_validate($node, $form, &$form_state) {
-  $node->fmapname          = trim($node->fmapname);
-  $node->description    = trim($node->description);
 
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
@@ -175,6 +173,10 @@ function chado_featuremap_validate($node, $form, &$form_state) {
     return;
   }
 
+  // trim white space from text fields
+  $node->fmapname       = trim($node->fmapname);
+  $node->description    = trim($node->description);
+  
   $featuremap = 0;
   // check to make sure the unique name on the map is unique
   // before we try to insert into chado. If this is an update then we will
@@ -470,11 +472,11 @@ function tripal_featuremap_node_presave($node) {
     case 'chado_featuremap':
       // for a form submission the 'fmapname' field will be set,
       // for a sync, we must pull from the featuremap object
-      if(property_exists($node, 'fmapname')) {
+      if (property_exists($node, 'fmapname')) {
         // set the title
         $node->title = $node->fmapname;
       }
-      else {
+      else if (property_exists($node, 'featuremap')) {
         $node->title = $node->featuremap->name;
       }
       break;

+ 14 - 3
tripal_library/includes/tripal_library.chado_node.inc

@@ -210,7 +210,18 @@ 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') {
+    return;
+  }
+  
+  // we are syncing if we do not have a node ID but we do have a featuremap_id. We don't
+  // need to validate during syncing so just skip it.
+  if (is_null($node->nid) and property_exists($node, 'library_id') and $node->library_id != 0) {
+    return;
+  }
+  
+  // trim white space from text fields
   $node->libraryname = trim($node->libraryname);
   $node->uniquename  = trim($node->uniquename);
   $node->description = trim($node->description);
@@ -552,11 +563,11 @@ function tripal_library_node_presave($node) {
     case 'chado_library':
       // for a form submission the 'libraryname' field will be set,
       // for a sync, we must pull from the library object
-      if(property_exists($node, 'libraryname')) {
+      if (property_exists($node, 'libraryname')) {
         // set the title
         $node->title = $node->libraryname;
       }
-      else {
+      else if (property_exists($node, 'library')) {
         $node->title = $node->library->name;
       }
       break;

+ 14 - 15
tripal_organism/includes/tripal_organism.chado_node.inc

@@ -211,14 +211,6 @@ function chado_organism_form($node, $form_state) {
  * @ingroup tripal_organism
  */
 function chado_organism_validate($node, $form, &$form_state) {
-  // remove any white space around values
-  $node->genus        = trim($node->genus);
-  $node->species      = trim($node->species);
-  $node->abbreviation = trim($node->abbreviation);
-  $node->common_name  = trim($node->common_name);
-  $node->description  = trim($node->description);
-
-
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
@@ -230,6 +222,13 @@ function chado_organism_validate($node, $form, &$form_state) {
     return;
   }
 
+  // remove any white space around values
+  $node->genus        = trim($node->genus);
+  $node->species      = trim($node->species);
+  $node->abbreviation = trim($node->abbreviation);
+  $node->common_name  = trim($node->common_name);
+  $node->description  = trim($node->description);
+  
   // Validating for an update
   if (property_exists($node, 'organism_id')) {
     $sql = "
@@ -287,7 +286,7 @@ function chado_organism_insert($node) {
   // if there is an organism_id in the $node object then this must be a sync so
   // we can skip adding the organism as it is already there, although
   // we do need to proceed with the rest of the insert
-  if (!property_exists($node,'organism_id')) {
+  if (!property_exists($node, 'organism_id')) {
     $values = array(
       'genus'        => $node->genus,
       'species'      => $node->species,
@@ -508,14 +507,14 @@ function chado_organism_load($nodes) {
 function tripal_organism_node_presave($node) {
   switch ($node->type) {
     case 'chado_organism':
-      // for a form submission the 'genus' field will be set,
-      // for a sync, we must pull from the organism object
-      if(property_exists($node, 'genus')) {
-        // set the title
+      // when syncing the details are not present in the $node object
+      // as they are when submitted via the form.  Therefore, if we do
+      // not see any field values from the form, we assume this fucntion
+      // is being called for syncing, so we must set the title accordingly
+      if (property_exists($node, 'genus')) {
         $node->title = $node->genus  . " " . $node->species;
       }
-      else {
-        // set the title
+      else if (property_exists($node, 'organism')) {
         $node->title = $node->organism->genus . " " . $node->organism->species;
       }
       break;

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

@@ -198,9 +198,6 @@ function chado_project_form(&$node, $form_state) {
  */
 function chado_project_validate($node, $form, &$form_state) {
 
-  $node->title = trim($node->title);
-  $node->description = trim($node->description);
-
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
@@ -212,6 +209,10 @@ function chado_project_validate($node, $form, &$form_state) {
     return;
   }
 
+  // trim white space from text fields
+  $node->title = trim($node->title);
+  $node->description = trim($node->description);
+  
   $project = 0;
   // check to make sure the name on the project is unique
   // before we try to insert into chado.

+ 7 - 7
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -306,13 +306,6 @@ function chado_pub_form($node, $form_state) {
  */
 function chado_pub_validate($node, $form, &$form_state) {
 
-  // get the submitted values
-  $title        = trim($node->pubtitle);
-  $pyear        = trim($node->pyear);
-  $uniquename   = trim($node->uniquename);
-  $is_obsolete  = $node->is_obsolete;
-  $type_id      = $node->type_id;
-
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
@@ -324,6 +317,13 @@ function chado_pub_validate($node, $form, &$form_state) {
     return;
   }
 
+  // get the submitted values
+  $title        = trim($node->pubtitle);
+  $pyear        = trim($node->pyear);
+  $uniquename   = trim($node->uniquename);
+  $is_obsolete  = $node->is_obsolete;
+  $type_id      = $node->type_id;
+  
   $pub = array();
 
   // make sure the year is four digits

+ 8 - 8
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -342,13 +342,6 @@ function chado_stock_form($node, $form_state) {
  */
 function chado_stock_validate(&$node, $form, &$form_state) {
 
-  // remove surrounding whitespace
-  $node->uniquename = trim($node->uniquename);
-  $node->sname = trim($node->sname);
-  $node->stock_description = trim($node->stock_description);
-  $node->accession = trim($node->accession);
-  $node->db_description = trim($node->db_description);
-
   // if this is a delete then don't validate
   if($node->op == 'Delete') {
     return;
@@ -360,6 +353,13 @@ function chado_stock_validate(&$node, $form, &$form_state) {
     return;
   }
 
+  // remove surrounding whitespace
+  $node->uniquename = trim($node->uniquename);
+  $node->sname = trim($node->sname);
+  $node->stock_description = trim($node->stock_description);
+  $node->accession = trim($node->accession);
+  $node->db_description = trim($node->db_description);
+  
   $int_in_chado_sql = "SELECT count(*) as count FROM {:table} WHERE :column = :value";
   $string_in_chado_sql = "SELECT count(*) as count FROM {:table} WHERE :column = :value";
 
@@ -796,7 +796,7 @@ function tripal_stock_node_presave($node) {
         $cvterm = chado_select_record('cvterm', array('name'), $values);
         $type = $cvterm[0]->name;
       }
-      else {
+      else if (property_exists($node, 'stock')) {
         $organism_id = $node->stock->organism_id;
         $sname       = $node->stock->name;
         $uniquename  = $node->stock->uniquename;