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
;
11 class TagAllCommand
extends ContainerAwareCommand
13 protected function configure()
16 ->setName('wallabag:tag:all')
17 ->setDescription('Tag all entries using the tagging rules.')
20 InputArgument
::REQUIRED
,
21 'User to tag entries for.'
26 protected function execute(InputInterface
$input, OutputInterface
$output)
29 $user = $this->getUser($input->getArgument('username'));
30 } catch (NoResultException
$e) {
31 $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username')));
35 $tagger = $this->getContainer()->get('wallabag_core.rule_based_tagger');
37 $output->write(sprintf('Tagging entries for user « <comment>%s</comment> »... ', $user->getUserName()));
39 $entries = $tagger->tagAllForUser($user);
41 $output->writeln('<info>Done.</info>');
42 $output->write(sprintf('Persist entries ... ', $user->getUserName()));
44 $em = $this->getDoctrine()->getManager();
45 foreach ($entries as $entry) {
50 $output->writeln('<info>Done.</info>');
54 * Fetches a user from its username.
56 * @param string $username
58 * @return \Wallabag\UserBundle\Entity\User
60 private function getUser($username)
62 return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
65 private function getDoctrine()
67 return $this->getContainer()->get('doctrine');