Browse Source

Chado Prepare Bug: Create Custom table tries to redirect which fails with Drush

Lacey Sanderson 7 years ago
parent
commit
b305ab18f8

+ 16 - 6
tripal_chado/api/tripal_chado.custom_tables.api.inc

@@ -117,12 +117,16 @@ function chado_edit_custom_table($table_id, $table_name, $schema, $skip_if_exist
  *   it's mview_id. This paramter is intended only when this function
  *   is called by the tripal_add_mview() function. When creating a custom
  *   table you shouldn't need to use this parameter.
+ * @param $redirect
+ *   Optional (default: TRUE). By default this function redirects back to
+ *   admin pages. However, when called by Drush we don't want to redirect. This
+ *   parameter allows this to be used as a true API function.
  * @return
  *   TRUE on success, FALSE on failure
  *
  * @ingroup tripal_custom_tables_api
  */
-function chado_create_custom_table($table, $schema, $skip_if_exists = TRUE, $mview_id = NULL) {
+function chado_create_custom_table($table, $schema, $skip_if_exists = TRUE, $mview_id = NULL, $redirect = TRUE) {
   global $databases;
   $created = 0;
   $recreated = 0;
@@ -206,6 +210,7 @@ function chado_create_custom_table($table, $schema, $skip_if_exists = TRUE, $mvi
       array('%table_name' => $table, '%message' => $error['!message'])), 'error');
     return FALSE;
   }
+
   if ($created) {
     drupal_set_message("Custom table, '" . $table . "' ,  created successfully.", 'status');
   }
@@ -216,12 +221,17 @@ function chado_create_custom_table($table, $schema, $skip_if_exists = TRUE, $mvi
     drupal_set_message("Custom table, '" . $table . "' , already exists. Table structure not changed, but definition array has been saved.", 'status');
   }
 
-  if ($mview_id) {
-    drupal_goto('admin/tripal/storage/chado/mviews/');
-  }
-  else {
-    drupal_goto('admin/tripal/storage/chado/custom_tables');
+  // Only redirect if asked to. This allows us to not try to redirect when this
+  // function is called by Drush.
+  if ($redirect) {
+    if ($mview_id) {
+      drupal_goto('admin/tripal/storage/chado/mviews/');
+    }
+    else {
+      drupal_goto('admin/tripal/storage/chado/custom_tables');
+    }
   }
+
   return TRUE;
 }
 

+ 6 - 2
tripal_chado/api/tripal_chado.mviews.api.inc

@@ -33,10 +33,14 @@
  *   The SQL query that loads the materialized view with data
  * @param $comment
  *   A string containing a description of the materialized view
+ * @param $redirect
+ *   Optional (default: TRUE). By default this function redirects back to
+ *   admin pages. However, when called by Drush we don't want to redirect. This
+ *   parameter allows this to be used as a true API function.
  *
  * @ingroup tripal_mviews_api
  */
-function tripal_add_mview($name, $modulename, $mv_schema, $query, $comment = NULL) {
+function tripal_add_mview($name, $modulename, $mv_schema, $query, $comment = NULL, $redirect = TRUE) {
 
   if (!array_key_exists('table', $mv_schema)) {
      tripal_report_error('tripal_chado', TRIPAL_ERROR,
@@ -77,7 +81,7 @@ function tripal_add_mview($name, $modulename, $mv_schema, $query, $comment = NUL
           chado_query($sql);
         }
         // create the table
-        chado_create_custom_table($mv_table, $mv_schema, 0, $record->mview_id);
+        chado_create_custom_table($mv_table, $mv_schema, 0, $record->mview_id, $redirect);
       }
     }
     catch (Exception $e) {

+ 5 - 5
tripal_chado/includes/setup/tripal_chado.chado_v1.2.inc

@@ -64,7 +64,7 @@ function tripal_chado_add_contactprop_table(){
       ),
     ),
   );
-  chado_create_custom_table('contactprop', $schema, TRUE);
+  chado_create_custom_table('contactprop', $schema, TRUE, NULL, FALSE);
 }
 
 /**
@@ -129,7 +129,7 @@ function tripal_chado_add_featuremap_dbxref_table(){
     'referring_tables' => NULL,
   );
 
-  chado_create_custom_table('featuremap_dbxref', $schema, TRUE);
+  chado_create_custom_table('featuremap_dbxref', $schema, TRUE, NULL, FALSE);
 
 }
 
@@ -201,7 +201,7 @@ function tripal_chado_add_featuremapprop_table(){
       ),
     ),
   );
-  chado_create_custom_table('featuremapprop', $schema, TRUE);
+  chado_create_custom_table('featuremapprop', $schema, TRUE, NULL, FALSE);
 }
 
 /**
@@ -266,7 +266,7 @@ function tripal_chado_add_featureposprop_table(){
       ),
     ),
   );
-  chado_create_custom_table('featureposprop', $schema, TRUE);
+  chado_create_custom_table('featureposprop', $schema, TRUE, NULL, FALSE);
 }
 
 
@@ -317,5 +317,5 @@ function tripal_chado_add_pubauthor_contact_table() {
       ),
     ),
   );
-  chado_create_custom_table('pubauthor_contact', $schema, TRUE);
+  chado_create_custom_table('pubauthor_contact', $schema, TRUE, NULL, FALSE);
 }

+ 9 - 9
tripal_chado/includes/setup/tripal_chado.chado_vx_x.inc

@@ -31,7 +31,7 @@ function tripal_chado_add_tripal_gff_temp_table() {
       'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
     ),
   );
-  chado_create_custom_table('tripal_gff_temp', $schema, TRUE);
+  chado_create_custom_table('tripal_gff_temp', $schema, TRUE, NULL, FALSE);
 }
 
 /**
@@ -71,7 +71,7 @@ function tripal_chado_add_tripal_gffcds_temp_table() {
       'tripal_gff_temp_idx0' => array('parent_id'),
     ),
   );
-  chado_create_custom_table('tripal_gffcds_temp', $schema);
+  chado_create_custom_table('tripal_gffcds_temp', $schema, TRUE, NULL, FALSE);
 }
 
 /**
@@ -106,7 +106,7 @@ function tripal_chado_add_tripal_gffprotein_temp_table() {
       'tripal_gff_temp_uq0' => array('feature_id'),
     ),
   );
-  chado_create_custom_table('tripal_gffprotein_temp', $schema, TRUE);
+  chado_create_custom_table('tripal_gffprotein_temp', $schema, TRUE, NULL, FALSE);
 }
 
 /**
@@ -205,7 +205,7 @@ function tripal_chado_add_organism_stock_count_mview() {
         O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
   ";
 
-  tripal_add_mview($view_name, 'tripal_stock', $schema, $sql, $comment);
+  tripal_add_mview($view_name, 'tripal_stock', $schema, $sql, $comment, FALSE);
 }
 
 
@@ -261,7 +261,7 @@ function tripal_chado_add_library_feature_count_mview(){
     GROUP BY L.library_id, L.name, CVT.name
   ";
 
-  tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment);
+  tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment, FALSE);
 }
 
 
@@ -344,7 +344,7 @@ function tripal_chado_add_organism_feature_count_mview() {
         O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
   ";
 
-  tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
+  tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment, FALSE);
 }
 
 
@@ -404,7 +404,7 @@ function tripal_chado_add_analysis_organism_mview() {
   );
 
   // add the view
-  tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment);
+  tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment, FALSE);
 }
 
 /**
@@ -463,7 +463,7 @@ function tripal_chado_add_db2cv_mview_mview() {
   ";
 
   // Create the MView
-  tripal_add_mview($mv_name, 'tripal_chado', $schema, $sql, $comment);
+  tripal_add_mview($mv_name, 'tripal_chado', $schema, $sql, $comment, FALSE);
 }
 /**
  * Add a materialized view of root terms for all chado cvs.
@@ -515,6 +515,6 @@ function tripal_chado_add_cv_root_mview_mview() {
   ";
 
   // Create the MView
-  tripal_add_mview($mv_name, 'tripal_chado', $schema, $sql, $comment);
+  tripal_add_mview($mv_name, 'tripal_chado', $schema, $sql, $comment, FALSE);
 }
 

+ 1 - 0
tripal_chado/includes/setup/tripal_chado.setup.inc

@@ -537,6 +537,7 @@ function tripal_chado_add_vx_x_custom_tables(){
   tripal_chado_add_analysis_organism_mview();
   tripal_chado_add_cv_root_mview_mview();
   tripal_chado_add_db2cv_mview_mview();
+
 }
 
 /**