You are here

function domain_set_primary_domain in Domain Access 7.3

Same name and namespace in other branches
  1. 6.2 domain.module \domain_set_primary_domain()
  2. 7.2 domain.module \domain_set_primary_domain()

Set the primary domain properly, if necessary.

3 calls to domain_set_primary_domain()
DomainTestCase::setUp in tests/domain.test
On setup, install our module and create a default domain.
domain_install in ./domain.install
Implements hook_install().
domain_overview_form in ./domain.admin.inc
Create an overview form for sorting domains and other quick actions.

File

./domain.module, line 1217
Core module functions for the Domain Access suite.

Code

function domain_set_primary_domain() {
  $root = strtolower(rtrim($_SERVER['HTTP_HOST']));
  if ($error = domain_valid_domain($root)) {
    return;
  }
  $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 is_default = 1")
    ->fetchField();
  if (empty($check)) {
    $domain = array(
      'subdomain' => $root,
      'sitename' => $site,
      'scheme' => $scheme,
      'weight' => -1,
      'valid' => 1,
      'is_default' => 1,
      'machine_name' => domain_machine_name($root),
    );
    drupal_write_record('domain_export', $domain);
    drupal_write_record('domain', $domain);
    module_invoke_all('domain_insert', $domain, array());
  }
}