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=656d3969f461d0fa07298a3db186aa4283e5df1d;hp=ff04f05843783cd230356f77edbddd9c47cf47a6;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/drupal/console/src/Command/Create/CommentsCommand.php b/vendor/drupal/console/src/Command/Create/CommentsCommand.php index ff04f0584..656d3969f 100644 --- a/vendor/drupal/console/src/Command/Create/CommentsCommand.php +++ b/vendor/drupal/console/src/Command/Create/CommentsCommand.php @@ -6,24 +6,28 @@ namespace Drupal\Console\Command\Create; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command; -use Drupal\Console\Core\Command\Shared\CommandTrait; +use Drupal\Console\Annotations\DrupalCommand; use Drupal\Console\Command\Shared\CreateTrait; +use Drupal\Console\Core\Command\Command; use Drupal\Console\Utils\Create\CommentData; -use Drupal\Console\Core\Style\DrupalStyle; +use Drupal\node\Entity\Node; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Class CommentsCommand * * @package Drupal\Console\Command\Generate + * + * @DrupalCommand( + * extension = "comment", + * extensionType = "module" + * ) */ class CommentsCommand extends Command { use CreateTrait; - use CommandTrait; /** * @var CommentData @@ -72,7 +76,7 @@ class CommentsCommand extends Command null, InputOption::VALUE_OPTIONAL, $this->trans('commands.create.comments.options.time-range') - ); + )->setAliases(['crc']); } /** @@ -80,11 +84,9 @@ class CommentsCommand extends Command */ protected function interact(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - $nodeId = $input->getArgument('node-id'); if (!$nodeId) { - $nodeId = $io->ask( + $nodeId = $this->getIo()->ask( $this->trans('commands.create.comments.questions.node-id') ); $input->setArgument('node-id', $nodeId); @@ -92,7 +94,7 @@ class CommentsCommand extends Command $limit = $input->getOption('limit'); if (!$limit) { - $limit = $io->ask( + $limit = $this->getIo()->ask( $this->trans('commands.create.comments.questions.limit'), 25 ); @@ -101,7 +103,7 @@ class CommentsCommand extends Command $titleWords = $input->getOption('title-words'); if (!$titleWords) { - $titleWords = $io->ask( + $titleWords = $this->getIo()->ask( $this->trans('commands.create.comments.questions.title-words'), 5 ); @@ -113,7 +115,7 @@ class CommentsCommand extends Command if (!$timeRange) { $timeRanges = $this->getTimeRange(); - $timeRange = $io->choice( + $timeRange = $this->getIo()->choice( $this->trans('commands.create.comments.questions.time-range'), array_values($timeRanges) ); @@ -127,35 +129,55 @@ class CommentsCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - $nodeId = $input->getArgument('node-id')?:1; + $node = \Drupal\node\Entity\Node::load($nodeId); + if (empty($node)) { + throw new \InvalidArgumentException( + $this->trans( + 'commands.generate.controller.messages.node-id-invalid' + ) + ); + } $limit = $input->getOption('limit')?:25; $titleWords = $input->getOption('title-words')?:5; $timeRange = $input->getOption('time-range')?:31536000; - $comments = $this->createCommentData->create( + $result = $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'), - ]; + if ($result['success']) { - $io->table($tableHeader, $comments['success']); + $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->success( - sprintf( - $this->trans('commands.create.comments.messages.created-comments'), - $limit - ) - ); + $this->getIo()->table($tableHeader, $result['success']); + + $this->getIo()->success( + sprintf( + $this->trans('commands.create.comments.messages.created-comments'), + count($result['success']) + ) + ); + } + + if (isset($result['error'])) { + foreach ($result['error'] as $error) { + $this->getIo()->error( + sprintf( + $this->trans('commands.create.comments.messages.error'), + $error + ) + ); + } + } return 0; }