You are here

function drush_node_revision_delete_validate in Node Revision Delete 7.3

Same name and namespace in other branches
  1. 8 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 149

Code

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

  // Make sure the content type exists.
  $content_types = node_type_get_names();
  $content_types_machine_name = array_keys($content_types);
  if (!in_array($args[0], $content_types_machine_name)) {
    return drush_set_error('NODE_REVISION_DELETE_WRONG_TYPE', dt('The content type "@type" does not exist. Available content types are @types', array(
      '@type' => $args[0],
      '@types' => implode(', ', $content_types_machine_name),
    )));
  }

  // Make sure the minimum number of revisions is a positive integer.
  if (!_node_revision_delete_is_integer_positive($args[1])) {
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', dt('The minimum number of revisions to keep must be a positive integer.'));
  }

  // Make sure the minimum age of revisions to be deleted is a integer number.
  if (!ctype_digit($args[2])) {
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', dt('You must enter digits for the minimum age of revisions to be deleted.'));
  }

  // Make sure the minimum inactivity age to wait for delete a revision is a
  // integer number.
  if (!ctype_digit($args[3])) {
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', dt('You must enter digits for the minimum inactivity age to wait for delete a revision.'));
  }

  // Validating the dry-run param.
  if (!empty($args[4]) && !ctype_digit($args[4]) && !in_array($args[4], array(
    0,
    1,
  ), TRUE)) {
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', dt('The dry run parameter must be a boolean (0 or 1).'));
  }
}