You are here

function _node_access_rebuild_batch_operation in Drupal 6

Same name and namespace in other branches
  1. 8 core/modules/node/node.module \_node_access_rebuild_batch_operation()
  2. 7 modules/node/node.module \_node_access_rebuild_batch_operation()
  3. 9 core/modules/node/node.module \_node_access_rebuild_batch_operation()

Batch operation for node_access_rebuild_batch.

This is a mutlistep operation : we go through all nodes by packs of 20. The batch processing engine interrupts processing and sends progress feedback after 1 second execution time.

Related topics

1 string reference to '_node_access_rebuild_batch_operation'
node_access_rebuild in modules/node/node.module
Rebuild the node access database. This is occasionally needed by modules that make system-wide changes to access levels.

File

modules/node/node.module, line 2380
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function _node_access_rebuild_batch_operation(&$context) {
  if (empty($context['sandbox'])) {

    // Initiate multistep processing.
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['current_node'] = 0;
    $context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT nid) FROM {node}'));
  }

  // Process the next 20 nodes.
  $limit = 20;
  $result = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit);
  while ($row = db_fetch_array($result)) {
    $loaded_node = node_load($row['nid'], NULL, TRUE);

    // To preserve database integrity, only aquire grants if the node
    // loads successfully.
    if (!empty($loaded_node)) {
      node_access_acquire_grants($loaded_node);
    }
    $context['sandbox']['progress']++;
    $context['sandbox']['current_node'] = $row['nid'];
  }

  // Multistep processing : report progress.
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}