You are here

function node_revision_delete_batch_process in Node Revision Delete 7.3

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

Process for one batch step, deleting a revision.

Parameters

string $content_type: Content type machine name.

int $minimum_revisions_to_keep: Minimum number of revisions to keep.

int $minimum_age_to_delete: Minimum age in months of revision to delete.

int $when_to_delete: Number of inactivity months to wait for delete a revision.

bool $dry_run: Boolean to know if we must delete the revision or only show how the will works.

array|\ArrayObject $context: The context.

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_admin_settings_form_submit in ./node_revision_delete.admin.inc
Form submit handler for the Node Revision Delete administration form.

File

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

Code

function node_revision_delete_batch_process($content_type, $minimum_revisions_to_keep, $minimum_age_to_delete, $when_to_delete, $dry_run, &$context) {
  if (!isset($context['sandbox']['nids'])) {

    // Set initial values.
    $candidates = _node_revision_delete_candidates($content_type, $minimum_revisions_to_keep, $minimum_age_to_delete, $when_to_delete);
    $context['sandbox']['nids'] = array_values(array_unique(array_column($candidates, 'nid')));
    $context['sandbox']['current'] = 0;
    $context['sandbox']['total'] = count($candidates);
  }

  // Perform the actual revision deletion.
  $nid = $context['sandbox']['nids'][$context['sandbox']['current']];
  if (isset($nid)) {
    $deleted_revisions = _node_revision_delete_do_delete($nid, $minimum_revisions_to_keep, $dry_run);
  }

  // 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'];
}