瀏覽代碼

Fixed bug in tripal_core

spficklin 14 年之前
父節點
當前提交
a3b0e16b18
共有 1 個文件被更改,包括 14 次插入4 次删除
  1. 14 4
      tripal_core/tripal_core.module

+ 14 - 4
tripal_core/tripal_core.module

@@ -205,6 +205,7 @@ function tripal_core_admin () {
 */
 function tripal_db_set_active($dbname){
    global $db_url, $db_type;
+   $chado_exists = 0;
 
    // only postgres can support search paths.  So if this is MysQL then
    // just run the normal tripal_db_set_active function.
@@ -214,21 +215,30 @@ function tripal_db_set_active($dbname){
       // not in the same Drupal database
       if(is_array($db_url)){ 
          if(isset($db_url[$dbname])){
-            return tripal_db_set_active($dbname);
+            return db_set_active($dbname);
          } 
       }
 
+      // check to make sure the chado schema exists
+      $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
+      if(db_fetch_object(db_query($sql))){
+         $chado_exists = 1;
+      }
+
       // here we make the assumption that the default database schema is
       // 'public'.  This will most likely always be the case but if not,
       // then this code will break
-      if(strcmp($dbname,'chado')==0){
+      if($chado_exists && strcmp($dbname,'chado')==0){
          db_query("set search_path to %s",'chado,public');  
          return 'public,chado';
       } 
-      else {
+      elseif($chado_exists) {
          db_query("set search_path to %s",'public,chado');  
          return 'chado,public';
       }
+      else {
+         return db_set_active($dbname);
+      }
    }
-   else return tripal_db_set_active($dbname);
+   else return db_set_active($dbname);
 }