function tripal_pub_update_publications

2.x tripal_pub.DEPRECATED.inc tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL)
3.x tripal_pub.DEPRECATED.inc tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL)
1.x tripal_pub.api.inc tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL)

Related topics

1 call to tripal_pub_update_publications()
drush_tripal_pub_tripal_pubs_update in tripal_pub/tripal_pub.drush.inc
Imports publications into Chado

File

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

Code

function tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL) {

  // 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 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 = '%s' and DB.name = '%s' ";
    $args[] = $accession;
    $args[] = $dbname;
  }
  elseif ($db) {
    $sql .= " WHERE DB.name = '%s' ";
    $args[] = $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 = db_fetch_object($results)) {
    $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_pub_get_remote_search_results($remote_db, $search, 1, 0);
    tripal_pub_add_publications($pubs, $do_contact, TRUE);

    $i++;
  }

  // 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 the caller wants to create contacts then we should sync them
  if ($do_contact) {
    print "Syncing contacts with Drupal...\n";
    tripal_contact_sync_contacts();
  }

  print "Done.\n";
}