Browse Source

fixed merge conflict

Stephen Ficklin 9 years ago
parent
commit
1501bf2ccd

+ 1 - 4
tripal/tripal.install

@@ -10,9 +10,6 @@
  * @ingroup tripal
  */
 function tripal_install() {
-  // Add some variables for the bundles.
-  tripal_add_variables();
-
   // On upgrade from Tv2 to Tv3 we need to add a new field to the tripal_jobs
   // table it's missing.
   if (!db_field_exists('tripal_jobs', 'includes')) {
@@ -127,8 +124,8 @@ function tripal_enable() {
     $sql = "ALTER INDEX tripal_variables_tripal_variables_c1_key2 RENAME TO tripal_variables_tripal_variables_c1_key";
     db_query($sql);
 
-    tripal_add_variables();
   }
+  tripal_add_variables();
 }
 
 /**

+ 60 - 30
tripal_chado/includes/tripal_chado.migrate.inc

@@ -58,9 +58,10 @@ function tripal_chado_migrate_form($form, &$form_state) {
       ),
     );
 
+    $no_data = TRUE;
     if ($form_state['clicked_button']['#name'] == 'get_v3_type_btn') {
 
-      // Migrate all
+      // Migrate all      
       $form['tv3_content_type']['tv3_migrate_all'] = array(
         '#type' => 'checkbox',
         '#title' => 'Migrate All'
@@ -70,42 +71,70 @@ function tripal_chado_migrate_form($form, &$form_state) {
         // Get all Tripal v2 node types from the chad_* linking table
         $sql =
           "SELECT V.name AS type, X.accession, db.name AS namespace , count(*) AS num
-              FROM chado.$table T
-              INNER JOIN $tv2_content_type CT ON T.$pkey = CT.$pkey
-              INNER JOIN chado.cvterm V ON V.cvterm_id = T.type_id
-              INNER JOIN chado.dbxref X ON X.dbxref_id = V.dbxref_id
-              INNER JOIN chado.db ON db.db_id = X.db_id
+              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 = db_query($sql);
+        $tv3_content_types = chado_query($sql);
         while($tv3_content_type = $tv3_content_types->fetchObject()) {
-          $form['tv3_content_type']['tv3_content_type--' . $tv3_content_type->namespace .
-              '--' . $tv3_content_type->accession . '--' . $tv3_content_type->type] = array(
+          // We need to store namespace/accession/type for each checkbox in the key becuase
+          // the value only allows 1 or 0
+          $key = urlencode(
+            'tv3_content_type--' . 
+            $tv3_content_type->namespace . '--' . 
+            $tv3_content_type->accession . '--' . 
+            $tv3_content_type->type);
+          $form['tv3_content_type'][$key] = array(
             '#type' => 'checkbox',
             '#title' => $tv3_content_type->type . ' (' . $tv3_content_type->num . ')',
           );
+          $no_data = FALSE;
         }
       }
       else if ($table == 'organism') {
         $sql =
           "SELECT count(*)
-              FROM chado.organism O
-              INNER JOIN chado_organism CO ON O.organism_id = CO.organism_id";
-        $org_count = db_query($sql)->fetchField();
-        $form['tv3_content_type']['tv3_content_type--local--organism--organism'] = array(
-          '#type' => 'checkbox',
-          '#title' => 'Organism (' . $org_count . ')',
-        );
+              FROM {organism} O
+              INNER JOIN public.chado_organism CO ON O.organism_id = CO.organism_id
+              LEFT JOIN public.chado_entity CE ON CE.record_id = O.organism_id 
+                AND CE.data_table = 'organism'
+              WHERE CE.record_id IS NULL";
+        $org_count = chado_query($sql)->fetchField();
+        if ($org_count > 0) {
+          $key = urldecode('tv3_content_type--local--organism--organism');
+          $form['tv3_content_type'][$key] = array(
+            '#type' => 'checkbox',
+            '#title' => 'Organism (' . $org_count . ')',
+          );
+          $no_data = FALSE;
+        }
       }
       else if ($table == 'analysis') {
         $sql =
         "SELECT count(*)
-              FROM chado.analysis A
-              INNER JOIN chado_analysis CA ON A.analysis_id = CA.analysis_id";
-        $ana_count = db_query($sql)->fetchField();
-        $form['tv3_content_type']['tv3_content_type--local--analysis--analysis'] = array(
-          '#type' => 'checkbox',
-          '#title' => 'Analysis (' . $ana_count . ')',
-        );
+              FROM {analysis} A
+              INNER JOIN public.chado_analysis CA ON A.analysis_id = CA.analysis_id
+              LEFT JOIN public.chado_entity CE ON CE.record_id = A.analysis_id 
+                AND CE.data_table = 'analysis'
+              WHERE CE.record_id IS NULL";
+        $ana_count = chado_query($sql)->fetchField();
+        if ($ana_count > 0) {
+          $key = urlencode('tv3_content_type--local--analysis--analysis');
+          $form['tv3_content_type'][$key] = array(
+            '#type' => 'checkbox',
+            '#title' => 'Analysis (' . $ana_count . ')',
+          );
+          $no_data = FALSE;
+        }
+      }
+      if ($no_data) {
+        unset($form['tv3_content_type']['tv3_migrate_all']);
+        drupal_set_message('No data for migration or all have been migrated.', 'warning');
       }
     }
   }
@@ -150,6 +179,7 @@ function tripal_chado_migrate_form_submit($form, &$form_state) {
     $tv3_content_type = array();
     foreach ($values AS $key => $value) {
       if ($tv2_content_type != 'all') {
+        $key = urldecode($key);
         if (preg_match('/^tv3_content_type--(.+)--(.+)--(.+)/', $key, $matches) &&
             ($value == 1 || $values['tv3_migrate_all'] == 1)) {
           $namespace = $matches[1];
@@ -180,7 +210,7 @@ function tripal_chado_migrate_form_submit($form, &$form_state) {
         'tripal_chado', 'tripal_chado_migrate_records', $args, $user->uid, 10, $includes);
     }
     else {
-      return drupal_set_message('Nothing to do. No data for migration.');
+      return drupal_set_message('Nothing to do. All data have been migrated or no data for migration.');
     }
   }
 }
@@ -279,14 +309,14 @@ function tripal_chado_migrate_all_types() {
       // Get all Tripal v2 node types from the chad_* linking table
       $sql = "
         SELECT V.name AS type, X.accession, db.name AS namespace
-        FROM chado.$table T
-          INNER JOIN $tv2_content_type CT ON T.$pkey = CT.$pkey
-          INNER JOIN chado.cvterm V ON V.cvterm_id = T.type_id
-          INNER JOIN chado.dbxref X ON X.dbxref_id = V.dbxref_id
-          INNER JOIN chado.db ON db.db_id = X.db_id
+        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 = db_query($sql);
+      $tv3_content_types = chado_query($sql);
       while($tv3_content_type = $tv3_content_types->fetchObject()) {
         array_push($types, array(
           'namespace' => $tv3_content_type->namespace,

+ 10 - 0
tripal_chado/tripal_chado.module

@@ -1904,3 +1904,13 @@ function tripal_chado_entity_property_get_value($entity, $options, $field_name,
 
   return drupal_render($render_array);
 }
+
+/**
+ * Remove the nid from chado_entity if it exists when the node is deleted
+ */
+function tripal_chado_node_delete($node) {
+  dpm($node);
+  $nid = $node->nid;
+  $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid";
+  db_query($sql, array('nid' => $nid));
+}

+ 26 - 22
tripal_panes/theme/templates/tripal_panes_generic.tpl.php

@@ -16,9 +16,11 @@ $bundle_type = $bundle->name . '-' . $bundle->label;
 
 $content = '';
 $toc = '';
-$has_base_pane_only = TRUE;
+$panes = $variables['element']['#panes'];
+$fields = $variables['element']['#fields'];
+$has_base_pane_only = count($panes) == 1 ? TRUE : FALSE;
 
-get_content($variables, $bundle_type, $content, $toc, $has_base_pane_only);
+get_content($panes, $fields, $bundle_type, $content, $toc, $has_base_pane_only);
 
 if ($has_base_pane_only) { ?>
   <div id ="tripal-<?php print $bundle_type?>-contents-box"> <?php
@@ -41,7 +43,7 @@ else { ?>
 }
 
 /**
- * Iterates through the panes and generates a conent string in HTML format.
+ * Iterates through the panes and generates the HTML conent
  *
  * @param $variables
  * @param $bundle_type
@@ -49,17 +51,14 @@ else { ?>
  * @param $toc
  * @param $has_base_pane_only
  */
-function get_content($variables, $bundle_type, &$content, &$toc, &$has_base_pane_only) {
-  $panes = $variables['element']['#panes'];
-  $fields = $variables['element']['#fields'];
+function get_content($panes, $fields, $bundle_type, &$content, &$toc, $has_base_pane_only) {
+
 
   // Iterate through all of the panes.
   foreach ($panes AS $pane_id => $pane) {
     // If we have a pane other than the base pane then we have more than
     // just the base.
-    if ($pane->name != 'te_base') {
-      $has_base_pane_only = FALSE;
-    }
+
     $pane_settings = unserialize($pane->settings);
     $table_layout_group = key_exists('table_layout', $pane_settings) ? $pane_settings['table_layout'] : array();
 
@@ -113,20 +112,25 @@ function get_content($variables, $bundle_type, &$content, &$toc, &$has_base_pane
       $output .= tripal_panes_generic_render_fields($no_group);
     }
 
-    $pane_label = $pane->name == 'te_base' ? 'Summary' : $pane->label;
-    $collapsible_item = array('element' => array());
-    $collapsible_item['element']['#description'] = $output;
-    $collapsible_item['element']['#title'] = $pane_label;
-    $collapsible_item['element']['#children'] = '';
-    $collapsible_item['element']['#attributes']['id'] = 'tripal_pane-fieldset-' . $pane->name;
-    $collapsible_item['element']['#attributes']['class'][] = 'tripal_pane-fieldset';
-    $collapsible_item['element']['#attributes']['class'][] = 'collapsible';
-    if ($pane->name != 'te_base') {
-      $collapsible_item['element']['#attributes']['class'][] = 'collapsed';
+    if ($has_base_pane_only) {
+      $content .= $output;
+    }
+    else {
+      $pane_label = $pane->name == 'te_base' ? 'Summary' : $pane->label;
+      $collapsible_item = array('element' => array());
+      $collapsible_item['element']['#description'] = $output;
+      $collapsible_item['element']['#title'] = $pane_label;
+      $collapsible_item['element']['#children'] = '';
+      $collapsible_item['element']['#attributes']['id'] = 'tripal_pane-fieldset-' . $pane->name;
+      $collapsible_item['element']['#attributes']['class'][] = 'tripal_pane-fieldset';
+      $collapsible_item['element']['#attributes']['class'][] = 'collapsible';
+      if ($pane->name != 'te_base') {
+        $collapsible_item['element']['#attributes']['class'][] = 'collapsed';
+      }
+      $toc_item_id = $pane_id;
+      $toc .= "<div class=\"tripal-panes-toc-list-item\"><a id=\"" . $pane->name . "\" class=\"tripal_panes-toc-list-item-link\" href=\"?pane=" . $pane->name . "\">" . $pane_label . "</a></div>";
+      $content .= theme('fieldset', $collapsible_item);
     }
-    $toc_item_id = $pane_id;
-    $toc .= "<div class=\"tripal-panes-toc-list-item\"><a id=\"" . $pane->name . "\" class=\"tripal_panes-toc-list-item-link\" href=\"?pane=" . $pane->name . "\">" . $pane_label . "</a></div>";
-    $content .= theme('fieldset', $collapsible_item);
     if ($pane->name == 'te_base') {
       $content .= '<div class="tripal-panes-content-top"></div>';
     }