function tripal_pub_import_by_dbxref

2.x tripal_pub.DEPRECATED.inc tripal_pub_import_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update)
3.x tripal_pub.DEPRECATED.inc tripal_pub_import_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update)
1.x tripal_pub.api.inc tripal_pub_import_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update)
1 call to tripal_pub_import_by_dbxref()
drush_tripal_pub_tripal_pubs_import in tripal_pub/tripal_pub.drush.inc
Imports publications into Chado

File

tripal_pub/api/tripal_pub.api.inc, line 297
The Tripal Pub API

Code

function tripal_pub_import_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update) {
  $num_to_retrieve = 1;
  $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 the publication 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";
  }

  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'];
    $pubs = tripal_pub_get_remote_search_results($remote_db, $criteria, $num_to_retrieve, $pager_id, $page);
    $pub_id = tripal_pub_add_publications($pubs, $do_contact, $do_update);

  }

  // transaction is complete
  tripal_db_commit_transaction();

  print "Transaction Complete\n";

  // sync the newly added publications with Drupal
  print "Syncing publications with Drupal...\n";
  tripal_pub_sync_pubs();

  // 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";
}