Skip to content
Snippets Groups Projects
Commit 29683abb authored by Adrian Cid Almaguer's avatar Adrian Cid Almaguer
Browse files

Add confirmation message and delete validations.

parent 800f12ae
Branches node_revision_delete-2911851-2911851-drush-command-to
Tags
1 merge request!10Node revision delete 2911851 2911851 drush command to
......@@ -527,54 +527,35 @@ class NodeRevisionDeleteCommands extends DrushCommands {
* @command nrd:track
* @aliases nrd-t, nrd-track
*/
public function track(string $content_type, int $minimum_revisions_to_keep, int $minimum_age_to_delete, int $when_to_delete) {
// Content_type argument must be string.
if (!is_string($content_type)) {
$this->io()->error(dt('Argument content type must be string.'));
return FALSE;
}
public function track(string $content_type, int $minimum_revisions_to_keep, int $minimum_age_to_delete, int $when_to_delete): bool {
// Validate for a valid content type.
$content_types = $this->entityTypeManager->getStorage('node_type')->loadMultiple();
$content_types_ids = array_map(function(NodeType $object) { return $object->id(); }, $content_types);
$content_types_ids = array_map(function (NodeType $object) {
return $object->id();
}, $content_types);
if (!in_array($content_type, $content_types_ids)) {
$this->io()->error(dt('Argument content type is not a valid content type.'));
return FALSE;
}
// minimum_revisions_to_keep argument must be numeric.
if (!is_int($minimum_revisions_to_keep)) {
$this->io()->error(dt('Argument minimum_revisions_to_keep must be numeric.'));
return FALSE;
}
// minimum_age_to_delete argument must be numeric.
if (!is_int($minimum_age_to_delete)) {
$this->io()->error(dt('Argument minimum_age_to_delete must be numeric.'));
return FALSE;
}
// when_to_delete argument must be numeric.
if (!is_int($when_to_delete)) {
$this->io()->error(dt('Argument when_to_delete must be numeric.'));
return FALSE;
}
// Validate for Maximum number allowed.
$config = $this->configFactory->getEditable('node_revision_delete.settings');
$node_revision_delete_minimum_age_to_delete_time = $config->get('node_revision_delete_minimum_age_to_delete_time');
$node_revision_delete_when_to_delete_time = $config->get('node_revision_delete_when_to_delete_time');
if ($minimum_age_to_delete > $node_revision_delete_minimum_age_to_delete_time['max_number']) {
$this->io()->error(dt('Argument minimum_age_to_delete must lower than Maximum Age of revision to delete.'));
$this->io()->error(dt('Argument minimum_age_to_delete must lower or equal to @number', ['@number' => $node_revision_delete_minimum_age_to_delete_time['max_number']]));
return FALSE;
}
if ($when_to_delete > $node_revision_delete_when_to_delete_time['max_number']) {
$this->io()->error(dt('Argument when_to_delete must lower than Maximum of When to Delete.'));
$this->io()->error(dt('Argument when_to_delete must lower or equal to @number.', ['@number' => $node_revision_delete_when_to_delete_time['max_number']]));
return FALSE;
}
$this->nodeRevisionDelete->saveContentTypeConfig($content_type, $minimum_revisions_to_keep, $minimum_age_to_delete, $when_to_delete);
$message = dt('<info>The content type @content_type is now tracked.</info>', ['@content_type' => $content_type]);
$this->writeln($message);
return TRUE;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment