function tripal_import_pub_by_dbxref
2.x tripal_pub.pub_importers.inc | tripal_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update) |
3.x tripal_chado.module.DEPRECATED.api.inc | tripal_import_pub_by_dbxref($pub_dbxref, $do_contact = false, $do_update = true) |
Imports a singe publication specified by a remote database cross reference.
Parameters
$pub_dbxref: The unique database ID for the record to update. This value must be of the format DB_NAME:ACCESSION where DB_NAME is the name of the database (e.g. PMID or AGL) and the ACCESSION is the unique identifier for the record in the database.
$do_contact: Set to TRUE if authors should automatically have a contact record added to Chado.
$do_update: If set to TRUE then the publication will be updated if it already exists in the database.
Related topics
2 calls to tripal_import_pub_by_dbxref()
- drush_tripal_pub_trp_import_pubs in tripal_pub/
tripal_pub.drush.inc - Imports publications into Chado
- tripal_pub_import_by_dbxref in tripal_pub/
api/ tripal_pub.DEPRECATED.inc
File
- tripal_pub/
includes/ tripal_pub.pub_importers.inc, line 1746 - Management of importers
Code
function tripal_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update) {
$num_to_retrieve = 1;
$pager_id = 0;
$page = 0;
$num_pubs = 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";
$transaction = db_transaction();
try {
if (preg_match('/^(.*?):(.*?)$/', $pub_dbxref, $matches)) {
$dbname = $matches[1];
$accession = $matches[2];
$criteria = array(
'num_criteria' => 1,
'remote_db' => $dbname,
'criteria' => array(
'1' => array(
'search_terms' => "$dbname:$accession",
'scope' => 'id',
'operation' => '',
'is_phrase' => 0,
),
),
);
$remote_db = $criteria['remote_db'];
$results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
$pubs = $results['pubs'];
$search_str = $results['search_str'];
$total_records = $results['total_records'];
$pub_id = tripal_pub_add_publications($pubs, $do_contact, $do_update);
}
// sync the newly added publications with Drupal
print "Syncing publications with Drupal...\n";
chado_node_sync_records('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";
}