3 namespace Wallabag\CoreBundle\Command
;
5 use Doctrine\ORM\NoResultException
;
6 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
7 use Symfony\Component\Console\Input\InputArgument
;
8 use Symfony\Component\Console\Input\InputInterface
;
9 use Symfony\Component\Console\Output\OutputInterface
;
10 use Symfony\Component\Console\Style\SymfonyStyle
;
12 class TagAllCommand
extends ContainerAwareCommand
14 protected function configure()
17 ->setName('wallabag:tag:all')
18 ->setDescription('Tag all entries using the tagging rules.')
21 InputArgument
::REQUIRED
,
22 'User to tag entries for.'
27 protected function execute(InputInterface
$input, OutputInterface
$output)
29 $io = new SymfonyStyle($input, $output);
32 $user = $this->getUser($input->getArgument('username'));
33 } catch (NoResultException
$e) {
34 $io->error(sprintf('User "%s" not found.', $input->getArgument('username')));
38 $tagger = $this->getContainer()->get('wallabag_core.rule_based_tagger');
40 $io->text(sprintf('Tagging entries for user <info>%s</info>...', $user->getUserName()));
42 $entries = $tagger->tagAllForUser($user);
44 $io->text('Persist entries... ');
46 $em = $this->getDoctrine()->getManager();
47 foreach ($entries as $entry) {
52 $io->success('Done.');
58 * Fetches a user from its username.
60 * @param string $username
62 * @return \Wallabag\UserBundle\Entity\User
64 private function getUser($username)
66 return $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($username);
69 private function getDoctrine()
71 return $this->getContainer()->get('doctrine');