function domain_set_primary_domain in Domain Access 7.2
Same name and namespace in other branches
- 6.2 domain.module \domain_set_primary_domain()
- 7.3 domain.module \domain_set_primary_domain()
Set the primary domain properly, if necessary.
1 call to domain_set_primary_domain()
- domain_configure_form in ./
domain.admin.inc - FormsAPI for configuring the domain module.
File
- ./
domain.module, line 910 - Core module functions for the Domain Access suite.
Code
function domain_set_primary_domain() {
$root = strtolower(rtrim($_SERVER['SERVER_NAME']));
$site = variable_get('site_name', 'Drupal');
$scheme = 'http';
if (!empty($_SERVER['HTTPS'])) {
$scheme = 'https';
}
$check = (bool) db_query("SELECT COUNT(domain_id) FROM {domain} WHERE domain_id = :domain_id", array(
':domain_id' => 0,
))
->fetchField();
if (empty($check)) {
db_insert('domain')
->fields(array(
'subdomain' => $root,
'sitename' => $site,
'scheme' => $scheme,
'valid' => 1,
))
->execute();
// MySQL won't let us insert row 0 into an autoincrement table.
// Similar to the {users} table, this leaves us with no row 1.
db_update('domain')
->fields(array(
'domain_id' => 0,
))
->condition('domain_id', 1)
->execute();
}
else {
db_update('domain')
->fields(array(
'subdomain' => $root,
'sitename' => $site,
'scheme' => $scheme,
'valid' => 1,
))
->condition('domain_id', 0)
->execute();
}
// Set the default domain variables.
variable_set('domain_root', $root);
variable_set('domain_scheme', $scheme);
variable_set('domain_sitename', $site);
// Allow other modules to respond to changes.
module_invoke_all('domainupdate', 'update', domain_default(TRUE));
}