Przeglądaj źródła

create dbxref accession if not present

bradford.condon 6 lat temu
rodzic
commit
7c06ef26d3

+ 20 - 2
tripal_chado/api/modules/tripal_chado.phylotree.api.inc

@@ -198,12 +198,30 @@ function chado_validate_phylotree($val_type, &$options, &$errors, &$warnings) {
       ),
     );
     $dbxref = chado_generate_var('dbxref', $values);
+
     if (!$dbxref) {
-      $errors['dbxref'] = t('The dbxref provided does not exist in the database: %dbxref.', array('%dbxref' => $dbxref));
-      return FALSE;
+
+      $db = chado_generate_var('db', array( 'name' => $db_name));
+
+      if (!$db){
+              $errors['dbxref'] = t('
+              dbxref could not be created for db: %dbxref.', array('%dbxref' => $dbxref));
+              return FALSE;
+      }
+    $dbxref =  chado_insert_record('dbxref', $values);
+
+    if (!$dbxref){
+            $errors['dbxref'] = t('
+            dbxref could not be created for db: %dbxref.', array('%dbxref' => $dbxref));
+            return FALSE;
     }
+  }
+  if (is_array($dbxref)){
+    $options['dbxref_id'] = $dbxref['dbxref_id'];
+    }else {
     $options['dbxref_id'] = $dbxref->dbxref_id;
   }
+  }
 
   // Make sure the tree name is unique.
   if (array_key_exists('name', $options) and $options['name']) {