|
@@ -614,7 +614,7 @@ function tripal_organism_admin_validate($form, &$form_state) {
|
|
// Submit the Cleanup Job if selected
|
|
// Submit the Cleanup Job if selected
|
|
if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
|
|
if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
|
|
tripal_add_job('Cleanup orphaned organisms', 'tripal_organism',
|
|
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) {
|
|
function chado_organism_delete($node) {
|
|
$organism_id = chado_get_id_for_node('organism', $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
|
|
// Remove data from the {chado_organism}, {node}, and {node_revisions} tables
|
|
$sql_del = "DELETE FROM {chado_organism} ".
|
|
$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);
|
|
db_query($sql_del, $node->nid, $node->vid);
|
|
$sql_del = "DELETE FROM {node} ".
|
|
$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);
|
|
db_query($sql_del, $node->nid, $node->vid);
|
|
$sql_del = "DELETE FROM {node_revisions} ".
|
|
$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);
|
|
db_query($sql_del, $node->nid, $node->vid);
|
|
|
|
|
|
// Test dependency before deleting from chado database. If a library or
|
|
// 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
|
|
* @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);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|