Browse Source

Fixed bug in getting publication year from AGL importer

spficklin 12 years ago
parent
commit
85bb3e871c

+ 0 - 4
tripal_pub/includes/importers/AGL.inc

@@ -661,26 +661,22 @@ function tripal_pub_AGL_parse_pubxml($pub_xml) {
               case 'g':
                 $matches = array();
                 if (preg_match('/^(\d\d\d\d)/', $value, $matches)) {
-                  $pub['Year'] = $matches[1];
                   $pub['Publication Date'] = $matches[1];
                 }
                 elseif (preg_match('/(.*?)(\.|\s+)\s*(\d+),\s(\d\d\d\d)/', $value, $matches)) {
                   $year = $matches[4];
                   $month = $matches[1];
                   $day = $matches[3];
-                  $pub['Year'] = $year;
                   $pub['Publication Date'] = "$year $month $day"; 
                 }
                 elseif (preg_match('/\((.*?)(\.|\s+)(\d\d\d\d)\)/', $value, $matches)) {
                   $year = $matches[3];
                   $month = $matches[1];
-                  $pub['Year'] = $year;
                   $pub['Publication Date'] = "$year $month"; 
                 }
                 elseif (preg_match('/^(.*?) (\d\d\d\d)/', $value, $matches)) {
                   $year = $matches[2];
                   $month = $matches[1];
-                  $pub['Year'] = $year;
                   $pub['Publication Date'] = "$year $month"; 
                 }
                 if (preg_match('/v\. (.*?)(,|\s+)/', $value, $matches)) {

+ 6 - 5
tripal_pub/includes/pub_form.inc

@@ -189,8 +189,9 @@ function chado_pub_validate($node) {
   }
 
   // make sure the year is four digits
-  if(!preg_match('/^\d\d\d\d$/', $pyear)){
-    form_set_error('pyear', t('The publication year should be a 4 digit year.'), array());
+  if(!preg_match('/^\d{4}$/', $pyear)){
+    form_set_error('pyear', t('The publication year should be a 4 digit year.'));
+    return;
   }
   
   // get the type of publication
@@ -198,7 +199,7 @@ function chado_pub_validate($node) {
   $options = array('statement_name' => 'sel_pub_ty');
   $cvterm = tripal_core_chado_select('cvterm', array('name'), $values, $options);
   if (count($cvterm) == 0) {
-    form_set_error('type_id', t('Invalided publication type.'), array());
+    form_set_error('type_id', t('Invalided publication type.'));
     return;
   }
 
@@ -206,7 +207,7 @@ function chado_pub_validate($node) {
   if (!$pub_id) {
     $results = tripal_pub_get_pubs_by_title_type_pyear($title, $cvterm[0]->name, $pyear);   
     if (count($results) > 0) {
-      form_set_error('pyear',t('A publication with this title, type and publication year, already exists.  Cannot add this publication'), array());
+      form_set_error('pyear',t('A publication with this title, type and publication year, already exists.  Cannot add this publication'));
     }
   }
   
@@ -233,7 +234,7 @@ function chado_pub_validate($node) {
         }
       }         
       if (count($results) > 0) {
-        form_set_error('pyear',t('A publication with this title and publication year, already exists.  Cannot update this publication'), array());       
+        form_set_error('pyear',t('A publication with this title and publication year, already exists.  Cannot update this publication'));       
       }
     }
   } 

+ 2 - 0
tripal_pub/includes/pub_sync.inc

@@ -86,7 +86,9 @@ function tripal_pub_sync_pub($pub) {
       return FALSE;
     }
   }
+  // if there are form errors then we need to reset the form errors cache, print a message and return
   else {
+    form_set_error(NULL,'',TRUE);
     print "ERROR: Unable to create publication node: " . $pub->title . "\n" . print_r($errors, TRUE) . "\n";
     return FALSE;
   }