Commit 175fb3e1 authored by Adrian Cid Almaguer's avatar Adrian Cid Almaguer
Browse files

Issue #2888577 by adriancid, Andreas Radloff: Add a dry-run option

parent 54d10236
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ Node Revision Delete 7.x-3.0-alpha2, 2017-XX-XX
-----------------------------------------------
Changes since 7.x-3.0-alpha1:

- #2888577 by adriancid, Andreas Radloff: Add a dry-run option.
- #2888217 by gmaltoni, adriancid: Fix javascript coding standard format.
- #2888159 by adriancid: Drush command to get how many revisions will be deleted
  per cron run.
+18 −0
Changes for node_revision_delete.admin.inc: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -248,12 +248,29 @@ function node_revision_delete_admin_settings_form(array $form, array &$form_stat
    $disabled = TRUE;
    $description = t('There not exists candidates nodes with revisions to delete.');
  }

  $form['run_now'] = array(
    '#type' => 'checkbox',
    '#title' => t('Delete revisions now'),
    '#description' => $description,
    '#disabled' => $disabled,
  );

  $form['dry_run'] = array(
    '#type' => 'checkbox',
    '#title' => t('Dry run'),
    '#description' => t('Test run without deleting revisions but seeing the output results.'),
    '#states' => array(
      // Hide the dry run option when the run now checkbox is disabled.
      'visible' => array(
        ':input[name="run_now"]' => array('checked' => TRUE),
      ),
      'unchecked' => array(
        ':input[name="run_now"]' => array('checked' => TRUE),
      ),
    ),
  );

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
@@ -306,6 +323,7 @@ function node_revision_delete_admin_settings_form_submit(array $form, array &$fo
          $content_type_info['minimum_revisions_to_keep'],
          $content_type_info['minimum_age_to_delete'],
          $content_type_info['when_to_delete'],
          $form_state['values']['dry_run'],
        ),
      );
    }
+2 −2
Changes for node_revision_delete.batch.inc: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
/**
 * Callback to delete revisions using Batch API.
 */
function node_revision_delete_batch_process($content_type, $minimum_revisions_to_keep, $minimum_age_to_delete, $when_to_delete, &$context) {
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.
    $context['sandbox']['nids'] = _node_revision_delete_candidates($content_type, $minimum_revisions_to_keep, $minimum_age_to_delete, $when_to_delete);
@@ -18,7 +18,7 @@ function node_revision_delete_batch_process($content_type, $minimum_revisions_to

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

  // Save results for final report.
  if (isset($context['results'][$nid])) {
+2 −2
Changes for node_revision_delete.module: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -527,7 +527,7 @@ function node_revision_delete_cron() {
 *   and pending containing a boolean where TRUE means that there
 *   are more revisions to delete for this node.
 */
function _node_revision_delete_do_delete($nid, $minimum_revisions_to_keep, $max = 50) {
function _node_revision_delete_do_delete($nid, $minimum_revisions_to_keep, $dry_run, $max = 50) {
  $node = new stdClass();
  $node->nid = $nid;
  $revisions = node_revision_list($node);
@@ -542,7 +542,7 @@ function _node_revision_delete_do_delete($nid, $minimum_revisions_to_keep, $max
  $deleted_revisions->pending = FALSE;
  foreach ($revisions as $revision) {
    $revision_id = $revision->vid;
    if (node_revision_delete($revision_id)) {
    if ($dry_run ? $dry_run : node_revision_delete($revision_id)) {
      $deleted_revisions->count++;
      // Stop deleting if we hit the limit per cron run.
      if ($deleted_revisions->count == $max) {