public function NodeRevisionDeleteCommands::setTime in Node Revision Delete 8
Configures the frequency with which to delete revisions while cron run.
@usage nrd-set-time Show a list to select the frequency with which to delete revisions while cron is running. @usage nrd-set-time every_time Configure the module to delete revisions every time the cron runs.
@command nrd:set-time @aliases nrd-st, nrd-set-time
Parameters
string $time: The time value (never, every_hour, every_time, everyday, every_week, every_10_days, every_15_days, every_month, every_3_months, every_6_months, every_year or every_2_years)
Throws
\Drush\Exceptions\UserAbortException
File
- src/
Commands/ NodeRevisionDeleteCommands.php, line 189
Class
- NodeRevisionDeleteCommands
- Class NodeRevisionDeleteCommands.
Namespace
Drupal\node_revision_delete\CommandsCode
public function setTime($time = '') {
// Getting an editable config because we will get and set a value.
$config = $this->configFactory
->getEditable('node_revision_delete.settings');
// Check for correct argument.
$options = Time::convertWordToTime();
$options_keys = array_keys($options);
if (!in_array($time, $options_keys)) {
if (!empty($time)) {
$this
->writeln(dt('"@time_value" is not a valid time argument.', [
'@time_value' => $time,
]));
}
$choice = $this
->io()
->choice(dt('Choose the frequency with which to delete revisions while cron is running:'), $this->nodeRevisionDelete
->getTimeValues());
$time = $options[$options_keys[$choice]];
}
else {
$time = $options[$time];
}
// Saving the values in the config.
$config
->set('node_revision_delete_time', $time);
$config
->save();
// Getting the values from the config.
$time_value = $this->nodeRevisionDelete
->getTimeValues($time);
$message = dt('<info>The frequency with which to delete revisions while cron is running was set to: @time.</info>', [
'@time' => $time_value,
]);
$this
->writeln($message);
}