You are here

function hook_domain_cron in Domain Access 7.3

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 function implements hook_domain_cron()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

domain_test_domain_cron in tests/domain_test.domain.inc
Implements hook_domain_cron().
2 invocations of hook_domain_cron()
DomainHookTest::testDomainHooks in tests/domain.test
domain_cron in ./domain.module
Implements hook_cron().

File

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

Code

function hook_domain_cron($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);
  }
}