? 469856-domain-conf-variable-get.patch
? 469856-primary-table.patch
? 469856_contributions-modules-domain-HEAD_0.patch
? 486370-lang.patch
Index: domain.bootstrap.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.bootstrap.inc,v
retrieving revision 1.8
diff -u -p -r1.8 domain.bootstrap.inc
--- domain.bootstrap.inc	1 May 2009 19:25:18 -0000	1.8
+++ domain.bootstrap.inc	28 Jun 2009 15:14:51 -0000
@@ -81,7 +81,8 @@ function _domain_bootstrap($phase) {
       // Make sure database is loaded
       _drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
       // If the module has been disabled, stop loading.
-      $check = db_result(db_query("SELECT status FROM {system} WHERE name = 'domain' AND type = 'module'"));
+      $table = domain_get_primary_table('system');
+      $check = db_result(db_query("SELECT status FROM $table WHERE name = 'domain' AND type = 'module'"));
       if (empty($check)) {
         return NULL;
       }
@@ -164,7 +165,8 @@ function _domain_bootstrap_modules_load(
 function _domain_bootstrap_modules_get() {
   global $conf;
   $key = 'domain_bootstrap_modules';
-  $conf[$key] = unserialize(db_result(db_query("SELECT value FROM {variable} WHERE name = '%s'", $key)));
+  $table = domain_get_primary_table('variable');
+  $conf[$key] = unserialize(db_result(db_query("SELECT value FROM $table WHERE name = '%s'", $key)));
   return $conf[$key];
 }
 
@@ -205,3 +207,34 @@ function _domain_bootstrap_invoke_all() 
   }
   return $return;
 }
+
+/**
+ * Escape the names of the default tables for variable lookups.
+ *
+ * There are a few cases where we must directly query data from the
+ * primary site's database. Due to table prefixing and Domain Prefix, we
+ * must ensure that we are querying the correct table.
+ *
+ * When using this function, you should insert the $table result directly
+ * into your query string, or use token replacement '%s' syntax. Do not
+ * enclose the table name in brackets {}, as that defeats the purpose of
+ * this function.
+ *
+ * @see _domain_conf_load_primary()
+ *
+ * @param $table
+ *   The name of the base table to lookup.
+ * @return
+ *   A query-safe table name pointing to the primary domain.
+ */
+function domain_get_primary_table($table) {
+  global $db_prefix;
+  if (is_string($db_prefix)) {
+    $table = $db_prefix . $table;
+  }
+  else if (is_array($db_prefix)) {
+    $table = $db_prefix['default'] . $table;
+  }
+  return db_escape_table($table);
+}
+
Index: domain_conf/domain_conf.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_conf/domain_conf.module,v
retrieving revision 1.46
diff -u -p -r1.46 domain_conf.module
--- domain_conf/domain_conf.module	14 Jun 2009 19:29:49 -0000	1.46
+++ domain_conf/domain_conf.module	28 Jun 2009 15:14:54 -0000
@@ -600,25 +600,26 @@ function domain_conf_language_options() 
  *   Otherwise, return the settings data for the primary domain.
  */
 function _domain_conf_load_primary($unset = FALSE) {
-  global $db_prefix;
   static $settings;
 
-  if (empty($settings)) {
-    $cache = 'cache';
+  if (!isset($settings)) {
     // Account for table prefixing.
-    if (empty($db_prefix)) {
-      $cache_table = $cache;
-    }
-    else if (is_string($db_prefix)) {
-      $cache_table = $db_prefix . $cache;
+    $cache_table = domain_get_primary_table('cache');
+    // Load the query.
+    $data = db_result(db_query("SELECT data FROM $cache_table WHERE cid = 'variables'"));
+    if (!empty($data)) {
+      $settings = unserialize($data);
     }
+    // If the cache has been cleared, this data will be empty.
+    // In this case, grab the data directly from the base {variable} table.
     else {
-      $cache_table = $db_prefix['default'] . $cache;
+      $variable_table = domain_get_primary_table('variable');
+      $result = db_query("SELECT name, value FROM $variable_table");
+      while ($vars = db_fetch_array($result)) {
+        $data[$vars['name']] = unserialize($vars['value']);
+      }
+      $settings = $data;
     }
-    $cache_table = db_escape_table($cache_table);
-    // Load the query.
-    $data = db_result(db_query("SELECT data FROM $cache_table WHERE cid = 'variables'"));
-    $settings = unserialize($data);
   }
   // Do we reset the global or just return data?
   if ($unset) {
