function tripal_execute_pub_importer
2.x tripal_pub.pub_importers.inc | tripal_execute_pub_importer($import_id, $job_id = NULL) |
3.x tripal_chado.pub_importers.inc | tripal_execute_pub_importer($import_id, $job_id = NULL) |
Imports all publications for a given publication import setup.
Parameters
$import_id: The ID of the import setup to use
$job_id: The jobs management job_id for the job if this function is run as a job.
Related topics
2 calls to tripal_execute_pub_importer()
- tripal_pub_importer_setup_form_submit in tripal_pub/
includes/ tripal_pub.pub_importers.inc - Submit the tripal_pub_importer_setup_form form
- tripal_pub_import_publications_by_import_id in tripal_pub/
api/ tripal_pub.DEPRECATED.inc
3 string references to 'tripal_execute_pub_importer'
- tripal_pub_importer_submit_job in tripal_pub/
includes/ tripal_pub.pub_importers.inc - Add a job to import publications
- tripal_pub_import_publications_by_import_id in tripal_pub/
api/ tripal_pub.DEPRECATED.inc - tripal_pub_job_describe_args in tripal_pub/
tripal_pub.module - Implements hook_job_describe_args().
File
- tripal_pub/
includes/ tripal_pub.pub_importers.inc, line 1568 - Management of importers
Code
function tripal_execute_pub_importer($import_id, $job_id = 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";
// start the transaction
$transaction = db_transaction();
try {
$page = 0;
$do_contact = FALSE;
$num_to_retrieve = 100;
// get all of the loaders
$args = array(':import_id' => $import_id);
$sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
$import = db_query($sql, $args)->fetchObject();
print "Executing Importer: '" . $import->name . "'\n";
$criteria = unserialize($import->criteria);
$remote_db = $criteria['remote_db'];
$total_pubs = 0;
do {
// retrieve the pubs for this page. We'll retreive 100 at a time
$results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
$pubs = $results['pubs'];
$num_pubs = $rseults['total_records'];
$total_pubs += $num_pubs;
tripal_pub_add_publications($pubs, $import->do_contact);
$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);
// 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";
chado_node_sync_records('pub');
// if any of the importers wanted to create contacts from the authors then sync them
if ($import->do_contact) {
print "Syncing contacts with Drupal...\n";
chado_node_sync_records('contact');
}
tripal_set_job_progress($job_id, '100');
}
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";
}