_node_access_rebuild_batch_operation(&$context)
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.
array $context: An array of contextual key/value information for rebuild batch process.
function _node_access_rebuild_batch_operation(&$context) { $node_storage = \Drupal::entityManager()->getStorage('node'); if (empty($context['sandbox'])) { // Initiate multistep processing. $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; $context['sandbox']['max'] = \Drupal::entityQuery('node')->count()->execute(); } // Process the next 20 nodes. $limit = 20; $nids = \Drupal::entityQuery('node') ->condition('nid', $context['sandbox']['current_node'], '>') ->sort('nid', 'ASC') // Disable access checking since all nodes must be processed even if the // user does not have access. And unless the current user has the bypass // node access permission, no nodes are accessible since the grants have // just been deleted. ->accessCheck(FALSE) ->range(0, $limit) ->execute(); $node_storage->resetCache($nids); $nodes = Node::loadMultiple($nids); foreach ($nodes as $nid => $node) { // To preserve database integrity, only write grants if the node // loads successfully. if (!empty($node)) { /** @var \Drupal\node\NodeAccessControlHandlerInterface $access_control_handler */ $access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node'); $grants = $access_control_handler->acquireGrants($node); \Drupal::service('node.grant_storage')->write($node, $grants); } $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']; } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!node!node.module/function/_node_access_rebuild_batch_operation/8.1.x