You are here

function _pm_permission_node_access_rebuild_batch_operation in Drupal PM (Project Management) 8

Same name and namespace in other branches
  1. 7.3 includes/pm.permission.inc \_pm_permission_node_access_rebuild_batch_operation()

Custom batch operation for rebuilding permission.

See also

pm_permission_hunt_and_update_all_child_permission()

1 string reference to '_pm_permission_node_access_rebuild_batch_operation'
pm_permission_hunt_and_update_all_child_permission in includes/pm.permission.inc
Check and performs access update if supplied pmorganization.

File

includes/pm.permission.inc, line 788
Main module file for the pm_permission module.

Code

function _pm_permission_node_access_rebuild_batch_operation($nids, &$context) {
  if (empty($context['sandbox'])) {

    // Initiate multistep processing.
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = count($nids);
    $context['sandbox']['nids'] = drupal_map_assoc($nids);
    if (empty($nids)) {
      $context['finished'] = 1;
      return;
    }
  }
  $nids = array_slice($context['sandbox']['nids'], 0, 20);
  $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);
    }
    unset($context['sandbox']['nids'][$nid]);
    $context['sandbox']['progress']++;
    $context['message'] = t('Now processing %node', array(
      '%node' => $node->title,
    ));
  }

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