Explorar o código

Fixed bug in syncing pubs

Stephen Ficklin %!s(int64=9) %!d(string=hai) anos
pai
achega
6bcdd980e1

+ 1 - 0
tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -8,6 +8,7 @@
 
 /**
  * Implements hook_node_info().
+ *
  * Provide information to drupal about the node types that we're creating
  * in this module
  *

+ 3 - 0
tripal_core/api/tripal_core.chado_nodes.api.inc

@@ -788,6 +788,9 @@ function chado_node_sync_records($base_table, $max_sync = FALSE,
   if (!$linking_table) {
     $linking_table = 'chado_' . $base_table;
   }
+  if (!$node_type) {
+    $node_type = 'chado_' . $base_table;
+  }
 
   print "\nSync'ing $base_table records.  ";
 

+ 26 - 26
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -1,34 +1,37 @@
 <?php
 /**
  * @file
- * Implements the pub node content type
+ * Implements Drupal Node hooks to create the chado_analysis node content type.
+ *
+ * @ingroup tripal_pub
  */
 
 /**
  * Implements hook_node_info().
  *
+ * Provide information to drupal about the node types that we're creating
+ * in this module
+ *
  * @ingroup tripal_pub
  */
 function tripal_pub_node_info() {
-
-  return array(
-    'chado_pub' => array(
-      'name'        => t('Publication'),
-      'base'        => 'chado_pub',
-      'description' => t('A publication from the Chado database'),
-      'has_title'   => TRUE,
-      'locked'      => TRUE,
-      'chado_node_api' => array(
-        'base_table' => 'pub',
-        'hook_prefix' => 'chado_pub',
-        'record_type_title' => array(
-          'singular' => t('Publication'),
-          'plural' => t('Publications')
-        ),
-        'sync_filters' => array(
-          'type_id' => FALSE,
-          'organism_id' => FALSE
-        ),
+  $nodes = array();
+  $nodes['chado_pub'] = array(
+    'name'        => t('Publication'),
+    'base'        => 'chado_pub',
+    'description' => t('A publication from the Chado database'),
+    'has_title'   => TRUE,
+    'locked'      => TRUE,
+    'chado_node_api' => array(
+      'base_table' => 'pub',
+      'hook_prefix' => 'chado_pub',
+      'record_type_title' => array(
+        'singular' => t('Publication'),
+        'plural' => t('Publications')
+      ),
+      'sync_filters' => array(
+        'type_id' => FALSE,
+        'organism_id' => FALSE,
       ),
     ),
   );
@@ -380,16 +383,13 @@ function chado_pub_validate($node, $form, &$form_state) {
     if ($prop_type[0]->name == 'Conference Name' or
         $prop_type[0]->name == 'Journal Name' or
         $prop_type[0]->name == 'Series Name') {
-      $v = array_values($prop_values);
-      $series_name = $v[0];
+      $series_name = array_values($prop_values)[0];
     }
     if ($prop_type[0]->name == 'Citation') {
-      $v = array_values($prop_values);
-      $uniquename = $v[0];
+      $uniquename = array_values($prop_values)[0];
     }
     if (count($prop_values) == 1) {
-      $v = array_values($prop_values);
-      $pub[$prop_type[0]->name] = $v[0];
+      $pub[$prop_type[0]->name] = array_values($prop_values)[0];
     }
     else {
       $pub[$prop_type[0]->name] = $prop_values;

+ 43 - 12
tripal_pub/includes/tripal_pub.pub_citation.inc

@@ -161,7 +161,7 @@ function tripal_pub_create_citation($pub) {
   // Therefore, we need to select the type that makes most sense for
   // construction of the citation. Here we'll iterate through them all
   // and select the one that matches best.
-  if(is_array($pub['Publication Type'])) {
+  if (is_array($pub['Publication Type'])) {
     foreach ($pub['Publication Type'] as $ptype) {
       if ($ptype == 'Journal Article' ) {
         $pub_type = $ptype;
@@ -193,16 +193,10 @@ function tripal_pub_create_citation($pub) {
         // we prefer that type
       }
     }
+    // If we don't have a recognized publication type, then just use the
+    // first one in the list.
     if (!$pub_type) {
-      tripal_report_error('tripal_pub', TRIPAL_ERROR,
-        "Cannot generate citation for publication type: %types.\nTitle: %title.\nDbxref: %dbxref",
-        array(
-          '%types' => print_r($pub['Publication Type'], TRUE),
-          '%title' => $pub['Title'],
-          '%dbxref' => $pub['Publication Dbxref'],
-        )
-      );
-      return FALSE;
+      $pub_type = $pub['Publication Type'][0];
     }
   }
   else {
@@ -363,9 +357,9 @@ function tripal_pub_create_citation($pub) {
     }
     $citation .= '.';
   }
-  //----------------------
+  //-----------------------
   // Conference Proceedings
-  //----------------------
+  //-----------------------
   elseif ($pub_type == 'Conference Proceedings') {
     if (array_key_exists('Authors', $pub)) {
       $citation = $pub['Authors'] . '. ';
@@ -404,6 +398,43 @@ function tripal_pub_create_citation($pub) {
     }
     $citation .= '.';
   }
+  //-----------------------
+  // Default
+  //-----------------------
+  else {
+    if (array_key_exists('Authors', $pub)) {
+      $citation = $pub['Authors'] . '. ';
+    }
+    $citation .= $pub['Title'] .  '. ';
+    if (array_key_exists('Series Name', $pub)) {
+      $citation .= $pub['Series Name'] . '. ';
+    }
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
+      $citation .= $pub['Series Abbreviation'] . '. ';
+    }
+    if (array_key_exists('Publication Date', $pub)) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif (array_key_exists('Year', $pub)) {
+      $citation .= $pub['Year'];
+    }
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
+      $citation .= '; ';
+    }
+    if (array_key_exists('Volume', $pub)) {
+      $citation .= $pub['Volume'];
+    }
+    if (array_key_exists('Issue', $pub)) {
+      $citation .= '(' . $pub['Issue'] . ')';
+    }
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
+        $citation .= ':';
+      }
+      $citation .= $pub['Pages'];
+    }
+    $citation .= '.';
+  }
 
   return $citation;
 }

+ 8 - 3
tripal_pub/tripal_pub.drush.inc

@@ -31,7 +31,7 @@ function tripal_pub_drush_help($command) {
  */
 function tripal_pub_drush_command() {
   $items = array();
-  
+
   $items['trp-import-pubs'] = array(
     'description' => dt('Imports publications from remote databases using saved configuration settings.'),
     'options' => array(
@@ -39,6 +39,9 @@ function tripal_pub_drush_command() {
       'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642).'),
       'report' => dt("Set to the email address of the recipient who should receive an HTML report of the publications that have been added."),
       'update' => dt("Set to 'Y' to update existing pubs.  By default only new pubs are inserted."),
+      'username' => array(
+        'description' => dt('The Drupal user name for which the job should be run.  The permissions for this user will be used.'),
+      ),
     ),
     'examples' => array(
       'Standard example' => 'drush tripal-pubs-import',
@@ -60,7 +63,7 @@ function tripal_pub_drush_command() {
       'Update all records for a single database' => 'drush tripal-pubs-update --db=PMID'
     ),
   );
-  
+
   // Deprecated commands
   $items['tripal-pubs-import'] = array(
     'description' => dt('DEPRECATED. Please see: trp-import-pubs.'),
@@ -106,6 +109,8 @@ function drush_tripal_pub_trp_import_pubs() {
   $dbxref = drush_get_option('dbxref');
   $do_report = drush_get_option('report');
   $update = drush_get_option('update');
+  $uname = drush_get_option('username');
+  drush_tripal_core_set_user($uname);
 
   if($update == 'Y') {
     $update = TRUE;
@@ -154,6 +159,6 @@ function drush_tripal_pub_trp_update_pubs() {
 function drush_tripal_pub_tripal_pubs_update() {
   drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
       "continue to work but please consider using the 'trp-update-pubs' command.\n\n");
-  
+
   drush_tripal_pub_trp_update_pubs();
 }