|
@@ -133,13 +133,9 @@ function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL)
|
|
|
drupal_set_message(t('If you want to create contact pages for authors, you must first ') . l(t('load the Tripal Contact Ontology'), 'admin/tripal/loaders/chado_vocabs/obo_loader'), 'error');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Commenting the AGL message out until we get AGL working again.
|
|
|
- * spf 6/22/2018
|
|
|
- * if(!extension_loaded ('yaz')){
|
|
|
- * drupal_set_message(t('<b>Note:</b> In order to create an importer using the USDA National Agricultural Library (AGL) you must install the yaz libraries. See the ') . l(t('Pub Module help page'), 'admin/tripal/legacy/tripal_pub/help') . ' for assistance. If you do not want to use AGL you can ignore this warning.', 'warning');
|
|
|
- * }
|
|
|
- */
|
|
|
+ if(!extension_loaded ('yaz')){
|
|
|
+ drupal_set_message(t('<b>Note:</b> In order to create an importer using the USDA National Agricultural Library (AGL) you must install the yaz libraries. See the ') . l(t('Pub Module help page'), 'admin/tripal/legacy/tripal_pub/help') . ' for assistance. If you do not want to use AGL you can ignore this warning.', 'warning');
|
|
|
+ }
|
|
|
|
|
|
// generate the search form
|
|
|
$form = drupal_get_form('tripal_pub_importer_setup_form', $pub_import_id, $action);
|
|
@@ -152,11 +148,13 @@ function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL)
|
|
|
$remote_db = array_key_exists('remote_db', $_SESSION['tripal_pub_import']) ? $_SESSION['tripal_pub_import']['remote_db'] : '';
|
|
|
$num_criteria = array_key_exists('num_criteria', $_SESSION['tripal_pub_import']) ? $_SESSION['tripal_pub_import']['num_criteria'] : '';
|
|
|
$days = array_key_exists('days', $_SESSION['tripal_pub_import']) ? $_SESSION['tripal_pub_import']['days'] : '';
|
|
|
+ $latestyear = array_key_exists('latestyear', $_SESSION['tripal_pub_import']) ? $_SESSION['tripal_pub_import']['latestyear'] : '';
|
|
|
|
|
|
$search_array = [];
|
|
|
$search_array['remote_db'] = $remote_db;
|
|
|
$search_array['num_criteria'] = $num_criteria;
|
|
|
$search_array['days'] = $days;
|
|
|
+ $search_array['latestyear'] = $latestyear;
|
|
|
for ($i = 1; $i <= $num_criteria; $i++) {
|
|
|
$search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'];
|
|
|
$search_array['criteria'][$i]['scope'] = $_SESSION['tripal_pub_import']['criteria'][$i]['scope'];
|
|
@@ -186,6 +184,10 @@ function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL)
|
|
|
if (array_key_exists('Publication Dbxref', $pub) and $pub['Publication Dbxref']) {
|
|
|
$raw_link = l('raw', 'admin/tripal/loaders/pub/raw/' . $pub['Publication Dbxref'], ['attributes' => ['target' => '_blank']]);
|
|
|
}
|
|
|
+ // indicate those that will be excluded by AGL year filtering parameters
|
|
|
+ if ((array_key_exists('passfilter', $pub)) and ($pub['passfilter'] == 0 )) {
|
|
|
+ $citation = '<span style="text-decoration: line-through;">' . $citation . '</span>';
|
|
|
+ }
|
|
|
$rows[] = [
|
|
|
number_format($i),
|
|
|
$citation,
|
|
@@ -279,12 +281,13 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
|
|
|
$criteria = NULL;
|
|
|
$remote_db = '';
|
|
|
$days = '';
|
|
|
+ $latestyear = '';
|
|
|
$disabled = '';
|
|
|
$do_contact = '';
|
|
|
$num_criteria = 1;
|
|
|
$loader_name = '';
|
|
|
|
|
|
- // if this is an edit the we are pulling an import object from the database
|
|
|
+ // if this is an edit then we are pulling an import object from the database
|
|
|
if ($action == "edit") {
|
|
|
$sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :pub_import_id";
|
|
|
$importer = db_query($sql, [':pub_import_id' => $pub_import_id])->fetchObject();
|
|
@@ -292,6 +295,7 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
|
|
|
$criteria = unserialize($importer->criteria);
|
|
|
$remote_db = $criteria['remote_db'];
|
|
|
$days = $criteria['days'];
|
|
|
+ $latestyear = $criteria['latestyear'];
|
|
|
$disabled = $criteria['disabled'];
|
|
|
$do_contact = $criteria['do_contact'];
|
|
|
$num_criteria = $criteria['num_criteria'];
|
|
@@ -302,6 +306,7 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
|
|
|
if (array_key_exists('tripal_pub_import', $_SESSION)) {
|
|
|
$remote_db = $_SESSION['tripal_pub_import']['remote_db'];
|
|
|
$days = $_SESSION['tripal_pub_import']['days'];
|
|
|
+ $latestyear = $_SESSION['tripal_pub_import']['latestyear'];
|
|
|
$disabled = $_SESSION['tripal_pub_import']['disabled'];
|
|
|
$do_contact = $_SESSION['tripal_pub_import']['do_contact'];
|
|
|
$num_criteria = $_SESSION['tripal_pub_import']['num_criteria'];
|
|
@@ -317,21 +322,23 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
|
|
|
// if we are re constructing the form from a failed validation or ajax callback
|
|
|
// then use the $form_state['values'] values
|
|
|
if (array_key_exists('values', $form_state)) {
|
|
|
- $remote_db = $form_state['values']['remote_db'];
|
|
|
- $days = $form_state['values']['days'];
|
|
|
- $disabled = $form_state['values']['disabled'];
|
|
|
- $do_contact = $form_state['values']['do_contact'];
|
|
|
- $num_criteria = $form_state['values']['num_criteria'];
|
|
|
- $loader_name = $form_state['values']['loader_name'];
|
|
|
+ $remote_db = $form_state['values']['remote_db'] ?? null;
|
|
|
+ $days = $form_state['values']['days'] ?? null;
|
|
|
+ $latestyear = $form_state['values']['latestyear'] ?? null;
|
|
|
+ $disabled = $form_state['values']['disabled'] ?? null;
|
|
|
+ $do_contact = $form_state['values']['do_contact'] ?? null;
|
|
|
+ $num_criteria = $form_state['values']['num_criteria'] ?? null;
|
|
|
+ $loader_name = $form_state['values']['loader_name'] ?? null;
|
|
|
}
|
|
|
// if we are re building the form from after submission (from ajax call) then
|
|
|
// the values are in the $form_state['input'] array
|
|
|
if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
|
|
|
- $remote_db = $form_state['input']['remote_db'];
|
|
|
- $days = $form_state['input']['days'];
|
|
|
- $disabled = $form_state['input']['disabled'];
|
|
|
- $do_contact = $form_state['input']['do_contact'];
|
|
|
- $loader_name = $form_state['input']['loader_name'];
|
|
|
+ $remote_db = $form_state['input']['remote_db'] ?? null;
|
|
|
+ $days = $form_state['input']['days'] ?? null;
|
|
|
+ $latestyear = $form_state['input']['latestyear'] ?? null;
|
|
|
+ $disabled = $form_state['input']['disabled'] ?? null;
|
|
|
+ $do_contact = $form_state['input']['do_contact'] ?? null;
|
|
|
+ $loader_name = $form_state['input']['loader_name'] ?? null;
|
|
|
|
|
|
// because the num_criteria is a value and not a visible or hidden form
|
|
|
// element it is not part of the ['input'] array, so we need to get it from the form
|
|
@@ -383,11 +390,7 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
|
|
|
if (!$remote_db) {
|
|
|
$remote_db = 'PMID';
|
|
|
}
|
|
|
- /**
|
|
|
- * Removing AGL option until we get it fixed
|
|
|
- * spf 6/22/2018
|
|
|
- */
|
|
|
- unset($remote_dbs['AGL']);
|
|
|
+
|
|
|
$form['themed_element']['remote_db'] = [
|
|
|
'#title' => t('Source'),
|
|
|
'#type' => 'select',
|
|
@@ -407,6 +410,14 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
|
|
|
'#default_value' => $days,
|
|
|
'#size' => 5,
|
|
|
];
|
|
|
+ // AGL only, this field will be removed for the pubmed loader
|
|
|
+ $form['themed_element']['latestyear'] = [
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#title' => t('Latest year of publication'),
|
|
|
+ '#description' => t('Filter returned publications for those that have been published no later than this year.'),
|
|
|
+ '#default_value' => $latestyear,
|
|
|
+ '#size' => 5,
|
|
|
+ ];
|
|
|
$form['themed_element']['disabled'] = [
|
|
|
'#type' => 'checkbox',
|
|
|
'#title' => t('Disabled'),
|
|
@@ -567,10 +578,14 @@ function tripal_pub_importer_setup_add_criteria_fields(&$form, &$form_state, $nu
|
|
|
|
|
|
// if we have criteria supplied from the database then use that as the initial defaults
|
|
|
if ($criteria) {
|
|
|
- $search_terms = $criteria['criteria'][$i]['search_terms'];
|
|
|
- $scope = $criteria['criteria'][$i]['scope'];
|
|
|
- $is_phrase = $criteria['criteria'][$i]['is_phrase'];
|
|
|
- $operation = $criteria['criteria'][$i]['operation'];
|
|
|
+ if (array_key_exists('criteria', $criteria)) {
|
|
|
+ if (array_key_exists($i, $criteria['criteria'])) {
|
|
|
+ $search_terms = $criteria['criteria'][$i]['search_terms'];
|
|
|
+ $scope = $criteria['criteria'][$i]['scope'];
|
|
|
+ $is_phrase = $criteria['criteria'][$i]['is_phrase'];
|
|
|
+ $operation = $criteria['criteria'][$i]['operation'];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// if the criteria comes the session
|
|
@@ -582,12 +597,12 @@ function tripal_pub_importer_setup_add_criteria_fields(&$form, &$form_state, $nu
|
|
|
}
|
|
|
|
|
|
// If the form_state has variables then use those. This happens when an error occurs on the form or the
|
|
|
- // form is resbumitted using AJAX
|
|
|
+ // form is resubmitted using AJAX
|
|
|
if (array_key_exists('values', $form_state)) {
|
|
|
- $search_terms = $form_state['values']["search_terms-$i"];
|
|
|
- $scope = $form_state['values']["scope-$i"];
|
|
|
- $is_phrase = $form_state['values']["is_phrase-$i"];
|
|
|
- $operation = $form_state['values']["operation-$i"];
|
|
|
+ $search_terms = $form_state['values']["search_terms-$i"] ?? null;
|
|
|
+ $scope = $form_state['values']["scope-$i"] ?? null;
|
|
|
+ $is_phrase = $form_state['values']["is_phrase-$i"] ?? null;
|
|
|
+ $operation = $form_state['values']["operation-$i"] ?? null;
|
|
|
}
|
|
|
$form['themed_element']['criteria'][$i]["scope-$i"] = [
|
|
|
'#type' => 'select',
|
|
@@ -707,6 +722,7 @@ function tripal_pub_importer_setup_form_validate($form, &$form_state) {
|
|
|
$num_criteria = $form_state['values']['num_criteria'];
|
|
|
$remote_db = $form_state['values']["remote_db"];
|
|
|
$days = trim($form_state['values']["days"]);
|
|
|
+ $latestyear = trim($form_state['values']["latestyear"]);
|
|
|
$disabled = $form_state['values']["disabled"];
|
|
|
$do_contact = $form_state['values']["do_contact"];
|
|
|
$loader_name = trim($form_state['values']["loader_name"]);
|
|
@@ -732,6 +748,10 @@ function tripal_pub_importer_setup_form_validate($form, &$form_state) {
|
|
|
form_set_error("days", "Please enter a numeric, non decimal value, for the number of days.");
|
|
|
$_SESSION['tripal_pub_import']['perform_search'] = 0;
|
|
|
}
|
|
|
+ if ($latestyear and !is_numeric($latestyear) or preg_match('/\./', $latestyear)) {
|
|
|
+ form_set_error("latestyear", "Please enter a numeric, non decimal value, for latestyear.");
|
|
|
+ $_SESSION['tripal_pub_import']['perform_search'] = 0;
|
|
|
+ }
|
|
|
// allow the selected remote database to validate any changes to the form if needed
|
|
|
$callback = "tripal_pub_remote_validate_form_$remote_db";
|
|
|
$form = call_user_func($callback, $form, $form_state);
|
|
@@ -748,6 +768,7 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
|
|
|
$num_criteria = $form_state['values']['num_criteria'];
|
|
|
$remote_db = $form_state['values']["remote_db"];
|
|
|
$days = trim($form_state['values']["days"]);
|
|
|
+ $latestyear = trim($form_state['values']["latestyear"]);
|
|
|
$loader_name = trim($form_state['values']["loader_name"]);
|
|
|
$disabled = $form_state['values']["disabled"];
|
|
|
$do_contact = $form_state['values']["do_contact"];
|
|
@@ -755,6 +776,7 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
|
|
|
// set the session variables
|
|
|
$_SESSION['tripal_pub_import']['remote_db'] = $remote_db;
|
|
|
$_SESSION['tripal_pub_import']['days'] = $days;
|
|
|
+ $_SESSION['tripal_pub_import']['latestyear'] = $latestyear;
|
|
|
$_SESSION['tripal_pub_import']['num_criteria'] = $num_criteria;
|
|
|
$_SESSION['tripal_pub_import']['loader_name'] = $loader_name;
|
|
|
$_SESSION['tripal_pub_import']['disabled'] = $disabled;
|
|
@@ -861,6 +883,10 @@ function theme_tripal_pub_importer_setup_form_elements($variables) {
|
|
|
$markup .= '</div>';
|
|
|
$markup .= '<div id="pub-search-form-row1" style="clear:both">';
|
|
|
$markup .= ' <div id="pub-search-form-row1-col1">' . drupal_render($form['days']) . '</div>';
|
|
|
+ // latest year field is used ony for AGL importer
|
|
|
+ if ($variables['form']['remote_db']['#value'] == 'AGL') {
|
|
|
+ $markup .= ' <div id="pub-search-form-row1-col2">' . drupal_render($form['latestyear']) . '</div>';
|
|
|
+ }
|
|
|
$markup .= '</div>';
|
|
|
$markup .= '<div id="pub-search-form-row2">' . drupal_render($form['disabled']) . '</div>';
|
|
|
$markup .= '<div id="pub-search-form-row3">' . drupal_render($form['do_contact']) . '</div>';
|
|
@@ -996,46 +1022,53 @@ function tripal_pub_add_publications($pubs, $do_contact, $update = FALSE, $job =
|
|
|
$memory = number_format(memory_get_usage()) . " bytes";
|
|
|
print "Processing $i of $total_pubs. Memory usage: $memory.\r";
|
|
|
|
|
|
- // add the publication to Chado
|
|
|
- $action = '';
|
|
|
- $pub_id = tripal_pub_add_publication($pub, $action, $do_contact, $update, $job);
|
|
|
- if ($pub_id) {
|
|
|
- // add the publication cross reference (e.g. to PubMed)
|
|
|
- if ($pub_id and $pub['Publication Dbxref']) {
|
|
|
- $dbxref = [];
|
|
|
- if (preg_match('/^(.*?):(.*?)$/', trim($pub['Publication Dbxref']), $matches)) {
|
|
|
- $dbxref['db_name'] = $matches[1];
|
|
|
- $dbxref['accession'] = $matches[2];
|
|
|
- }
|
|
|
- else {
|
|
|
- tripal_report_error($message_type, TRIPAL_ERROR,
|
|
|
- 'Unable to extract the dbxref to be associated with the publication (pub ID=@pub_id) from @dbxref. This reference should be [database-name]:[accession]',
|
|
|
- [
|
|
|
- '@pub_id' => $pub_id,
|
|
|
- '@dbxref' => $pub['Publication Dbxref'],
|
|
|
- $message_opts,
|
|
|
- ]
|
|
|
- );
|
|
|
+ // implementation of year limits for AGL uses a 'passfilter' flag
|
|
|
+ if ((!array_key_exists('passfilter', $pub)) or ($pub['passfilter'] == 1 )) {
|
|
|
+
|
|
|
+ // add the publication to Chado
|
|
|
+ $action = '';
|
|
|
+ $pub_id = tripal_pub_add_publication($pub, $action, $do_contact, $update, $job);
|
|
|
+ // $pub_id will be null if publication already existed
|
|
|
+ if ($pub_id) {
|
|
|
+ // add the publication cross reference (e.g. to PubMed)
|
|
|
+ if ($pub_id and $pub['Publication Dbxref']) {
|
|
|
+ $dbxref = [];
|
|
|
+ if (preg_match('/^(.*?):(.*?)$/', trim($pub['Publication Dbxref']), $matches)) {
|
|
|
+ $dbxref['db_name'] = $matches[1];
|
|
|
+ $dbxref['accession'] = $matches[2];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ tripal_report_error($message_type, TRIPAL_ERROR,
|
|
|
+ 'Unable to extract the dbxref to be associated with the publication (pub ID=@pub_id) from @dbxref. This reference should be [database-name]:[accession]',
|
|
|
+ [
|
|
|
+ '@pub_id' => $pub_id,
|
|
|
+ '@dbxref' => $pub['Publication Dbxref'],
|
|
|
+ $message_opts,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ $pub_dbxref = tripal_associate_dbxref('pub', $pub_id, $dbxref);
|
|
|
}
|
|
|
- $pub_dbxref = tripal_associate_dbxref('pub', $pub_id, $dbxref);
|
|
|
+ $pub['pub_id'] = $pub_id;
|
|
|
}
|
|
|
- $pub['pub_id'] = $pub_id;
|
|
|
- }
|
|
|
|
|
|
- switch ($action) {
|
|
|
- case 'error':
|
|
|
- $report['error'][] = $pub['Citation'];
|
|
|
- break;
|
|
|
- case 'inserted':
|
|
|
- $report['inserted'][] = $pub['Citation'];
|
|
|
- break;
|
|
|
- case 'updated':
|
|
|
- $report['updated'][] = $pub['Citation'];
|
|
|
- break;
|
|
|
- case 'skipped':
|
|
|
- $report['skipped'][] = $pub['Citation'];
|
|
|
- break;
|
|
|
+ switch ($action) {
|
|
|
+ case 'error':
|
|
|
+ $report['error'][] = $pub['Citation'];
|
|
|
+ break;
|
|
|
+ case 'inserted':
|
|
|
+ $report['inserted'][] = $pub['Citation'];
|
|
|
+ break;
|
|
|
+ case 'updated':
|
|
|
+ $report['updated'][] = $pub['Citation'];
|
|
|
+ break;
|
|
|
+ case 'skipped':
|
|
|
+ $report['skipped'][] = $pub['Citation'];
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ // else pub failed AGL year filter
|
|
|
+ else { $report['skipped'][] = $pub['Citation']; }
|
|
|
$i++;
|
|
|
}
|
|
|
return $report;
|
|
@@ -1081,7 +1114,6 @@ function tripal_pub_add_publications($pubs, $do_contact, $update = FALSE, $job =
|
|
|
*/
|
|
|
function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE, $update_if_exists = FALSE, $job = NULL) {
|
|
|
$pub_id = 0;
|
|
|
-
|
|
|
// These are options for the tripal_report_error function. We do not
|
|
|
// want to log messages to the watchdog except for errors and to the job and
|
|
|
// to the terminal
|
|
@@ -1250,6 +1282,11 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ // Filtering flag for AGL, not a property to add here
|
|
|
+ if ($key == 'passfilter') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
// Since we're not updating the 'Publication Dbxref' on an update
|
|
|
// skip this property.
|
|
|
if ($update_if_exists and $key == 'Publication Dbxref') {
|