function _node_access_rebuild_batch_operation in Drupal 7
Same name and namespace in other branches
- 8 core/modules/node/node.module \_node_access_rebuild_batch_operation()
- 6 modules/node/node.module \_node_access_rebuild_batch_operation()
- 9 core/modules/node/node.module \_node_access_rebuild_batch_operation()
- 10 core/modules/node/node.module \_node_access_rebuild_batch_operation()
Implements callback_batch_operation().
Performs batch operation for node_access_rebuild().
This is a multistep 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.
Parameters
array $context: An array of contextual key/value information for rebuild batch process.
Related topics
1 string reference to '_node_access_rebuild_batch_operation'
- node_access_rebuild in modules/
node/ node.module - Rebuilds the node access database.
File
- modules/
node/ node.module, line 3688 - 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_query('SELECT COUNT(nid) FROM {node}')
->fetchField();
}
// Process the next 20 nodes.
$limit = 20;
$nids = db_query_range("SELECT nid FROM {node} WHERE nid > :nid ORDER BY nid ASC", 0, $limit, array(
':nid' => $context['sandbox']['current_node'],
))
->fetchCol();
$nodes = node_load_multiple($nids, array(), TRUE);
foreach ($nodes as $nid => $node) {
// To preserve database integrity, only acquire grants if the node
// loads successfully.
if (!empty($node)) {
node_access_acquire_grants($node);
}
$context['sandbox']['progress']++;
$context['sandbox']['current_node'] = $nid;
}
// Multistep processing : report progress.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}