You are here

function node_revision_delete_batch_process in Node Revision Delete 7.2

Same name and namespace in other branches
  1. 7.3 node_revision_delete.batch.inc \node_revision_delete_batch_process()

Callback to delete revisions using Batch API.

2 string references to 'node_revision_delete_batch_process'
drush_node_revision_delete in ./node_revision_delete.drush.inc
Implements drush_COMMANDFILE_COMMANDNAME().
node_revision_delete_form_submit in ./node_revision_delete.admin.inc
Form submit handler for the settings form.

File

./node_revision_delete.batch.inc, line 11
Batch API callbacks for node_revision_delete module.

Code

function node_revision_delete_batch_process($content_type, $max_revisions, &$context) {
  if (!isset($context['sandbox']['nids'])) {

    // Set initial values.
    $context['sandbox']['nids'] = node_revision_delete_candidates($content_type, $max_revisions);
    $context['sandbox']['current'] = 0;
    $context['sandbox']['total'] = count($context['sandbox']['nids']);
  }

  // Perform the actual revision deletion.
  $nid = $context['sandbox']['nids'][$context['sandbox']['current']];
  $deleted_revisions = _node_revision_delete_do_delete($nid, $max_revisions);

  // Save results for final report.
  if (isset($context['results'][$nid])) {
    $context['results'][$nid] += $deleted_revisions->count;
  }
  else {
    $context['results'][$nid] = $deleted_revisions->count;
  }

  // Evaluate if we are done with the current node.
  if (empty($deleted_revisions->pending)) {
    $context['sandbox']['current']++;
  }

  // Inform the batch engine that we are not finished,
  // and provide an estimation of the completion level we reached.
  $context['finished'] = empty($context['sandbox']['nids']) ? 1 : $context['sandbox']['current'] / $context['sandbox']['total'];
}