Browse Source

Fix for issue #278

Stephen Ficklin 7 years ago
parent
commit
d049bd99c9

+ 17 - 9
tripal_chado/api/tripal_chado.schema.api.inc

@@ -262,8 +262,15 @@ function chado_dbschema_exists($schema) {
  */
 function chado_is_local() {
 
+  // If the is_local variable has been set then we've already checked if
+  // Chado is local and we don't need to repeat it again.
+  if (isset($GLOBALS["chado_is_local"])) {
+    return $GLOBALS["chado_is_local"];
+  }
+
   // This is postgresql-specific code to check the existence of the chado schema
-  // @coder-ignore: acting on pg_catalog schema rather then drupal schema therefore, table prefixing does not apply
+  // @coder-ignore: acting on pg_catalog schema rather then drupal schema
+  // therefore, table prefixing does not apply
   $sql = "
     SELECT nspname
     FROM pg_namespace
@@ -330,13 +337,14 @@ function chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE) {
 
   global $databases;
   $version = '';
-  $is_local = 0;
-
-  // check that Chado is installed if not return 'uninstalled as the version'
-  $chado_exists = chado_is_local();
-  if (!$chado_exists) {
-    // if it's not in the drupal database check to see if it's specified in the $db_url
-    // in the settings.php
+  $is_local = FALSE;
+  $chado_exists = FALSE;
+
+  // Check that Chado is installed if not return 'uninstalled as the version'
+  $is_local = isset($GLOBALS["chado_is_local"]) && $GLOBALS["chado_is_local"];
+  if (!$is_local) {
+    // If it's not in the drupal database check to see if it's specified in
+    // the $db_url in the settings.php
     if (!array_key_exists(tripal_get_schema_name('chado'), $databases)) {
       // if it's not in the drupal database or specified in the $db_url then
       // return uninstalled as the version
@@ -348,7 +356,7 @@ function chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE) {
     chado_set_active($previous_db);
   }
   else {
-    $is_local = 1;
+    $chado_exists = TRUE;
     // @todo we need a chado aware db_table_exists.
     $prop_exists = db_table_exists(tripal_get_schema_name('chado') . '.chadoprop');
   }

+ 5 - 4
tripal_chado/tripal_chado.module

@@ -74,11 +74,12 @@ tripal_chado_set_globals();
  * @ingroup tripal_chado
  */
 function tripal_chado_set_globals() {
-  // these global variables are meant to be accessed by all Tripal
+  // These global variables are meant to be accessed by all Tripal
   // modules to find the chado version installed and if Chado is local.
-  // these variables are stored as globals rather than using the drupal_set_variable
-  // functions because the Drupal functions make databaes queries and for long
-  // running loaders we don't want those queries repeatedly.
+  // These variables are stored as globals rather than using the
+  // drupal_set_variable functions because the Drupal functions make databaes
+  // queries and for long running loaders we don't want those queries
+  // repeatedly.
   $GLOBALS["chado_is_installed"]  = chado_is_installed();
   if ($GLOBALS["chado_is_installed"]) {
     $GLOBALS["chado_is_local"]      = chado_is_local();

+ 2 - 1
tripal_chado_views/api/tripal_chado_views.api.inc

@@ -178,7 +178,8 @@ function tripal_make_view_compatible_with_external($view) {
   }
 
   // IF chado is external then remove all config relating to drupal tables
-  if (!chado_is_local()) {
+  $is_local = isset($GLOBALS["chado_is_local"]) && $GLOBALS["chado_is_local"];
+  if (!$is_local()) {
 
     // Iterate through all displays
     foreach ($view->display as $display_name => $display) {

+ 2 - 1
tripal_chado_views/tripal_chado_views.views.inc

@@ -616,7 +616,8 @@ function tripal_chado_views_views_data_alter(&$data) {
       $base_title = ucwords(str_replace('_', ' ', $base_table));
 
       // add in joins to the node tables if the Chado schema is local
-      if (chado_is_local()) {
+      $is_local = isset($GLOBALS["chado_is_local"]) && $GLOBALS["chado_is_local"];
+      if ($is_local) {
         // if a node linking table exists then add in the joins
         if (db_table_exists($linker_table)) {