function domain_prefix_domain_bootstrap_full in Domain Access 6.2
Implementats hook_domain_bootstrap_full().
File
- domain_prefix/
domain_prefix.module, line 28 - Interface for selective table prefixing for use with Domain Access.
Code
function domain_prefix_domain_bootstrap_full($domain) {
// We must make sure that we can reset the $db_prefix to that
// provided by settings.php, which is available the first time this
// function is called.
static $original_prefix;
global $db_prefix;
if (!isset($original_prefix)) {
$original_prefix = $db_prefix;
}
// Now load the dynamic tables.
$tables = array();
$prefix = 'domain_' . $domain['domain_id'] . '_';
$result = db_query("SELECT tablename FROM {domain_prefix} WHERE domain_id = %d AND status > %d", $domain['domain_id'], 1);
while ($data = db_fetch_array($result)) {
$tables[] = $data['tablename'];
}
if (!empty($tables)) {
$new_prefix = array();
// There might be global prefixing; if so, prepend the global.
if (is_string($db_prefix)) {
$new_prefix['default'] = $db_prefix;
$prefix = $db_prefix . $prefix;
}
foreach ($tables as $table) {
$new_prefix[$table] = $prefix;
}
// Keep existing $db_prefix values as they were defined in settings.php,
// in case they're not overwritten in $new_prefix.
// See http://drupal.org/node/632950 for background.
if (is_array($db_prefix)) {
$db_prefix = array_merge($db_prefix, $new_prefix);
}
else {
$db_prefix = $new_prefix;
}
}
else {
$db_prefix = $original_prefix;
}
// This function may already be loaded, see http://drupal.org/node/929540.
if (function_exists('domain_prefix_domainpath')) {
return;
}
// Check for prefixes of the url_alias table, and if present add hook_domainprefix().
$count = db_result(db_query("SELECT 1 FROM {domain_prefix} WHERE status > 1 AND tablename = 'url_alias'"));
if ($count > 0) {
include 'domain_prefix.path.inc';
}
}