Browse Source

Added a requirement that Chado must be accessible before Tripal Views gets installed

spficklin 12 years ago
parent
commit
8f64c6204a

+ 9 - 10
tripal_feature/api/tripal_feature.api.inc

@@ -569,7 +569,7 @@ function trpial_feature_get_formatted_sequence($feature_id, $feature_name,
   $upstream, $downstream) {
   
   // to speed things up we need to make sure we have a persistent connection
-  tripal_db_persistent_chado(); 
+  $connection = tripal_db_persistent_chado(); 
   
   if (!$upstream) {
      $upstream = 0;
@@ -591,7 +591,8 @@ function trpial_feature_get_formatted_sequence($feature_id, $feature_name,
       // parent sequence.
       $psql ='PREPARE sequence_by_parent (int, int, int) AS 
               SELECT
-                OF.name srcname, FL.srcfeature_id, FL.strand, OCVT.name as srctypename, SCVT.name as typename,
+                OF.name srcname, FL.srcfeature_id, FL.strand, 
+                OCVT.name as srctypename, SCVT.name as typename,
                 FL.fmin, FL.fmax,
                 CASE 
                   WHEN FL.strand >= 0 THEN 
@@ -604,8 +605,7 @@ function trpial_feature_get_formatted_sequence($feature_id, $feature_name,
                        WHEN FL.fmin - $2 <= 0 THEN 0
                        ELSE FL.fmin - $2
                     END                   
-                END as adjfmin,                                
-                                
+                END as adjfmin,                                                                
                 CASE 
                   WHEN FL.strand >= 0 THEN
                     CASE 
@@ -617,8 +617,7 @@ function trpial_feature_get_formatted_sequence($feature_id, $feature_name,
                       WHEN FL.fmax + $1 > OF.seqlen THEN OF.seqlen
                       ELSE FL.fmax + $1   
                     END               
-                END as adjfmax,     
-                
+                END as adjfmax,                     
                 CASE 
                   WHEN FL.strand >= 0 THEN 
                     CASE 
@@ -630,8 +629,7 @@ function trpial_feature_get_formatted_sequence($feature_id, $feature_name,
                        WHEN FL.fmax + $1 > OF.seqlen THEN OF.seqlen - FL.fmax
                        ELSE $1
                     END                   
-                END as upstream,
-                
+                END as upstream,                
                 CASE 
                   WHEN FL.strand >= 0 THEN 
                     CASE 
@@ -644,7 +642,7 @@ function trpial_feature_get_formatted_sequence($feature_id, $feature_name,
                        ELSE $2
                     END                   
                 END as downstream,                                          
-                substring(OF.residues from (adjfmin + 1) for (upstream + (FL.fmax - FL.fmin) + downstream)  as residues
+                substring(OF.residues from (adjfmin + 1) for (upstream + (FL.fmax - FL.fmin) + downstream))  as residues
               FROM featureloc FL 
                 INNER JOIN feature SF on FL.feature_id = SF.feature_id
                 INNER JOIN cvterm SCVT on SF.type_id = SCVT.cvterm_id
@@ -653,6 +651,7 @@ function trpial_feature_get_formatted_sequence($feature_id, $feature_name,
               WHERE SF.feature_id = $3';
               
       $status = chado_query($psql);
+exit;    
       if (!$status) {
         watchdog('tripal_views_handler_field_sequence', 
           "init: not able to prepare SQL statement '%name'", 
@@ -697,7 +696,7 @@ function trpial_feature_get_formatted_sequence($feature_id, $feature_name,
     // execute the query
     $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
     $parents = chado_query($sql, $upstream, $downstream, $feature_id);
-    
+
     while ($parent = db_fetch_object($parents)) {  
       $seq = '';  // initialize the sequence for each parent
 

+ 34 - 0
tripal_views/tripal_views.install

@@ -321,3 +321,37 @@ function tripal_views_views_schema() {
 
   return $schema;
 }
+/**
+ * Implementation of hook_requirements(). Make sure Chado database is accessible
+ * before installation
+ *
+ * @ingroup tripal_views
+ */
+function tripal_views_requirements($phase) {
+  global $db_url;
+  
+  $requirements = array();
+  if ($phase == 'install') {
+    $is_remote = FALSE;
+    $is_local = FALSE;
+  
+    // check if chado is accessible but not local
+    if (is_array($db_url) && isset($db_url['chado'])) {
+       $is_remote = TRUE;
+    }
+    // check if chado is locally accessible
+    $is_local = tripal_core_chado_schema_exists();
+  
+    if (!$is_remote and $is_local) {
+      $requirements ['tripal_views'] = array(
+        'title' => "tripal_views",
+        'value' => t("Chado must be available before Tripal Views can be enabled.  
+                      Please ensure Chado is in the Drupal database in a 'chado' 
+                      schema (desired) or defined in the \$db_url variable of 
+                      the settings.php file.",
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
+}

+ 2 - 2
tripal_views/tripal_views.module

@@ -17,7 +17,7 @@ function tripal_views_menu() {
   $items = array();
 
   $items['chado'] = array(
-    'title' => 'Biological Data',
+    'title' => 'Search Biological Data',
     'description' => 'Listings of the various biological data available categorized by type.',
     'page callback' => 'tripal_views_biological_data_page',
     'access arguments' => array('access content'),
@@ -184,4 +184,4 @@ function tripal_views_biological_data_page() {
   $output .= '</dl>';
 
   return $output;
-}
+}