function chado_execute_active_pub_importers
3.x tripal_chado.pub.api.inc | chado_execute_active_pub_importers($report_email = FALSE, $do_update = FALSE) |
Imports all publications for all active import setups.
Parameters
$report_email: A list of email address, separated by commas, that should be notified once importing has completed.
$do_update: If set to TRUE then publications that already exist in the Chado database will be updated, whereas if FALSE only new publications will be added.
Related topics
2 calls to chado_execute_active_pub_importers()
- drush_tripal_chado_trp_import_pubs in tripal_chado/
tripal_chado.drush.inc - Imports publications into Chado
- tripal_execute_active_pub_importers in tripal_chado/
api/ modules/ tripal_chado.module.DEPRECATED.api.inc - Imports all publications for all active import setups.
File
- tripal_chado/
api/ modules/ tripal_chado.pub.api.inc, line 416 - Provides API functions specificially for managing publication records in Chado.
Code
function chado_execute_active_pub_importers($report_email = FALSE, $do_update = FALSE) {
$num_to_retrieve = 100;
$page = 0;
print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
"If the load fails or is terminated prematurely then the entire set of \n" .
"insertions/updates is rolled back and will not be found in the database\n\n";
// start the transaction
$transaction = db_transaction();
try {
// Get all of the loaders.
$args = array();
$sql = "SELECT * FROM {tripal_pub_import} WHERE disabled = 0 ";
$results = db_query($sql, $args);
$do_contact = FALSE;
$reports = array();
foreach ($results as $import) {
$page = 0;
print "Executing importer: '" . $import->name . "'\n";
// Keep track if any of the importers want to create contacts from authors.
if ($import->do_contact == 1) {
$do_contact = TRUE;
}
$criteria = unserialize($import->criteria);
$remote_db = $criteria['remote_db'];
do {
// Retrieve the pubs for this page. We'll retreive 100 at a time.
$results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
$pubs = $results['pubs'];
$reports[$import->name] = tripal_pub_add_publications($pubs, $import->do_contact, $do_update);
$page++;
}
// Continue looping until we have a $pubs array that does not have
// our requested numer of records. This means we've hit the end.
while (count($pubs) == $num_to_retrieve);
}
// Sync the newly added publications with Drupal. If the user
// requested a report then we don't want to print any syncing information
// so pass 'FALSE' to the sync call.
// For backwards compatibility check to see if the legacy pub module
// is enabled. If so, then sync the nodes.
if (module_exists('tripal_pub')) {
print "Syncing publications with Drupal...\n";
chado_node_sync_records('pub');
}
// Iterate through each of the reports and generate a final report with HTML
// links.
$HTML_report = '';
if ($report_email) {
$HTML_report .= "<html>";
global $base_url;
foreach ($reports as $importer => $report) {
$total = count($report['inserted']);
$HTML_report .= "<b>$total new publications from importer: $importer</b><br><ol>\n";
foreach ($report['inserted'] as $pub) {
$item = $pub['Title'];
if (array_key_exists('pub_id', $pub)) {
$item = l($pub['Title'], "$base_url/pub/" . $pub['pub_id']);
}
$HTML_report .= "<li>$item</li>\n";
}
$HTML_report .= "</ol>\n";
}
$HTML_report .= "</html>";
$site_email = variable_get('site_mail', '');
$params = array(
'message' => $HTML_report
);
drupal_mail('tripal_pub', 'import_report', $report_email, language_default(), $params, $site_email, TRUE);
}
// For backwards compatibility check to see if the legacy pub module
// is enabled. If so, then sync the nodes.
if (module_exists('tripal_pub')) {
// If any of the importers wanted to create contacts from the authors then
// sync them.
if ($do_contact) {
print "Syncing contacts with Drupal...\n";
chado_node_sync_records('contact');
}
}
}
catch (Exception $e) {
$transaction->rollback();
print "\n"; // make sure we start errors on new line
watchdog_exception('T_pub_import', $e);
print "FAILED: Rolling back database changes...\n";
return;
}
print "Done.\n";
}