You are here

function domain_lookup in Domain Access 7.3

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

Runs a lookup against the {domain} table.

This function also calls hook_domain_load(), which lets module developers overwrite or add to the $domain array.

Note that this function should not be called prior to hook_init(). Lookups run too early in the bootstrap process can cause registry issues.

Parameters

$domain_id: The domain_id taken from {domain}. Optional, but one of the two values must be present

$subdomain: The string representation of a {domain} entry. Optional.

$reset: A boolean flag to clear the static variable if necessary.

Return value

An array containing the requested row from the {domain} table, plus the elements added by hook_domain_load(). Returns -1 on failure.

32 calls to domain_lookup()
DomainCreateTest::testDomainCreate in tests/domain.test
DomainHookTest::testDomainHooks in tests/domain.test
DomainInvalidTest::testDomainInvalid in tests/domain.test
domain_alias_init in domain_alias/domain_alias.module
Implements hook_init().
domain_block_view_server in ./domain.blocks.inc
Prints information about the current HTTP request.

... See full list

File

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

Code

function domain_lookup($domain_id = NULL, $subdomain = NULL, $reset = FALSE) {
  $domains =& drupal_static(__FUNCTION__ . '_domains');
  $result =& drupal_static(__FUNCTION__ . '_result');

  // Create a unique key so we can static cache all requests.
  $key = $domain_id . $subdomain;

  // Shortcut if we know the data.
  if (!$reset && isset($domains[$key])) {
    return $domains[$key];
  }

  // Get the data from the database. Doing this prevents extra queries.
  if (!isset($result) || $reset) {

    // Temporary hack for update to 7.x.3.
    if (db_table_exists('domain_export')) {
      $result = db_query("SELECT domain_id, subdomain, sitename, scheme, valid, weight, is_default, machine_name FROM {domain}", array(), array(
        'fetch' => PDO::FETCH_ASSOC,
      ))
        ->fetchAllAssoc('domain_id');
    }
    else {
      $result = db_query("SELECT domain_id, subdomain, sitename, scheme, valid, weight, is_default FROM {domain}", array(), array(
        'fetch' => PDO::FETCH_ASSOC,
      ))
        ->fetchAllAssoc('domain_id');
    }
  }

  // If both are NULL, no lookup can be run.
  if (is_null($domain_id) && is_null($subdomain) || $domain_id < 0) {
    $domains[$key] = -1;
  }
  elseif (!isset($domains[$key]) || $reset) {
    if ($subdomain) {
      foreach ($result as $array) {
        if ($array['subdomain'] == $subdomain) {
          $domain = $array;
        }
      }
    }
    elseif (isset($result[$domain_id])) {
      $domain = $result[$domain_id];
    }

    // Did we get a valid result?
    if (isset($domain['domain_id'])) {

      // Let Domain Access module extensions act to override the defaults.
      $domains[$key] = domain_api($domain, $reset);
    }
    else {
      $domains[$key] = -1;
    }
  }
  return $domains[$key];
}