diff --git a/src/Commands/NodeRevisionDeleteCommands.php b/src/Commands/NodeRevisionDeleteCommands.php index 2d62cc99fffc431126eb74dce08dbe6711ec7e8c..7f26e63e13f5c4d561f5b86a9c3229901a76e5de 100644 --- a/src/Commands/NodeRevisionDeleteCommands.php +++ b/src/Commands/NodeRevisionDeleteCommands.php @@ -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; }