From 6790c7bdb1ceb44e002113582a7ce49da2189372 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 20 Dec 2020 01:17:49 +0300 Subject: [PATCH] #21 Adding 'invite:add' command. --- src/Command/AddInvitesCommand.php | 60 +++++++++++++++++++++++++++++++ src/Command/AddUserCommand.php | 4 +-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/Command/AddInvitesCommand.php diff --git a/src/Command/AddInvitesCommand.php b/src/Command/AddInvitesCommand.php new file mode 100644 index 0000000..6e59685 --- /dev/null +++ b/src/Command/AddInvitesCommand.php @@ -0,0 +1,60 @@ +em = $em; + $this->userRepo = $userRepo; + $this->inviteManager = $inviteManager; + } + + protected function configure() + { + $this + ->setName('invite:add') + ->addArgument('username', InputArgument::REQUIRED, 'Username') + ->addArgument('number', InputArgument::REQUIRED, 'Number of invites') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $username = $input->getArgument('username'); + $number = $input->getArgument('number'); + + if (null === $user = $this->userRepo->findOneBy(['username' => $username])) { + $output->writeln('User not found.'); + + return 1; + } + + $this->inviteManager->createInvitesForUser($user, $number); + + $this->em->flush(); + + $output->writeln(sprintf('%d invites added to \'%s\'.', $number, $user->getUsername())); + + return 0; + } +} diff --git a/src/Command/AddUserCommand.php b/src/Command/AddUserCommand.php index e84536b..7609362 100644 --- a/src/Command/AddUserCommand.php +++ b/src/Command/AddUserCommand.php @@ -66,7 +66,7 @@ class AddUserCommand extends Command } if (!$password) { - $output->writeln('User password cannot be empty.'); + $output->writeln('User password cannot be empty.'); return 1; } @@ -86,7 +86,7 @@ class AddUserCommand extends Command $this->em->flush(); - $output->writeln(sprintf('User \'%s\' registered, %d invites added.', $user->getUsername(), $invites)); + $output->writeln(sprintf('User \'%s\' registered, %d invites added.', $user->getUsername(), $invites)); return 0; }