function tripal_pub_import_publications
2.x tripal_pub.DEPRECATED.inc | tripal_pub_import_publications($report_email = FALSE, $do_update = FALSE) |
3.x tripal_pub.DEPRECATED.inc | tripal_pub_import_publications($report_email = FALSE, $do_update = FALSE) |
1.x tripal_pub.api.inc | tripal_pub_import_publications($report_email = FALSE, $do_update = FALSE) |
2 calls to tripal_pub_import_publications()
- drush_tripal_pub_tripal_pubs_import in tripal_pub/
tripal_pub.drush.inc - Imports publications into Chado
- tripal_pub_importer_setup_form_submit in tripal_pub/
includes/ pub_importers.inc
File
- tripal_pub/
api/ tripal_pub.api.inc, line 203 - The Tripal Pub API
Code
function tripal_pub_import_publications($report_email = FALSE, $do_update = FALSE) {
$num_to_retrieve = 100;
$pager_id = 0;
$page = 0;
$num_pubs = 0;
// get a persistent connection
$connection = tripal_db_persistent_chado();
if (!$connection) {
print "A persistant connection was not obtained. Loading will be slow\n";
}
// if we cannot get a connection then let the user know the loading will be slow
tripal_db_start_transaction();
if ($connection) {
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";
}
// 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();
while ($import = db_fetch_object($results)) {
$page = 0;
print "Importing: " . $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 10 at a time
$pubs = tripal_pub_get_remote_search_results($remote_db, $criteria, $num_to_retrieve, $pager_id, $page);
$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);
}
// transaction is complete
tripal_db_commit_transaction();
print "Transaction Complete\n";
// 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
print "Syncing publications with Drupal...\n";
tripal_pub_sync_pubs();
// 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 ($pub['pub_id']) {
$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);
}
// if any of the importers wanted to create contacts from the authors then sync them
if ($do_contact) {
print "Syncing contacts with Drupal...\n";
tripal_contact_sync_contacts();
}
print "Done.\n";
}