You are here

function drush_node_revision_delete_validate in Node Revision Delete 8

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

Implements drush_hook_COMMAND_validate().

File

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

Code

function drush_node_revision_delete_validate() {
  $args = func_get_args();

  // Make sure the content type exists and is configured.
  $available_content_types = array_map(function ($content_type) {

    /** @var \Drupal\node\NodeTypeInterface $availables_content_types */
    return $content_type
      ->id();
  }, Drupal::service('node_revision_delete')
    ->getConfiguredContentTypes());
  $not_available_content_types = array_diff($args, $available_content_types);
  if (count($not_available_content_types)) {
    $names = implode(', ', $not_available_content_types);
    $singular = "The following content type is not configured for revision deletion: @names";
    $plural = "The following content types are not configured for revision deletion: @names";
    $message = _node_revision_delete_drush_plural(count($not_available_content_types), $singular, $plural, [
      '@names' => $names,
    ]);
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', $message);
  }

  // Checking if we have candidates nodes to delete.
  $candidates = count(\Drupal::service('node_revision_delete')
    ->getCandidatesRevisions($args[0]));
  if (!$candidates) {
    drush_log(dt('There is not revisions to delete for @content_type.', [
      '@content_type' => $args[0],
    ], 'warning'));
    return FALSE;
  }
}