Browse Source

Fixed bug with preparing Chado multiple times. Fixed bug with setting the field term name

Stephen Ficklin 8 years ago
parent
commit
c8b40b4f84

+ 2 - 1
tripal/includes/TripalFields/TripalField.inc

@@ -135,7 +135,7 @@ class TripalField {
    */
   public static function info() {
     $class = get_called_class();
-    return array(
+    $info = array(
       'label' => $class::$default_label,
       'description' => $class::$default_description,
       'settings' => $class::$default_settings,
@@ -144,6 +144,7 @@ class TripalField {
       'default_formatter' => $class::$default_formatter,
       'no_ui' => $class::$no_ui,
     );
+    return $info;
   }
 
 

+ 23 - 7
tripal/includes/tripal.fields.inc

@@ -34,16 +34,32 @@ function tripal_field_info() {
  * Implements hook_info_alter().
  */
 function tripal_field_info_alter(&$info) {
-  // Make sure all fields have a 'tripal_term' setting so we can map
+  // Make sure all fields have a term setting so we can map
   // all fields to a vocabulary term for the semantic web.
   foreach ($info as $field_name => $details) {
-    if(array_key_exists('settings', $details)) {
-      if (!array_key_exists('tripal_term', $details['settings'])) {
-        $info[$field_name]['settings']['tripal_term'] = '';
+    if(array_key_exists('instance_settings', $details)) {
+      if (!array_key_exists('term_vocabulary', $details['instance_settings'])) {
+        $info[$field_name]['instance_settings']['term_vocabulary'] = '';
+      }
+      if (!array_key_exists('term_name', $details['instance_settings'])) {
+        $info[$field_name]['instance_settings']['term_name'] = '';
+      }
+      if (!array_key_exists('term_accession', $details['instance_settings'])) {
+        $info[$field_name]['instance_settings']['term_accession'] = '';
+      }
+      if (!array_key_exists('term_fixed', $details['instance_settings'])) {
+        $info[$field_name]['instance_settings']['term_fixed'] = FALSE;
+      }
+      if (!array_key_exists('auto_attach', $details['instance_settings'])) {
+        $info[$field_name]['instance_settings']['auto_attach'] = TRUE;
       }
     }
     else {
-      $info[$field_name]['settings']['tripal_term'] = '';
+      $info[$field_name]['instance_settings']['term_vocabulary'] = '';
+      $info[$field_name]['instance_settings']['term_name'] = '';
+      $info[$field_name]['instance_settings']['term_accession'] = '';
+      $info[$field_name]['instance_settings']['term_fixed'] = FALSE;
+      $info[$field_name]['instance_settings']['auto_attach'] = TRUE;
     }
   }
 }
@@ -414,6 +430,7 @@ function tripal_field_instance_settings_form_alter_process($element, &$form_stat
     $term_name = $instance['settings']['term_name'];
     $term = tripal_get_term_details($vocabulary, $accession);
   }
+  dpm($instance);
 
   // Construct a table for the vocabulary information.
   $headers = array();
@@ -453,8 +470,7 @@ function tripal_field_instance_settings_form_alter_process($element, &$form_stat
   $table = array(
     'header' => $headers,
     'rows' => $rows,
-    'attributes' => array(
-    ),
+    'attributes' => array(),
     'sticky' => FALSE,
     'caption' => '',
     'colgroups' => array(),

+ 3 - 0
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -428,6 +428,9 @@ function tripal_chado_field_storage_query($query) {
     return $result;
   }
   $bundle = tripal_load_bundle_entity(array('name' => $query->entityConditions['bundle']));
+  if (!$bundle) {
+    return;
+  }
   $data_table = $bundle->data_table;
   $type_column = $bundle->type_column;
   $type_id = $bundle->type_id;

+ 5 - 0
tripal_chado/includes/tripal_chado.fields.inc

@@ -1135,6 +1135,11 @@ function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bund
       'label' => 'Organism Image',
       'description' => 'An image for the organism',
       'required' => FALSE,
+      'settings' => array(
+        'term_vocabulary' => 'data',
+        'term_name' => 'Image',
+        'term_accession' => '2968',
+      ),
       'display' => array(
         'default' => array(
           'label' => 'hidden',

+ 42 - 14
tripal_chado/includes/tripal_chado.setup.inc

@@ -207,8 +207,12 @@ function tripal_chado_prepare_chado() {
        'data_table' => 'organism',
      )
     );
-    if (!tripal_create_bundle($args, $error)) {
-      throw new Exception($error['!message']);
+    $term = tripal_load_term_entity(array('vocabulary' => 'OBI', 'accession' => '0100026'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
     }
 
     // Create the 'Analysis' entity type. This uses the local:analysis term.
@@ -221,8 +225,12 @@ function tripal_chado_prepare_chado() {
         'data_table' => 'analysis',
       )
     );
-    if (!tripal_create_bundle($args, $error)) {
-      throw new Exception($error['!message']);
+    $term = tripal_load_term_entity(array('vocabulary' => 'local', 'accession' => 'analysis'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
     }
 
     // Create the 'Project' entity type. This uses the local:project term.
@@ -235,8 +243,12 @@ function tripal_chado_prepare_chado() {
         'data_table' => 'project',
       )
     );
-    if (!tripal_create_bundle($args, $error)) {
-      throw new Exception($error['!message']);
+    $term = tripal_load_term_entity(array('vocabulary' => 'local', 'accession' => 'project'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
     }
 
     // Create the 'Map' entity type. This uses the local:project term.
@@ -249,8 +261,12 @@ function tripal_chado_prepare_chado() {
         'data_table' => 'featuremap',
       )
     );
-    if (!tripal_create_bundle($args, $error)) {
-      throw new Exception($error['!message']);
+    $term = tripal_load_term_entity(array('vocabulary' => 'data', 'accession' => '1274'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
     }
 
     // Create the 'Publication' entity type.
@@ -263,8 +279,12 @@ function tripal_chado_prepare_chado() {
         'data_table' => 'pub',
       )
     );
-    if (!tripal_create_bundle($args, $error)) {
-      throw new Exception($error['!message']);
+    $term = tripal_load_term_entity(array('vocabulary' => 'TPUB', 'accession' => '0000002'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
     }
 
     // Create the 'Gene' entity type.
@@ -278,8 +298,12 @@ function tripal_chado_prepare_chado() {
         'type_column' => 'type_id',
       )
     );
-    if (!tripal_create_bundle($args, $error)) {
-      throw new Exception($error['!message']);
+    $term = tripal_load_term_entity(array('vocabulary' => 'SO', 'accession' => '0000704'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
     }
 
     // Create the 'mRNA' entity type.
@@ -293,8 +317,12 @@ function tripal_chado_prepare_chado() {
         'type_column' => 'type_id',
       )
     );
-    if (!tripal_create_bundle($args, $error)) {
-      throw new Exception($error['!message']);
+    $term = tripal_load_term_entity(array('vocabulary' => 'SO', 'accession' => '0000234'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
     }
 
     // Set a variable to indicate the site is prepared.