You are here

function _drush_node_revision_delete_validate_maximum_time 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_maximum_time()

Helper function to validate the maximum time.

Parameters

array $args: An array with number and time.

Return value

bool A boolean indicating the success of the validation.

2 calls to _drush_node_revision_delete_validate_maximum_time()
drush_node_revision_delete_nrd_minimum_age_to_delete_time_validate in ./node_revision_delete.drush.inc
Implements drush_hook_COMMAND_validate().
drush_node_revision_delete_nrd_when_to_delete_time_validate in ./node_revision_delete.drush.inc
Implements drush_hook_COMMAND_validate().

File

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

Code

function _drush_node_revision_delete_validate_maximum_time(array $args) {

  // If we don't have arguments we will return the config values.
  if (!count($args)) {
    return TRUE;
  }

  // Check for only 2 arguments.
  if (count($args) != 2) {
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', dt('This command use two arguments.'));
  }

  // Check for integer number.
  if (!ctype_digit($args[0])) {
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', dt('You must enter digits for the maximum number.'));
  }

  // Check for valid integer number.
  if ($args[0] < 1) {
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', dt('You must enter a digit no more less than 1 for the maximum number.'));
  }

  // Check for time.
  if (!in_array($args[1], [
    'days',
    'weeks',
    'months',
  ])) {
    return drush_set_error('NODE_REVISION_DELETE_INVALID_ARGUMENT', dt('The accepted time arguments are: days, weeks or months.'));
  }
}