Browse Source

Views Integration (Issue #2479599): Additional Ramifications since the unset mview_id was used to detect legacy mviews repeatedly, there needed to be fixes in the hook_views_data() and views integration UI

Lacey Sanderson 9 years ago
parent
commit
faa9546d67

+ 23 - 20
tripal_views/includes/tripal_views_integration_UI.inc

@@ -306,7 +306,7 @@ function tripal_views_integration_form($form, &$form_state) {
   $chado_tables = array_merge(array('Select'), $chado_tables);
   $default = '';
   if ($setup_id) {
-    $default = (!$setup_obj->mview_id) ? $setup_obj->table_name : '';
+    $default = ($setup_obj->table_name) ? $setup_obj->table_name : '';
   }
   $form['base_table_type']['table_name'] = array(
     '#title' => t('Chado/Custom Table'),
@@ -326,7 +326,6 @@ function tripal_views_integration_form($form, &$form_state) {
 
 
   // build the form element that lists the materialized views
-  // D7 TODO: Check DBTNG changes work
   $query = db_query("SELECT mview_id, name FROM {tripal_mviews} WHERE mv_schema is NULL or mv_schema = '' ORDER BY name");
   $mview_tables = array();
   $mview_tables['0'] = 'Select';
@@ -334,24 +333,29 @@ function tripal_views_integration_form($form, &$form_state) {
     $mview_tables[$mview->mview_id] = $mview->name;
   }
   $default = '';
-  if ($setup_id && isset($setup_obj->mview_id)) {
+  $legacy_mview = FALSE;
+  if ($setup_id && !empty($setup_obj->mview_id)) {
     $default = $setup_obj->mview_id;
   }
-  $form['base_table_type']['mview_id'] = array(
-    '#title' => t('Legacy Materialized View'),
-    '#type' => 'select',
-    '#options' => $mview_tables,
-    '#description' => 'Which materialized view to use.',
-    '#default_value' => $default,
-    '#ajax' => array(
-       //D6: 'path' => 'tripal/views-integration/ajax/view_setup_table',
-       'callback' => 'tripal_views_integration_ajax_view_setup_table',
-       'wrapper' => 'tripal-views-integration-form',
-       'effect' => 'fade',
-       'event' => 'change',
-       'method' => 'replace',
-    ),
-  );
+  if (isset($mview_tables[$setup_obj->mview_id])) {
+    $legacy_mview = TRUE;
+
+    $form['base_table_type']['mview_id'] = array(
+      '#title' => t('Legacy Materialized View'),
+      '#type' => 'select',
+      '#options' => $mview_tables,
+      '#description' => 'Which materialized view to use.',
+      '#default_value' => $default,
+      '#ajax' => array(
+         //D6: 'path' => 'tripal/views-integration/ajax/view_setup_table',
+         'callback' => 'tripal_views_integration_ajax_view_setup_table',
+         'wrapper' => 'tripal-views-integration-form',
+         'effect' => 'fade',
+         'event' => 'change',
+         'method' => 'replace',
+      ),
+    );
+  }
 
   $form['views_type'] = array(
     '#type' => 'fieldset',
@@ -470,8 +474,7 @@ function tripal_views_integration_form($form, &$form_state) {
     // get the columns in this materialized view.  They are separated by commas
     // where the first word is the column name and the rest is the type
     $columns = array();
-    if ($mview_id) {
-      // D7 TODO: Check DBTNG changes work
+    if ($legacy_mview) {
       $sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = :id";
       $mview = db_query($sql, array(':id' => $mview_id));
       $mview = $mview->fetchObject();

+ 7 - 0
tripal_views/tripal_views.views.inc

@@ -165,6 +165,7 @@ function tripal_views_views_data() {
     // POPULATE THE BASE TABLE NAME AND FIELDS
     // If an $mview_id is given then get the materialized view info,
     // otherwise get the Chado table info
+    $legacy_mview = FALSE;
     if ($mview_id) {
 
       // get the base table name from the materialized view
@@ -174,6 +175,12 @@ function tripal_views_views_data() {
       $mview_table = $mview_table->fetchObject();
       $base_table = $mview_table->name;
 
+      if (!empty($mview_table->mv_specs)) {
+        $legacy_mview = TRUE;
+      }
+    }
+
+    if ($legacy_mview) {
       // get the columns in this materialized view.  They are separated by commas
       // where the first word is the column name and the rest is the type
       $columns = explode(",", $mview_table->mv_specs);