You are here

function og_access_invoke_node_access_acquire_grants in Organic groups 7.2

Batch API group content privacy change callback.

Parameters

$group_type: The group type to handle.

$group_id: The group id to handle.

$context: Batch API context.

1 string reference to 'og_access_invoke_node_access_acquire_grants'
og_access_handle_group_privacy_change in og_access/og_access.module
In case of group privacy change, create batch operation to update group content.

File

og_access/og_access.module, line 371
Enable access control for private and public groups and group content.

Code

function og_access_invoke_node_access_acquire_grants($group_type, $group_id, &$context) {
  if (empty($context['sandbox'])) {

    // Count relevant nodes.
    $query = new EntityFieldQuery();
    $total = $query
      ->entityCondition('entity_type', 'og_membership')
      ->propertyCondition('group_type', $group_type, '=')
      ->propertyCondition('entity_type', 'node', '=')
      ->propertyCondition('gid', $group_id, '=')
      ->count()
      ->execute();
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['last_id'] = 0;
    $context['sandbox']['total'] = $total;
  }
  $limit = 50;

  // Retrieve the next batch.
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'og_membership')
    ->propertyCondition('group_type', $group_type, '=')
    ->propertyCondition('entity_type', 'node', '=')
    ->range(0, $limit)
    ->propertyCondition('etid', $context['sandbox']['last_id'], '>')
    ->propertyCondition('gid', $group_id, '=')
    ->propertyOrderBy('etid', 'ASC')
    ->execute();

  // Mark "finished" if there are no more results.
  if (!isset($result['og_membership'])) {
    $context['finished'] = 1;
    return;
  }
  foreach (entity_load('og_membership', array_keys($result['og_membership'])) as $og_membership) {

    // Load the node group content and "refresh" its grants.
    $node = node_load($og_membership->etid);

    // Rebuild the permissions for the node.
    node_access_acquire_grants($node);
    $context['sandbox']['progress']++;
    $context['sandbox']['last_id'] = $node->nid;
  }
  $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['total'];
}