You are here

function hook_domaincron in Domain Access 7.2

Same name and namespace in other branches
  1. 5 API.php \hook_domaincron()
  2. 6.2 API.php \hook_domaincron()

Enables Domain Access modules to fire cron hooks across all active domains.

Each module implementing this hook will have the function run once per active domain record. The global $_domain variable will be set to the current $domain passed as an argument.

This function is especially useful if you need to run node queries that obey node access rules.

Note that Domain Prefix and Domain Conf are activated by this hook. That means each domain will have its tables and variables loaded before your function fires.

Parameters

$domain: The information for the current domain record, taken from {domain}.

Related topics

1 invocation of hook_domaincron()
domain_cron in ./domain.module
Implements hook_cron()

File

./domain.api.php, line 167
API documentation file.

Code

function hook_domaincron($domain) {

  // Run a node query.
  $select = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ))
    ->condition('status', 1)
    ->orderBy('created', 'DESC')
    ->extend('PagerDefault')
    ->limit(1);

  // Note that we don't tag this query with 'node_access' because it is an
  // administrative query and we want to return all nodes for a specific domain.
  $select
    ->join('domain_access', 'da', 'n.nid = da.nid AND da.domain_id = :domain_id', array(
    ':domain_id' => $domain['domain_id'],
  ));
  $nid = $select
    ->execute()
    ->fetchCol();
  if ($node = node_load($nid)) {

    // Set a variable for each domain containing the last node updated.
    variable_set('domain_' . $domain['domain_id'] . '_lastnode', $node->nid);
  }
}