You are here

function drush_node_revision_delete_nrd_delete_prior_revisions in Node Revision Delete 8

Same name and namespace in other branches
  1. 7.3 node_revision_delete.drush.inc \drush_node_revision_delete_nrd_delete_prior_revisions()

Callback for nrd-delete-prior-revisions command.

Parameters

string|int $nid:

  • The nid of the node to delete.

string|int $vid:

  • The revision id which is used to find prior revisions.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

./node_revision_delete.drush.inc, line 453
Drush commands related to the Node Revision Delete module.

Code

function drush_node_revision_delete_nrd_delete_prior_revisions($nid, $vid) {
  if (drush_confirm(dt("Additionally, do you want to delete the revision @vid?", [
    '@vid' => $vid,
  ]))) {
    \Drupal::entityTypeManager()
      ->getStorage('node')
      ->deleteRevision($vid);
    drush_print(dt('The revision @vid was sucessfully deleted.', [
      '@vid' => $vid,
    ]));
  }

  // Get a list of revisions to delete.
  $revisions_before = \Drupal::service('node_revision_delete')
    ->getPreviousRevisions($nid, $vid);

  // Loop through the list of revisions, then delete them one by one.
  foreach ($revisions_before as $revision) {
    \Drupal::entityTypeManager()
      ->getStorage('node')
      ->deleteRevision($revision
      ->getRevisionId());
  }

  // Print out success message.
  // @TODO: Add a pluran message for the case only one revision is deleted.
  $message = dt('Successfully deleted @count revision(s) of node @nid.', [
    '@count' => count($revisions_before),
    '@nid' => $nid,
  ]);
  drush_print($message);
}