function chado_reimport_publications
2.x tripal_pub.DEPRECATED.inc | chado_reimport_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL) |
3.x tripal_chado.pub.api.inc | chado_reimport_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL) |
Updates publication records.
Updates publication records that currently exist in the Chado pub table with the most recent data in the remote database.
Parameters
$do_contact: Set to TRUE if authors should automatically have a contact record added to Chado. Contacts are added using the name provided by the remote database.
$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.
$db: The name of the remote database to update. If this value is provided and no dbxref then all of the publications currently in the Chado database for this remote database will be updated.
Related topics
3 calls to chado_reimport_publications()
- drush_tripal_chado_trp_update_pubs in tripal_chado/
tripal_chado.drush.inc - Imports publications into Chado
- tripal_pub_update_publications in legacy/
tripal_pub/ api/ tripal_pub.DEPRECATED.inc - tripal_reimport_publications in tripal_chado/
api/ modules/ tripal_chado.module.DEPRECATED.api.inc - Updates publication records.
1 string reference to 'chado_reimport_publications'
- tripal_pub_update_publications in legacy/
tripal_pub/ api/ tripal_pub.DEPRECATED.inc
File
- tripal_chado/
api/ modules/ tripal_chado.pub.api.inc, line 534 - Provides API functions specificially for managing publication records in Chado.
Code
function chado_reimport_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL) {
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 {
// Get a list of all publications by their Dbxrefs that have supported
// databases.
$sql = "
SELECT DB.name as db_name, DBX.accession
FROM pub P
INNER JOIN pub_dbxref PDBX ON P.pub_id = PDBX.pub_id
INNER JOIN dbxref DBX ON DBX.dbxref_id = PDBX.dbxref_id
INNER JOIN db DB ON DB.db_id = DBX.db_id
";
$args = array();
if ($dbxref and preg_match('/^(.*?):(.*?)$/', $dbxref, $matches)) {
$dbname = $matches[1];
$accession = $matches[2];
$sql .= "WHERE DBX.accession = :accession and DB.name = :dbname ";
$args[':accession'] = $accession;
$args[':dbname'] = $dbname;
}
elseif ($db) {
$sql .= " WHERE DB.name = :dbname ";
$args[':dbname'] = $db;
}
$sql .= "ORDER BY DB.name, P.pub_id";
$results = chado_query($sql, $args);
$num_to_retrieve = 100;
$i = 0; // count the number of IDs. When we hit $num_to_retrieve we'll do the query.
$curr_db = ''; // keeps track of the current current database.
$ids = array(); // the list of IDs for the database.
$search = array(); // the search array passed to the search function.
// Iterate through the pub IDs.
while ($pub = $results->fetchObject()) {
$accession = $pub->accession;
$remote_db = $pub->db_name;
// Here we need to only update publications for databases we support.
$supported_dbs = variable_get('tripal_pub_supported_dbs', array());
if (!in_array($remote_db, $supported_dbs)) {
continue;
}
$search = array(
'num_criteria' => 1,
'remote_db' => $remote_db,
'criteria' => array(
'1' => array(
'search_terms' => "$remote_db:$accession",
'scope' => 'id',
'operation' => '',
'is_phrase' => 0,
),
),
);
$pubs = tripal_get_remote_pubs($remote_db, $search, 1, 0);
tripal_pub_add_publications($pubs, $do_contact, TRUE);
$i++;
}
// For backwards compatibility check to see if the legacy pub module
// is enabled. If so, then sync the nodes.
if (module_exists('tripal_pub')) {
// Sync the newly added publications with Drupal.
print "Syncing publications with Drupal...\n";
chado_node_sync_records('pub');
// If the caller wants to create contacts then we should 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";
}