function chado_cleanup_orphaned_nodes
2.x tripal_core.chado_nodes.api.inc | chado_cleanup_orphaned_nodes($table, $nentries = 25000, $linking_table = NULL, $node_type = NULL, $job_id = NULL) |
3.x tripal_core.chado_nodes.api.inc | chado_cleanup_orphaned_nodes($table, $nentries = 25000,
$linking_table = NULL, $node_type = NULL, $job_id = NULL) |
This function is a wrapper for the chado_cleanup_orphaned_nodes function. It breaks up the work of chado_cleanup_orphaned_nodes into smaller pieces that are more managable for servers that may have low php memory settings.
Parameters
$table: The name of the table that corresonds to the node type we want to clean up.
$nentries: Optional. The number of entries to parse at one time (ie: the batch size). Set to zero if no limit is needed.
$linking_table: Optional. The name of the linking table that maps Drupal nodes to Chado records. This is only required if the linking table name is not of the form: chado_[table] where [table] is the value provided to the $table argument.
$node_type: Optional. The name of the node type for the records. This is only required if the node type is not of the form: chado_[table] where [table] is the value provided to the $table.
$job_id: Optional. This should be the job id from the Tripal jobs system. Typically, only the Tripal jobs system will use the argument.
Related topics
- drush_tripal_core_tripal_node_clean in tripal_core/
tripal_core.drush.inc - DEPRECATED. Clean-up orphaned Drupal nodes and chado records.
- drush_tripal_core_trp_clean_nodes in tripal_core/
tripal_core.drush.inc - Clean-up orphaned Drupal nodes and chado records.
- drush_tripal_phylogeny_trp_delete_phylotree in tripal_phylogeny/
tripal_phylogeny.drush.inc - Deletes a phylotree record.
- tripal_analysis_delete_analyses in tripal_analysis/
includes/ tripal_analysis.delete.inc - Function to actually delete the features indicated
- tripal_core_chado_node_cleanup_orphaned in tripal_core/
api/ tripal_core.DEPRECATED.api.inc
- chado_node_sync_form_submit in tripal_core/
api/ tripal_core.chado_nodes.api.inc - Generic Sync Form Submit
- tripal_core_chado_node_cleanup_orphaned in tripal_core/
api/ tripal_core.DEPRECATED.api.inc
File
- tripal_core/
api/ tripal_core.chado_nodes.api.inc, line 1005 - API to handle much of the common functionality implemented when creating a drupal node type.
Code
function chado_cleanup_orphaned_nodes($table, $nentries = 25000, $linking_table = NULL, $node_type = NULL, $job_id = NULL) {
// The max number of records either as nodes or linked records.
$count = 0;
// Will hold the number of nodes of this type.
$ncount = 0;
// Will hold the number of linked records.
$clcount = 0;
if (!$node_type) {
$node_type = 'chado_' . $table;
}
if (!$linking_table) {
$linking_table = 'chado_' . $table;
}
// Find the number nodes of type chado_$table and find the number of entries
// in chado_$table; keep the larger of the two numbers.
$dsql = "SELECT COUNT(*) FROM {node} WHERE type = :node_type";
$ndat = db_query($dsql, array(':node_type' => $node_type));
$temp = $ndat->fetchObject();
$ncount = $temp->count;
$clsql = "SELECT COUNT(*) FROM {" . $linking_table . "}";
$cdat = db_query($clsql);
$clcount = $cdat->fetchObject();
if ($ncount < $clcount) {
$count = $clcount;
}
else {
$count = $ncount;
}
$transaction = db_transaction();
print "\nNOTE: This operation is performed using a database transaction. \n" .
"If it fails or is terminated prematurely then the entire set of \n" .
"changes is rolled back and will not be found in the database\n\n";
try {
$m = ceil($count / $nentries);
for ($i = 0; $i < $m; $i++) {
$offset = ($nentries * $i);
chado_cleanup_orphaned_nodes_part($table, $job_id, $nentries, $offset, $linking_table, $node_type);
}
}
catch (Exception $e) {
$transaction->rollback();
print "\n"; // make sure we start errors on new line
watchdog_exception('trp-fsync', $e);
print "FAILED: Rolling back database changes...\n";
}
return '';
}