You are here

function drush_node_revision_delete_nrd_set_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_nrd_set_time()

Callback for the nrd-delete-set-time command.

File

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

Code

function drush_node_revision_delete_nrd_set_time($time = '') {

  // Getting an editable config because we will get and set a value.
  $config = \Drupal::service('config.factory')
    ->getEditable('node_revision_delete.settings');

  // Check for correct argument.
  $options = Time::convertWordToTime();
  if (!in_array($time, array_keys($options))) {
    if (!empty($time)) {
      drush_log(dt('"@time_value" is not a valid time argument.', [
        '@time_value' => $time,
      ]), 'warning');
    }
    $time = drush_choice(\Drupal::service('node_revision_delete')
      ->getTimeValues(), dt('Choose the frequency with which to delete revisions while cron is running:'));
  }
  else {
    $time = $options[$time];
  }

  // Saving the values in the config.
  $config
    ->set('node_revision_delete_time', $time);
  $config
    ->save();
  $time_value = \Drupal::service('node_revision_delete')
    ->getTimeValues($time);
  $message = dt('The frequency with which to delete revisions while cron is running was set to: @time.', [
    '@time' => $time_value,
  ]);
  drush_log($message, 'success');
}