Browse Source

Fixed bug in hook_load() if nodes were orphaned

Stephen Ficklin 11 years ago
parent
commit
7fc8443a04

+ 6 - 0
tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -536,6 +536,12 @@ function chado_analysis_load($nodes) {
     // find the analysis and add in the details
     $analysis_id = chado_get_id_from_nid('analysis', $nid);
 
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    if (!$analysis_id) {
+      continue;
+    }
+    
     // build the analysis variable
     $values = array('analysis_id' => $analysis_id);
     $analysis = chado_generate_var('analysis', $values);

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

@@ -496,6 +496,12 @@ function chado_contact_load($nodes) {
     // find the contact and add in the details
     $contact_id = chado_get_id_from_nid('contact', $nid);
 
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    if (!$contact_id) {
+      continue;
+    }
+    
     // get the contact
     $values = array('contact_id' => $contact_id);
     $contact = chado_generate_var('contact', $values);

+ 6 - 0
tripal_example/includes/tripal_example.chado_node.inc

@@ -442,6 +442,12 @@ function chado_example_load($nodes) {
     // find the example and add in the details
     //$example_id = chado_get_id_from_nid('example', $nid);
 
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    //if (!$example_id) {
+    //  continue;
+    //}
+    
     // build the example variable by using the chado_generate_var() function
     //$values = array('example_id' => $example_id);
     //$example = chado_generate_var('example', $values);

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

@@ -670,6 +670,12 @@ function chado_feature_load($nodes) {
   foreach ($nodes as $nid => $node) {
     // find the feature and add in the details
     $feature_id = chado_get_id_from_nid('feature', $nid);
+    
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    if (!$feature_id) {
+      continue;
+    }
 
     // build the feature variable
     $values = array('feature_id' => $feature_id);

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

@@ -419,6 +419,12 @@ function chado_featuremap_load($nodes) {
     // get the feature details from chado
     $featuremap_id = chado_get_id_from_nid('featuremap', $node->nid);
 
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    if (!$featuremap_id) {
+      continue;
+    }
+    
     $values = array('featuremap_id' => $featuremap_id);
     $featuremap = chado_generate_var('featuremap', $values);
 

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

@@ -387,6 +387,12 @@ function chado_library_load($nodes) {
     // get the feature details from chado
     $library_id = chado_get_id_from_nid('library', $node->nid);
 
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    if (!$library_id) {
+      continue;
+    }
+    
     $values = array('library_id' => $library_id);
     $library = chado_generate_var('library', $values);
 

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

@@ -484,6 +484,12 @@ function chado_organism_load($nodes) {
   foreach ($nodes as $nid => $node) {
     // find the organism and add in the details
     $organism_id = chado_get_id_from_nid('organism', $nid);
+    
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    if (!$organism_id) {
+      continue;
+    }
 
     // build the organism variable
     $values = array('organism_id' => $organism_id);

+ 7 - 0
tripal_project/includes/tripal_project.chado_node.inc

@@ -394,6 +394,13 @@ function chado_project_load($nodes) {
     // get the feature details from chado
     $project_id = chado_get_id_from_nid('project', $node->nid);
 
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    if (!$project_id) {
+      continue;
+    }
+    
+    
     $values = array('project_id' => $project_id);
     $project = chado_generate_var('project', $values);
 

+ 30 - 0
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -959,6 +959,12 @@ function chado_pub_load($nodes) {
   foreach ($nodes as $nid => $node) {
     // find the pub and add in the details
     $pub_id = chado_get_id_from_nid('pub', $nid);
+    
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes. 
+    if (!$pub_id) {
+      continue;
+    }
 
     // get the pub
     $values = array('pub_id' => $pub_id);
@@ -1146,3 +1152,27 @@ function tripal_pub_node_update($node) {
     tripal_pub_set_pub_url($node, $pub_id);
   }
 }
+
+/**
+ * Implements hook_node_presave(). Acts on all content types.
+ *
+ * @ingroup tripal_stock
+ */
+function tripal_pub_node_presave($node) {
+  switch ($node->type) {
+    case 'chado_pub':
+      // 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, 'title')) {
+        // do nothing, the title is set
+      }
+      else if (property_exists($node, 'pub')) {
+        // in Drupal a node title can only be 255 characters so we truncate
+        // it just in case
+        $node->title = substr($node->pub->title, 0, 255);
+      }
+      break;
+  }
+}

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

@@ -56,43 +56,42 @@ function chado_stock_load($nodes) {
   foreach ($nodes as $nid => $node) {
     // get the stock details from chado
     $stock_id = chado_get_id_from_nid('stock', $node->nid);
-    if (empty($stock_id)) {
-      tripal_report_error('tripal_stock', TRIPAL_ERROR,
-        'Unable to retrieve stock_id for %title (NID = %nid).',
-        array('%title' => $node->title, '%nid' => $node->nid)
-      );
+    
+    // if the nid does not have a matching record then skip this node.
+    // this can happen with orphaned nodes.
+    if (!$stock_id) {
+      continue;
     }
-    else {
 
-      // build the variable with all the stock details
-      $values = array('stock_id' => $stock_id);
-      $stock = chado_generate_var('stock', $values);
-
-      // by default, the titles are saved using the unique constraint.  We will
-      // keep it the same, but remove the duplicate name if the unique name and name
-      // are identical
-      $title_type = variable_get('chado_stock_title', 'unique_constraint');
-      if($title_type == 'unique_constraint') {
-        if (strcmp($stock->name, $stock->uniquename)==0) {
-          $node->title = $stock->name . " (" . $stock->type_id->name . ") " . $stock->organism_id->genus . " " . $stock->organism_id->species ;
-        }
-        // in previous version of Tripal, the stock title was simply the unique name.
-        // so, we recreate the title just to be sure all of our stock pages are consistent
-        else {
-          $node->title = $stock->name . ", " . $stock->uniquename . " (" . $stock->type_id->name . ") " . $stock->organism_id->genus . " " . $stock->organism_id->species ;
-        }
-      }
-      // set the title to be the stock name or uniquename as configured
-      if($title_type == 'stock_name') {
-        $node->title = $stock->name;
+    // build the variable with all the stock details
+    $values = array('stock_id' => $stock_id);
+    $stock = chado_generate_var('stock', $values);
+
+    // by default, the titles are saved using the unique constraint.  We will
+    // keep it the same, but remove the duplicate name if the unique name and name
+    // are identical
+    $title_type = variable_get('chado_stock_title', 'unique_constraint');
+    if($title_type == 'unique_constraint') {
+      if (strcmp($stock->name, $stock->uniquename)==0) {
+        $node->title = $stock->name . " (" . $stock->type_id->name . ") " . $stock->organism_id->genus . " " . $stock->organism_id->species ;
       }
-      if($title_type == 'stock_unique_name') {
-        $node->title = $stock->uniquename;
+      // in previous version of Tripal, the stock title was simply the unique name.
+      // so, we recreate the title just to be sure all of our stock pages are consistent
+      else {
+        $node->title = $stock->name . ", " . $stock->uniquename . " (" . $stock->type_id->name . ") " . $stock->organism_id->genus . " " . $stock->organism_id->species ;
       }
-
-      // add this to the node
-      $node->stock = $stock;
     }
+    // set the title to be the stock name or uniquename as configured
+    if($title_type == 'stock_name') {
+      $node->title = $stock->name;
+    }
+    if($title_type == 'stock_unique_name') {
+      $node->title = $stock->uniquename;
+    }
+
+    // add this to the node
+    $node->stock = $stock;
+    
 
     $new_nodes[$nid] = $node;