Browse Source

All node types (except stock) have a function to cleanup orphaned nodes but it wasn't complete for some. A new core API function was created that all modules with node types can use to clean up orphaned nodes. Also, the drush trpjob-run command was fixed so that a username must be provided to run the job

spficklin 12 years ago
parent
commit
2840b98e85

+ 10 - 60
tripal_analysis/tripal_analysis.module

@@ -198,13 +198,13 @@ function chado_analysis_insert($node) {
  * @ingroup tripal_analysis
  */
 function chado_analysis_delete($node) {
-  // Before removing, get analysis_id so we can remove it from chado database
-  // later
-  $sql_drupal = "SELECT analysis_id ".
-                 "FROM {chado_analysis} ".
-                 "WHERE nid = %d ".
-                 "AND vid = %d";
-  $analysis_id = db_result(db_query($sql_drupal, $node->nid, $node->vid));
+  $analysis_id = chado_get_id_for_node('analysis', $node);
+  
+  // if we don't have an organism id for this node then this isn't a node of
+  // type chado_organism or the entry in the chado_organism table was lost.
+  if (!$analysis_id){
+    return;
+  }
 
   // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
   $sql_del = "DELETE FROM {chado_analysis} ".
@@ -852,7 +852,7 @@ function get_chado_analyses() {
 }
 
 /**
- * Remove orphaned drupal nodes or chado analysis
+ * Remove orphaned drupal nodes
  *
  * @param $dummy
  *   Not Used -kept for backwards compatibility
@@ -863,58 +863,8 @@ function get_chado_analyses() {
  */
 function tripal_analyses_cleanup($dummy = NULL, $job_id = NULL) {
 
-    // select each node from node table with chado_analysis as type
-    // check to make sure it also exists in chado_analysis table, delete if it doesn't
-    // (this should never, ever happen, but we'll double check anyway)
-  $sql_drupal_node = "SELECT * FROM {node} WHERE type LIKE 'chado_analysis%' order by nid";
-    $sql_drupal_ca = "SELECT * from {chado_analysis} WHERE nid = %d";
-
-  $results = db_query($sql_drupal_node);
-  while ($node = db_fetch_object($results)) {
-        $ca_record = db_fetch_object(db_query($sql_drupal_ca, $node->nid));
-        if (!$ca_record) {
-            node_delete($node->nid);
-      $message = "Missing in chado_analysis table.... DELETING node: $nid->nid\n";
-      watchdog('tripal_analysis', $message, array(), WATCHDOG_WARNING);
-        }
-  }
-
-    // get nodes from chado_analysis table and load into array, saving chado analysis_id
-    // as we iterate through, we'll check that they are actual nodes and
-    // delete if they aren't
-    // (this should never, ever happen, but we'll double check anyway)
-  $sql_drupal_ca2 = "SELECT * FROM {chado_analysis}";
-  $sql_drupal_node2 = "SELECT * FROM {node} WHERE type LIKE 'chado_analysis%' AND nid = %d";
-
-  $results = db_query($sql_drupal_ca2);
-  $nid2aid = array();
-  while ($ca_record = db_fetch_object($results)) {
-        $node = db_fetch_object(db_query($sql_drupal_node2, $ca_record->nid));
-        if (!$node) {
-      db_query("DELETE FROM {chado_analysis} WHERE nid = %nid", $ca_record->nid);
-      $message = "chado_analysis missing node.... DELETING chado_analysis record with nid: $ca_record->nid\n";
-      watchdog('tripal_analysis', $message, array(), WATCHDOG_WARNING);
-        }
-        else{
-        $nid2aid[$ca_record->nid] = $ca_record->analysis_id;
-        }
-  }
-
-  // iterate through all of the chado_analysis nodes in drupal
-    // and delete those that aren't valid in chado
-    $sql_chado = "SELECT analysis_id from {analysis} WHERE analysis_id = %d";
-
-  foreach ($nid2aid as $nid => $aid) {
-        $previous_db = tripal_db_set_active('chado');
-    $chado_record = db_fetch_object(db_query($sql_chado, $aid));
-        tripal_db_set_active($previous_db);
-    if (!$chado_record) {
-            node_delete($nid);
-      $message = "Missing in analysis table in chado.... DELETING node: $nid\n";
-      watchdog('tripal_analysis', $message, array(), WATCHDOG_WARNING);
-    }
-  }
-  return '';
+  return tripal_core_clean_orphaned_nodes('analysis', $job_id);
+  
 }
 /*******************************************************************************
  * tripal_analysis_nodeapi()

+ 101 - 0
tripal_core/api/tripal_core.api.inc

@@ -2884,3 +2884,104 @@ function tripal_core_get_chado_table_schema($table) {
 
    return $table_arr;
 }
+/**
+ * This function will delete Drupal nodes for any sync'ed table (e.g.
+ * feature, organism, analysis, stock, library) if the chado record has been
+ * deleted or the entry in the chado_[table] table has been removed.
+ *
+ * @param $table
+ *   The name of the table that corresonds to the node type we want to clean up.
+ * @param $job_id
+ *   This should be the job id from the Tripal jobs system.  This function
+ *   will update the job status using the provided job ID.
+ *
+ * @ingroup tripal_core_api
+ */
+function tripal_core_clean_orphaned_nodes($table, $job_id) {
+  $count = 0;
+  
+  // build the SQL statments needed to check if nodes point to valid analyses
+  $dsql = "SELECT * FROM {node} WHERE type = 'chado_%s' order by nid";
+  $nsql = "SELECT * FROM {node} WHERE nid = %d";
+  $csql = "SELECT * FROM {chado_%s} where nid = %d ";
+  $clsql= "SELECT * FROM {chado_%s}";
+  $lsql = "SELECT * FROM %s where %s_id = %d ";
+
+  // load into nodes array
+  print "Getting nodes\n";
+  $nodes = array();
+  $res = db_query($dsql, $table);
+  while ($node = db_fetch_object($res)) {
+    $nodes[$count] = $node;
+    $count++;
+  }
+
+  // load the chado_$table into an array
+  print "Getting chado_$table\n";
+  $cnodes = array();
+  $res = db_query($clsql, $table);
+  while ($node = db_fetch_object($res)) {
+    $cnodes[$count] = $node;
+    $count++;
+  }
+  $interval = intval($count * 0.01);
+  if ($interval < 1) {
+    $interval = 1;
+  }
+  
+  // iterate through all of the chado_$table entries and remove those
+  // that don't have a node or don't have a $table record in chado.libary
+  foreach ($cnodes as $nid) {
+  
+    // update the job status every 1% analyses
+    if ($job_id and $i % $interval == 0) {
+      tripal_job_set_progress($job_id, intval(($i / $count) * 100));
+    }
+    
+    // see if the node exits, if not remove the entry from the chado_$table table
+    $node = db_fetch_object(db_query($nsql, $nid->nid));
+    if (!$node) {
+      db_query("DELETE FROM {chado_%s} WHERE nid = %d", $table, $nid->nid);
+      $message = "chado_$table missing node.... DELETING: $nid->nid";
+      watchdog('tripal_core', $message, array(), WATCHDOG_WARNING);
+    }
+    
+    // see if the record in chado exist, if not remove the entry from the chado_$table
+    $table_id = $table . "_id";
+    $record = db_fetch_object(chado_query($lsql, $table, $table, $nid->$table_id));
+    if (!$record) {
+      chado_query("DELETE FROM {chado_%s} WHERE %s_id = '%d'", $table, $table, $nid->$table_id);
+      $message = "chado_$table missing $table.... DELETING entry.";
+      watchdog('tripal_core', $message, array(), WATCHDOG_WARNING);
+    }
+    $i++;
+  }
+   
+  // iterate through all of the nodes and delete those that don't
+  // have a corresponding entry in chado_$table
+  foreach ($nodes as $node) {
+
+    // update the job status every 1% libraries
+    if ($job_id and $i % $interval == 0) {
+      tripal_job_set_progress($job_id, intval(($i / $count) * 100));
+    }
+
+    // check to see if the node has a corresponding entry
+    // in the chado_$table table. If not then delete the node.
+    $link = db_fetch_object(db_query($csql, $table, $node->nid));
+    if (!$link) {
+      if (node_access('delete', $node)) {
+        $message = "Node missing in chado_$table table.... DELETING node $node->nid";
+        watchdog("tripal_core", $message, array(), WATCHDOG_WARNING);
+        node_delete($node->nid);
+      } 
+      else {
+        $message = "Node missing in chado_$table table.... but cannot delete due to improper permissions (node $node->nid)";
+        watchdog("tripal_core", $message, array(), WATCHDOG_WARNING);
+      }
+    }    
+    $i++;
+  }
+
+  return '';
+}

+ 22 - 7
tripal_core/tripal_core.drush.inc

@@ -59,8 +59,11 @@ function tripal_core_drush_command() {
     // used by drush help
     'description' => dt('Lauches any jobs waiting in the queue.'),
     'examples' => array(
-      'Normal Job' => 'drush tripal-launch-jobs',
-      'Parallel Job' => 'drush tripal-launch-jobs --parallel=1'
+      'Normal Job' => 'drush tripal-launch-jobs admin',
+      'Parallel Job' => 'drush tripal-launch-jobs admin --parallel=1'
+    ),
+    'arguments' => array(
+      'user' => dt('The Drupal username under which the job should be run.  The permissions for this user will be used.'),
     ),
     // supply options
     'options' => array(
@@ -77,17 +80,29 @@ function tripal_core_drush_command() {
  *
  * NOTE: The following code is executed when drush 'trpjob-run' or 'drush tripal-launch-jobs' is called
  */
-function drush_tripal_core_tripal_launch_jobs() {
+function drush_tripal_core_tripal_launch_jobs($username) {
   $parallel = drush_get_option('parallel');
   $job_id = drush_get_option('job_id');
+
+  if($username){
+    global $user;
+    $user = user_load(array('name' => $username));
+  }
+  else {
+    drush_print('ERROR: Please provide a username for running this job.'); 
+    return;
+  }
+  
   if ($parallel) {
-    print "Tripal Job Launcher (in parallel)\n";
-    print "-------------------\n";
+    drush_print("Tripal Job Launcher (in parallel)");
+    drush_print("Running as user '$username'");
+    drush_print("-------------------");
     tripal_jobs_launch($parallel,$job_id);
   }
   else {
-    print "Tripal Job Launcher\n";
-    print "-------------------\n";
+    drush_print("Tripal Job Launcher");
+    drush_print("Running as user '$username'");
+    drush_print("-------------------");
     tripal_jobs_launch(0,$job_id);
   }
 }

+ 6 - 4
tripal_core/tripal_launch_jobs.php

@@ -26,9 +26,6 @@ $_SERVER['REQUEST_METHOD'] = NULL;
 require_once 'includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
-fwrite($stdout, "Tripal Job Launcher\n");
-fwrite($stdout, "-------------------\n");
-
 // check to make sure the username is valid
 $username = $argv[1];
 $do_parallel = $argv[2];
@@ -40,6 +37,11 @@ if (!db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '%s'", $userna
 global $user;
 $user = user_load(array('name' => $username));
 
+
+fwrite($stdout, "Tripal Job Launcher\n");
+fwrite($stdout,"Running as user '$username'\n";
+fwrite($stdout, "-------------------\n");
+
 tripal_jobs_launch($do_parallel);
 
 /**
@@ -51,4 +53,4 @@ function print_usage($stdout) {
   fwrite($stdout, "Usage:\n");
   fwrite($stdout, "  php ./sites/all/modules/tripal_core/tripal_launch_jobs <username> \n\n");
   fwrite($stdout, "    where <username> is a Drupal user name\n\n");
-}
+}

+ 18 - 64
tripal_feature/tripal_feature.module

@@ -538,6 +538,12 @@ function chado_feature_update($node) {
 function chado_feature_delete($node) {
 
   $feature_id  = chado_get_id_for_node('feature', $node);
+  
+  // if we don't have a library id for this node then this isn't a node of
+  // type chado_library or the entry in the chado_library table was lost.
+  if (!$feature_id){
+    return;
+  }
 
   // remove the drupal content
   $sql_del = "DELETE FROM {chado_feature} ".
@@ -1529,6 +1535,10 @@ function tripal_feature_load_organism_feature_counts($organism) {
  */
 function tripal_feature_load_organism_feature_browser($organism) {
 
+  if (!$organism) {
+    return array();
+  }
+
   // don't show the browser if the settings in the admin page is turned off
   // instead return the array indicating the status of the browser
   $show_browser = variable_get('tripal_feature_browse_setting', 'show_feature_browser');
@@ -2650,75 +2660,19 @@ function tripal_feature_set_taxonomy($node, $feature_id) {
 
 /**
  *
+ * Remove orphaned drupal nodes
+ *
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
  *
  * @ingroup tripal_feature
  */
 function tripal_features_cleanup($dummy = NULL, $job_id = NULL) {
 
-  // build the SQL statments needed to check if nodes point to valid features
-  $dsql = "SELECT * FROM {node} WHERE type = 'chado_feature' order by nid";
-  $nsql = "SELECT * FROM {node} WHERE nid = %d";
-  $csql = "SELECT * FROM {chado_feature} where nid = %d ";
-  $cfsql= "SELECT * FROM {chado_feature}";
-
-  // load into nodes array
-  $results = db_query($dsql);
-  $count = 0;
-  $nodes = array();
-  while ($node = db_fetch_object($results)) {
-    $nodes[$count] = $node;
-    $count++;
-  }
-
-  // load the chado_features into an array
-  $results = db_query($cfsql);
-  $cnodes = array();
-  while ($node = db_fetch_object($results)) {
-    $cnodes[$count] = $node;
-    $count++;
-  }
-  $interval = intval($count * 0.01);
-  if ($interval > 1) {
-    $interval = 1;
-  }
-
-  // iterate through all of the chado_feature nodes and delete those  that aren't valid
-  foreach ($nodes as $nid) {
-
-    // update the job status every 1% features
-    if ($job_id and $i % $interval == 0) {
-      tripal_job_set_progress($job_id, intval(($i/$count)*100));
-    }
-
-    // check to see if the node has a corresponding entry
-    // in the chado_feature table. If not then delete the node.
-    $feature = db_fetch_object(db_query($csql, $nid->nid));
-    if (!$feature) {
-      node_delete($nid->nid);
-      $message = "Missing in chado_feature table.... DELETING: $nid->nid\n";
-      watchdog('tripal_feature', $message, array(), WATCHDOG_WARNING);
-      continue;
-    }
-
-    $i++;
-  }
-
-  // iterate through all of the chado_feature nodes and delete those  that aren't valid
-  foreach ($cnodes as $nid) {
-    // update the job status every 1% features
-    if ($job_id and $i % $interval == 0) {
-      tripal_job_set_progress($job_id, intval(($i/$count)*100));
-    }
-    $node = db_fetch_object(db_query($nsql, $nid->nid));
-    if (!$node) {
-      db_query("DELETE FROM {chado_feature} WHERE nid = %nid", $nid->nid);
-      $message = "chado_feature missing node.... DELETING: $nid->nid\n";
-      watchdog('tripal_feature', $message, array(), WATCHDOG_WARNING);
-    }
-
-    $i++;
-  }
-  return '';
+  return tripal_core_clean_orphaned_nodes('feature', $job_id);
+ 
 }
 
 /**

+ 0 - 0
tripal_library/tripal_library.api.inc → tripal_library/api/tripal_library.api.inc


+ 0 - 0
tripal_library/reindex.php → tripal_library/includes/reindex.inc


+ 0 - 0
tripal_library/taxonify.php → tripal_library/includes/taxonify.inc


+ 22 - 69
tripal_library/tripal_library.module

@@ -8,7 +8,7 @@
  * @ingroup tripal_modules
  */
 
-require('tripal_library.api.inc');
+require('api/tripal_library.api.inc');
 
 /**
  * Display help and module information
@@ -164,7 +164,10 @@ function tripal_library_views_api() {
  */
 function tripal_library_module_description_page() {
   $text = '';
-
+  $text .= '<h3>Tripal Library Administrative Tools Quick Links:</h3>';
+  $text .= "<ul>
+             <li><a href=\"" . url("admin/tripal/tripal_library/configuration") . "\">Library Configuration</a></li>
+           </ul>";
   $text .= '<h3>Module Description:</h3>';
   $text .= '<p>The Tripal Library module is an interface for the Chado Library module which groups features (sequences) into genetic libraries.
     This module provides support for visualization of "library" pages, editing and updating.</p>';
@@ -1484,13 +1487,15 @@ function tripal_library_taxonify_features($library_id = NULL, $job_id = NULL) {
  * @ingroup tripal_library
  */
 function chado_library_delete(&$node) {
-  // Before removing, get library_id so we can remove it from chado database
-  // later
-  $sql_drupal = "SELECT library_id ".
-               "FROM {chado_library} ".
-               "WHERE nid = %d AND vid = %d";
-  $library_id = db_result(db_query($sql_drupal, $node->nid, $node->vid));
 
+  $library_id = chado_get_id_for_node('library', $node);
+  
+  // if we don't have a library id for this node then this isn't a node of
+  // type chado_library or the entry in the chado_library table was lost.
+  if (!$library_id){
+    return;
+  }
+  
   // Remove data from {chado_library}, {node} and {node_revisions} tables of
   // drupal database
   $sql_del = "DELETE FROM {chado_library} ".
@@ -1637,73 +1642,21 @@ function get_chado_libraries() {
   }
   }
 /**
+ * Remove orphaned drupal nodes
+ *
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
  *
  * @ingroup tripal_library
  */
 function tripal_library_cleanup($dummy = NULL, $job_id = NULL) {
 
-  // build the SQL statments needed to check if nodes point to valid analyses
-  $dsql = "SELECT * FROM {node} WHERE type = 'chado_library' order by nid";
-  $nsql = "SELECT * FROM {node} WHERE nid = %d";
-  $csql = "SELECT * FROM {chado_library} where nid = %d ";
-  $cosql= "SELECT * FROM {chado_library}";
-  $tsql = "SELECT * FROM {library} L WHERE library_id = %d";
-
-  // load into nodes array
-  $results = db_query($dsql);
-  $count = 0;
-  $nodes = array();
-  while ($node = db_fetch_object($results)) {
-    $nodes[$count] = $node;
-    $count++;
-  }
-
-  // load the chado_analyses into an array
-  $results = db_query($cosql);
-  $cnodes = array();
-  while ($node = db_fetch_object($results)) {
-    $cnodes[$count] = $node;
-    $count++;
-  }
-  $interval = intval($count * 0.01);
-
-  // iterate through all of the chado_library nodes and delete those that aren't valid
-  foreach ($nodes as $nid) {
-
-    // update the job status every 1% analyses
-    if ($job_id and $i % $interval == 0) {
-      tripal_job_set_progress($job_id, intval(($i/$count)*100));
-    }
-
-    // first check to see if the node has a corresponding entry
-    // in the chado_library table. If not then delete the node.
-    $library = db_fetch_object(db_query($csql, $nid->nid));
-    if (!$library) {
-      node_delete($nid->nid);
-      $message = "Missing in chado_library table.... DELETING: $nid->nid\n";
-      watchdog('tripal_library', $message, array(), WATCHDOG_WARNING);
-      continue;
-    }
-    $i++;
-  }
-
-  // iterate through all of the chado_library nodes and delete those  that aren't valid
-  foreach ($cnodes as $nid) {
-    // update the job status every 1% analyses
-    if ($job_id and $i % $interval == 0) {
-      tripal_job_set_progress($job_id, intval(($i/$count)*100));
-    }
-    $node = db_fetch_object(db_query($nsql, $nid->nid));
-    if (!$node) {
-      db_query("DELETE FROM {chado_library} WHERE nid = '%nid'", $nid->nid);
-      $message = "chado_library missing node.... DELETING: $nid->nid\n";
-      watchdog('tripal_library', $message, array(), WATCHDOG_WARNING);
-    }
-
-    $i++;
-  }
-  return '';
+  return tripal_core_clean_orphaned_nodes('library', $job_id);
+  
 }
+
 /************************************************************************
  */
 function theme_tripal_library_search_result($node) {

+ 21 - 70
tripal_organism/tripal_organism.module

@@ -614,7 +614,7 @@ function tripal_organism_admin_validate($form, &$form_state) {
   // Submit the Cleanup Job if selected
   if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
     tripal_add_job('Cleanup orphaned organisms', 'tripal_organism',
-      'tripal_organisms_cleanup', $job_args, $user->uid);
+      'tripal_organism_cleanup', $job_args, $user->uid);
   }
 }
 /**
@@ -799,19 +799,25 @@ function chado_organism_update($node) {
  */
 function chado_organism_delete($node) {
   $organism_id = chado_get_id_for_node('organism', $node);
+  
+  // if we don't have an organism id for this node then this isn't a node of
+  // type chado_organism or the entry in the chado_organism table was lost.
+  if (!$organism_id){
+    return;
+  }
 
   // Remove data from the {chado_organism}, {node}, and {node_revisions} tables
   $sql_del = "DELETE FROM {chado_organism} ".
-            "WHERE nid = %d ".
-            "AND vid = %d";
+             "WHERE nid = %d ".
+             "AND vid = %d";
   db_query($sql_del, $node->nid, $node->vid);
   $sql_del = "DELETE FROM {node} ".
-            "WHERE nid = %d ".
-            "AND vid = %d";
+             "WHERE nid = %d ".
+             "AND vid = %d";
   db_query($sql_del, $node->nid, $node->vid);
   $sql_del = "DELETE FROM {node_revisions} ".
-            "WHERE nid = %d ".
-            "AND vid = %d";
+             "WHERE nid = %d ".
+             "AND vid = %d";
   db_query($sql_del, $node->nid, $node->vid);
 
   // Test dependency before deleting from chado database. If a library or
@@ -1183,73 +1189,18 @@ function tripal_organism_taxonify_features($organism_id = NULL, $job_id = NULL)
   }
 }
 /**
+ * Remove orphaned drupal nodes
+ *
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
  *
  * @ingroup tripal_organism
  */
-function tripal_organisms_cleanup($dummy = NULL, $job_id = NULL) {
-
-  // build the SQL statments needed to check if nodes point to valid organisms
-  $dsql = "SELECT * FROM {node} WHERE type = 'chado_organism' order by nid";
-  $nsql = "SELECT * FROM {node} WHERE nid = %d";
-  $csql = "SELECT * FROM {chado_organism} where nid = %d ";
-  $cosql= "SELECT * FROM {chado_organism}";
-  $tsql = "SELECT * FROM {Organism} O ".
-         "WHERE organism_id = %d";
-
-  // load into nodes array
-  $results = db_query($dsql);
-  $count = 0;
-  $nodes = array();
-  while ($node = db_fetch_object($results)) {
-    $nodes[$count] = $node;
-    $count++;
-  }
-
-  // load the chado_organisms into an array
-  $results = db_query($cosql);
-  $cnodes = array();
-  while ($node = db_fetch_object($results)) {
-    $cnodes[$count] = $node;
-    $count++;
-  }
-  $interval = intval($count * 0.01);
-
-  // iterate through all of the chado_organism nodes and delete those that aren't valid
-  foreach ($nodes as $nid) {
-
-    // update the job status every 1% organisms
-    if ($job_id and $i % $interval == 0) {
-      tripal_job_set_progress($job_id, intval(($i/$count)*100));
-    }
-
-    // first check to see if the node has a corresponding entry
-    // in the chado_organism table. If not then delete the node.
-    $organism = db_fetch_object(db_query($csql, $nid->nid));
-    if (!$organism) {
-      node_delete($nid->nid);
-      $message = "Missing in chado_organism table.... DELETING: $nid->nid\n";
-      watchdog('tripal_organism', $message, array(), WATCHDOG_WARNING);
-      continue;
-    }
-    $i++;
-  }
+function tripal_organism_cleanup($dummy = NULL, $job_id = NULL) {
 
-  // iterate through all of the chado_organism nodes and delete those  that aren't valid
-  foreach ($cnodes as $nid) {
-    // update the job status every 1% organisms
-    if ($job_id and $i % $interval == 0) {
-      tripal_job_set_progress($job_id, intval(($i/$count)*100));
-    }
-    $node = db_fetch_object(db_query($nsql, $nid->nid));
-    if (!$node) {
-      db_query("DELETE FROM {chado_organism} WHERE nid = %d", $nid->nid);
-      $message = "chado_organism missing node.... DELETING: $nid->nid\n";
-      watchdog('tripal_organism', $message, array(), WATCHDOG_WARNING);
-    }
-
-    $i++;
-  }
-  return '';
+  return tripal_core_clean_orphaned_nodes('organism', $job_id);
 }
 
 /**