Browse Source

Created tripal_cvterm_mapping table when installing tripal_chado. Fixed function tripal_chado_map_cvterms() to populate the table

Chun-Huai Cheng 8 years ago
parent
commit
b4a74cc2fa

+ 10 - 45
tripal_chado/includes/tripal_chado.mapping.inc

@@ -1,44 +1,5 @@
 <?php
 
-/**
- *
- */
-function tripal_chado_tripal_cvterm_mapping_schema() {
-
-  $schema = array (
-    'table' => 'tripal_cvterm_mapping',
-    'fields' => array (
-      'mapping_id' => array(
-        'type' => 'serial',
-        'not null' => TRUE
-      ),
-      'cvterm_id' => array (
-        'type' => 'int',
-        'not null' => TRUE
-      ),
-      'chado_table' => array (
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE
-      ),
-      'chado_field' => array (
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE
-      ),
-    ),
-    'primary key' => array (
-      0 => 'mapping_id'
-    ),
-    'indexes' => array(
-      'tripal_cvterm2table_idx1' => array('cvterm_id'),
-      'tripal_cvterm2table_idx2' => array('chado_table'),
-      'tripal_cvterm2table_idx3' => array('chado_table', 'chado_field'),
-    ),
-  );
-  return $schema;
-}
-
 /**
  * This function populates the Tripal entity tables using existing
  * data in the database.
@@ -50,7 +11,7 @@ function tripal_chado_map_cvterms() {
 
   // Perform this action in a transaction
   $transaction = db_transaction();
-  print "\nNOTE: Populating of tripal entity tables is performed using a database transaction. \n" .
+  print "\nNOTE: Populating of tripal_cvterm_mapping table is performed using a database transaction. \n" .
       "If the load fails or is terminated prematurely then the entire set of \n" .
       "insertions/updates is rolled back and will not be found in the database\n\n";
   try {
@@ -84,12 +45,16 @@ function tripal_chado_map_cvterms() {
           // it doesn't already exist.
           $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
 
-          $values = array(
-            'cvterm_id' => $cvterm->cvterm_id,
-            'chado_table' => $tablename,
-            'chado_field' => $remote_id
-          );
           // TODO insert records into the tripal_cvterm_mapping table.
+          db_insert('tripal_cvterm_mapping')
+            ->fields(
+              array(
+                'cvterm_id' => $cvterm->cvterm_id,
+                'chado_table' => $tablename,
+                'chado_field' => $remote_id
+              )
+            )
+            ->execute();
         }
       }
     }

+ 42 - 1
tripal_chado/tripal_chado.install

@@ -215,7 +215,8 @@ function tripal_chado_schema() {
     }
   }
 
-
+  // Map cvterm usage to chado tables
+  $schema['tripal_cvterm_mapping'] = tripal_chado_tripal_cvterm_mapping_schema();
 
   return $schema;
 }
@@ -664,3 +665,43 @@ function tripal_chado_chado_entity_schema() {
   );
   return $schema;
 }
+
+/**
+ * Tripal cvterm mapping schema
+ * Map cvterms to chado tables that use them
+ */
+function tripal_chado_tripal_cvterm_mapping_schema() {
+
+  $schema = array (
+    'table' => 'tripal_cvterm_mapping',
+    'fields' => array (
+      'mapping_id' => array(
+        'type' => 'serial',
+        'not null' => TRUE
+      ),
+      'cvterm_id' => array (
+        'type' => 'int',
+        'not null' => TRUE
+      ),
+      'chado_table' => array (
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE
+      ),
+      'chado_field' => array (
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE
+      ),
+    ),
+    'primary key' => array (
+      0 => 'mapping_id'
+    ),
+    'indexes' => array(
+      'tripal_cvterm2table_idx1' => array('cvterm_id'),
+      'tripal_cvterm2table_idx2' => array('chado_table'),
+      'tripal_cvterm2table_idx3' => array('chado_table', 'chado_field'),
+    ),
+  );
+  return $schema;
+}

+ 1 - 1
tripal_chado/tripal_chado.module

@@ -73,7 +73,7 @@ function tripal_chado_init() {
       // Check to see if the Chado and Drupal have been prepared
       if (!variable_get('tripal_chado_is_prepared', FALSE)) {
         drupal_set_message('Chado is installed but Tripal has not yet prepared Drupal and Chado. Please ' .
-            l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/chado_prepare') .
+            l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/prepare') .
             ' before continuing.', 'warning');
       }
     }