You are here

function _book_access_rebuild_batch_operation in Book access 6

1 string reference to '_book_access_rebuild_batch_operation'
book_access_permissions_form_submit in ./book_access.admin.inc
Submission callback for the administration settings.

File

./book_access.admin.inc, line 366
Administration interface for the Book access module.

Code

function _book_access_rebuild_batch_operation($bid, &$context) {
  if (empty($context['sandbox'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['current_node'] = 0;
    $context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT nid) FROM {book} WHERE bid = %d', $bid));
  }
  $result = db_query_range("SELECT nid FROM {book} WHERE nid > %d AND bid = %d ORDER BY nid ASC", $context['sandbox']['current_node'], $bid, 0, 20);
  while ($row = db_fetch_array($result)) {
    $loaded_node = node_load($row['nid'], NULL, TRUE);
    if (!empty($loaded_node)) {
      node_access_acquire_grants($loaded_node);
    }
    $context['sandbox']['progress']++;
    $context['sandbox']['current_node'] = $row['nid'];
    $context['message'] = t('Rebuilding access permissions for %title', array(
      '%title' => $loaded_node->title,
    ));
  }
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}