X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCreate%2FCommentsCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCreate%2FCommentsCommand.php;h=ff04f05843783cd230356f77edbddd9c47cf47a6;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Create/CommentsCommand.php b/vendor/drupal/console/src/Command/Create/CommentsCommand.php new file mode 100644 index 000000000..ff04f0584 --- /dev/null +++ b/vendor/drupal/console/src/Command/Create/CommentsCommand.php @@ -0,0 +1,162 @@ +createCommentData = $createCommentData; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('create:comments') + ->setDescription($this->trans('commands.create.comments.description')) + ->addArgument( + 'node-id', + InputOption::VALUE_REQUIRED, + $this->trans('commands.create.comments.arguments.node-id'), + null + ) + ->addOption( + 'limit', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.create.comments.options.limit') + ) + ->addOption( + 'title-words', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.create.comments.options.title-words') + ) + ->addOption( + 'time-range', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.create.comments.options.time-range') + ); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $nodeId = $input->getArgument('node-id'); + if (!$nodeId) { + $nodeId = $io->ask( + $this->trans('commands.create.comments.questions.node-id') + ); + $input->setArgument('node-id', $nodeId); + } + + $limit = $input->getOption('limit'); + if (!$limit) { + $limit = $io->ask( + $this->trans('commands.create.comments.questions.limit'), + 25 + ); + $input->setOption('limit', $limit); + } + + $titleWords = $input->getOption('title-words'); + if (!$titleWords) { + $titleWords = $io->ask( + $this->trans('commands.create.comments.questions.title-words'), + 5 + ); + + $input->setOption('title-words', $titleWords); + } + + $timeRange = $input->getOption('time-range'); + if (!$timeRange) { + $timeRanges = $this->getTimeRange(); + + $timeRange = $io->choice( + $this->trans('commands.create.comments.questions.time-range'), + array_values($timeRanges) + ); + + $input->setOption('time-range', array_search($timeRange, $timeRanges)); + } + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $nodeId = $input->getArgument('node-id')?:1; + $limit = $input->getOption('limit')?:25; + $titleWords = $input->getOption('title-words')?:5; + $timeRange = $input->getOption('time-range')?:31536000; + + $comments = $this->createCommentData->create( + $nodeId, + $limit, + $titleWords, + $timeRange + ); + + $tableHeader = [ + $this->trans('commands.create.comments.messages.node-id'), + $this->trans('commands.create.comments.messages.comment-id'), + $this->trans('commands.create.comments.messages.title'), + $this->trans('commands.create.comments.messages.created'), + ]; + + $io->table($tableHeader, $comments['success']); + + $io->success( + sprintf( + $this->trans('commands.create.comments.messages.created-comments'), + $limit + ) + ); + + return 0; + } +}