Browse Source

Fixed duplicate function declarations. Changed pub migration to only one type (i.e. Publiction).Working on organism image migration

Chun-Huai Cheng 8 years ago
parent
commit
45e500f6b6

+ 6 - 4
legacy/tripal_analysis/tripal_analysis.install

@@ -81,7 +81,8 @@ function tripal_analysis_uninstall() {
  *
  * @ingroup tripal_analysis
  */
-function tripal_analysis_create_analysisfeatureprop() {
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_analysis_create_analysisfeatureprop() {
 
   // Create analysisfeatureprop table in chado.  This is needed for Chado
   // version 1.11, the table exists in Chado 1.2.
@@ -100,7 +101,7 @@ function tripal_analysis_create_analysisfeatureprop() {
     ";
     chado_query($sql);
   }
-}
+} */
 
 /**
  * Add cvs related to analyses
@@ -236,7 +237,8 @@ function tripal_analysis_schema() {
  *
  * @ingroup tripal_analysis
  */
-function tripal_analysis_add_mview_analysis_organism() {
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_analysis_add_mview_analysis_organism() {
   $view_name = 'analysis_organism';
   $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.');
 
@@ -289,4 +291,4 @@ function tripal_analysis_add_mview_analysis_organism() {
 
   // add the view
   tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment);
-}
+} */

+ 3 - 2
legacy/tripal_contact/tripal_contact.install

@@ -172,7 +172,8 @@ function tripal_contact_schema() {
  *
  * @ingroup tripal_contact
  */
-function tripal_contact_add_custom_tables(){
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_contact_add_custom_tables(){
   $schema = array (
     'table' => 'contactprop',
     'fields' => array (
@@ -232,4 +233,4 @@ function tripal_contact_add_custom_tables(){
     ),
   );
   chado_create_custom_table('contactprop', $schema, TRUE);
-}
+} */

+ 12 - 9
legacy/tripal_feature/tripal_feature.install

@@ -82,8 +82,8 @@ function tripal_feature_install() {
 function tripal_feature_uninstall() {
 
 }
-
-function tripal_feature_add_tripal_gff_temp_table() {
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_feature_add_tripal_gff_temp_table() {
   $schema = array(
     'table' => 'tripal_gff_temp',
     'fields' => array(
@@ -116,12 +116,13 @@ function tripal_feature_add_tripal_gff_temp_table() {
     ),
   );
   chado_create_custom_table('tripal_gff_temp', $schema, TRUE);
-}
+} */
 
 /**
  *
  */
-function tripal_feature_add_tripal_gffcds_temp_table($skip_recreate = TRUE) {
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_feature_add_tripal_gffcds_temp_table($skip_recreate = TRUE) {
   $schema = array(
     'table' => 'tripal_gffcds_temp',
     'fields' => array(
@@ -156,12 +157,13 @@ function tripal_feature_add_tripal_gffcds_temp_table($skip_recreate = TRUE) {
     ),
   );
   chado_create_custom_table('tripal_gffcds_temp', $schema, $skip_recreate);
-}
+} */
 
 /**
  *
  */
-function tripal_feature_add_tripal_gffprotein_temp_table() {
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_feature_add_tripal_gffprotein_temp_table() {
   $schema = array(
     'table' => 'tripal_gffprotein_temp',
     'fields' => array(
@@ -191,7 +193,7 @@ function tripal_feature_add_tripal_gffprotein_temp_table() {
     ),
   );
   chado_create_custom_table('tripal_gffprotein_temp', $schema, TRUE);
-}
+} */
 
 /**
  * Implementation of hook_schema().
@@ -243,7 +245,8 @@ function tripal_feature_schema() {
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_add_organism_count_mview() {
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_feature_add_organism_count_mview() {
   $view_name = 'organism_feature_count';
   $comment = 'Stores the type and number of features per organism';
 
@@ -306,7 +309,7 @@ function tripal_feature_add_organism_count_mview() {
   ";
 
   tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
-}
+} */
 /**
  * Add cvs related to publications
  *

+ 3 - 2
legacy/tripal_featuremap/tripal_featuremap.install

@@ -309,7 +309,8 @@ function tripal_featuremap_add_cvterms() {
  *
  * @ingroup tripal_featuremap
  */
-function tripal_featuremap_add_custom_tables(){
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_featuremap_add_custom_tables(){
   // add the featuremaprop table to Chado
   $schema = array (
     'table' => 'featuremapprop',
@@ -482,4 +483,4 @@ function tripal_featuremap_add_custom_tables(){
     ),
   );
   chado_create_custom_table('featureposprop', $schema, TRUE);
-}
+} */

+ 3 - 2
legacy/tripal_pub/tripal_pub.install

@@ -171,7 +171,8 @@ function tripal_pub_schema() {
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_add_custom_tables() {
+// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+/* function tripal_pub_add_custom_tables() {
   $schema = array (
     'table' => 'pubauthor_contact',
     'fields' => array (
@@ -213,7 +214,7 @@ function tripal_pub_add_custom_tables() {
     ),
   );
   chado_create_custom_table('pubauthor_contact', $schema, TRUE);
-}
+} */
 
 /**
  * This is the required update for tripal_pub when upgrading from Drupal core API 6.x.

+ 126 - 57
tripal_chado/includes/tripal_chado.migrate.inc

@@ -129,36 +129,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
         '#title' => 'Migrate All'
       );
       // Migrate selection only
-      if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
-        // Get all Tripal v2 node types from the chad_* linking table
-        $sql =
-          "SELECT V.name AS type, X.accession, db.name AS vocabulary , count(*) AS num
-              FROM {" . $table . "} T
-              INNER JOIN public.$tv2_content_type CT ON T.$pkey = CT.$pkey
-              INNER JOIN {cvterm} V ON V.cvterm_id = T.type_id
-              INNER JOIN {dbxref} X ON X.dbxref_id = V.dbxref_id
-              INNER JOIN {db} ON db.db_id = X.db_id
-              LEFT JOIN public.chado_entity CE ON CE.record_id = T.$pkey
-              AND CE.data_table = '$table'
-              WHERE CE.record_id IS NULL
-              GROUP BY V.name, X.accession, db.name";
-        $tv3_content_types = chado_query($sql);
-        while($tv3_content_type = $tv3_content_types->fetchObject()) {
-          // We need to store vocabulary/accession/type for each checkbox in the key becuase
-          // the value only allows 1 or 0
-          $key = urlencode(
-            'tv3_content_type--' .
-            $tv3_content_type->vocabulary . '--' .
-            $tv3_content_type->accession . '--' .
-            $tv3_content_type->type);
-          $form['step2']['step2_container']['tv3_content_type'][$key] = array(
-            '#type' => 'checkbox',
-            '#title' => $tv3_content_type->type . ' (' . $tv3_content_type->num . ')',
-          );
-          $no_data = FALSE;
-        }
-      }
-      else if ($table == 'organism') {
+      if ($table == 'organism') {
         $sql =
           "SELECT count(*)
               FROM {organism} O
@@ -230,6 +201,53 @@ function tripal_chado_migrate_form($form, &$form_state) {
           $no_data = FALSE;
         }
       }
+      else if ($table == 'pub') {
+        $sql =
+        "SELECT count(*)
+              FROM {pub} P
+              INNER JOIN public.chado_pub CP ON P.pub_id = CP.pub_id
+              LEFT JOIN public.chado_entity CE ON CE.record_id = P.pub_id
+                AND CE.data_table = 'pub'
+              WHERE CE.record_id IS NULL";
+        $proj_count = chado_query($sql)->fetchField();
+        if ($proj_count > 0) {
+          $key = urlencode('tv3_content_type--TPUB--0000002--Publication');
+          $form['step2']['step2_container']['tv3_content_type'][$key] = array(
+            '#type' => 'checkbox',
+            '#title' => 'Publication (' . $proj_count . ')',
+          );
+          $no_data = FALSE;
+        }
+      }
+      else if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
+        // Get all Tripal v2 node types from the chad_* linking table
+        $sql =
+          "SELECT V.name AS type, X.accession, db.name AS vocabulary , count(*) AS num
+              FROM {" . $table . "} T
+              INNER JOIN public.$tv2_content_type CT ON T.$pkey = CT.$pkey
+              INNER JOIN {cvterm} V ON V.cvterm_id = T.type_id
+              INNER JOIN {dbxref} X ON X.dbxref_id = V.dbxref_id
+              INNER JOIN {db} ON db.db_id = X.db_id
+              LEFT JOIN public.chado_entity CE ON CE.record_id = T.$pkey
+              AND CE.data_table = '$table'
+              WHERE CE.record_id IS NULL
+              GROUP BY V.name, X.accession, db.name";
+        $tv3_content_types = chado_query($sql);
+        while($tv3_content_type = $tv3_content_types->fetchObject()) {
+          // We need to store vocabulary/accession/type for each checkbox in the key becuase
+          // the value only allows 1 or 0
+          $key = urlencode(
+            'tv3_content_type--' .
+            $tv3_content_type->vocabulary . '--' .
+            $tv3_content_type->accession . '--' .
+            $tv3_content_type->type);
+          $form['step2']['step2_container']['tv3_content_type'][$key] = array(
+            '#type' => 'checkbox',
+            '#title' => $tv3_content_type->type . ' (' . $tv3_content_type->num . ')',
+          );
+          $no_data = FALSE;
+        }
+      }
       if ($no_data) {
         unset($form['step2']['step2_container']['tv3_content_type']['tv3_migrate_all']);
         drupal_set_message('No data for migration or all have been migrated.', 'warning');
@@ -604,31 +622,7 @@ function tripal_chado_migrate_map_types($tv2_content_types) {
     $pkey = $schema['primary key'][0];
     $fkeys = $schema['foreign keys'];
 
-    if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
-      // Get all Tripal v2 node types from the chad_* linking table
-      $sql = "
-        SELECT V.name AS type, X.accession, db.name AS vocabulary
-        FROM {" . $table . "} T
-          INNER JOIN public.$tv2_content_type CT ON T.$pkey = CT.$pkey
-          INNER JOIN {cvterm} V ON V.cvterm_id = T.type_id
-          INNER JOIN {dbxref} X ON X.dbxref_id = V.dbxref_id
-          INNER JOIN {db} ON db.db_id = X.db_id
-          GROUP BY V.name, X.accession, db.name
-          ";
-      $tv3_content_types = chado_query($sql);
-      while($tv3_content_type = $tv3_content_types->fetchObject()) {
-        array_push($types, array(
-          'vocabulary' => $tv3_content_type->vocabulary,
-          'accession' => $tv3_content_type->accession,
-          'term_name' => $tv3_content_type->type,
-          'storage_args' => array (
-            'data_table' => $table,
-            'type_column' => db_field_exists('chado.' . $table, 'type_id') ? 'type_id' : ''
-          )
-        ));
-      }
-    }
-    else if ($table == 'organism') {
+    if ($table == 'organism') {
       array_push($types, array(
         'vocabulary' => 'OBI',
         'accession' => '0100026',
@@ -668,7 +662,40 @@ function tripal_chado_migrate_map_types($tv2_content_types) {
         )
     ));
   }
-
+  else if ($table == 'pub') {
+    array_push($types, array(
+      'vocabulary' => 'TPUB',
+      'accession' => '0000002',
+      'term_name' => 'Publication',
+      'storage_args' => array (
+        'data_table' => $table
+      )
+    ));
+  }
+  else if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
+      // Get all Tripal v2 node types from the chad_* linking table
+      $sql = "
+        SELECT V.name AS type, X.accession, db.name AS vocabulary
+        FROM {" . $table . "} T
+          INNER JOIN public.$tv2_content_type CT ON T.$pkey = CT.$pkey
+          INNER JOIN {cvterm} V ON V.cvterm_id = T.type_id
+          INNER JOIN {dbxref} X ON X.dbxref_id = V.dbxref_id
+          INNER JOIN {db} ON db.db_id = X.db_id
+          GROUP BY V.name, X.accession, db.name
+          ";
+      $tv3_content_types = chado_query($sql);
+      while($tv3_content_type = $tv3_content_types->fetchObject()) {
+        array_push($types, array(
+          'vocabulary' => $tv3_content_type->vocabulary,
+          'accession' => $tv3_content_type->accession,
+          'term_name' => $tv3_content_type->type,
+          'storage_args' => array (
+            'data_table' => $table,
+            'type_column' => db_field_exists('chado.' . $table, 'type_id') ? 'type_id' : ''
+          )
+        ));
+      }
+    }
   }
   return $types;
 }
@@ -700,6 +727,11 @@ function tripal_chado_migrate_selected_types($tv3_content_types) {
       'bundle_name' => $bundle_name
     );
     tripal_chado_publish_records($value);
+    
+    // Migrate organism images
+    if ($term->name == 'organism') {
+      tripal_chado_migrate_organism_images($bundle_name);
+    }
   }
 }
 
@@ -777,4 +809,41 @@ function tripal_chado_migrate_url_alias_for_selected_types($tv2_content_types =
       db_query($usql);
     }
   }
-}
+}
+
+/**
+ * Migrate images for Tripal v2 organism content
+ *
+ * Migrate images for all chado_organism
+ *
+ * @param unknown $tv2_content_types
+ */
+function tripal_chado_migrate_organism_images () {
+  // Get all organism entities
+  $results = 
+    db_select('chado_entity', 'ce')
+    ->fields('ce', array('entity_id', 'record_id', 'nid'))
+    ->condition('data_table', 'organism')
+    ->execute();
+  
+  // Iterate through each organism entity
+  while ($organism = $results->fetchObject()) {
+    $nid = $organism->nid;
+    $eid = $organism->entity_id;
+    
+    // check if there is a file record for the organism node
+    $fid = db_select('file_usage', 'fu')
+    ->field('fu', array('fid'))
+    ->condition('module', 'tripal_organism')
+    ->condition('type', 'organism_image')
+    ->condition('id', $nid)
+    ->execute()
+    ->fetchField();
+    
+    // If there is an image, add it to the organism entity
+    if ($fid) {
+      
+    }
+  }
+  
+}