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
;
11 use Wallabag\CoreBundle\Event\EntrySavedEvent
;
13 class ReloadEntryCommand
extends ContainerAwareCommand
15 protected function configure()
18 ->setName('wallabag:entry:reload')
19 ->setDescription('Reload entries')
20 ->setHelp('This command reload entries')
21 ->addArgument('username', InputArgument
::OPTIONAL
, 'Reload entries only for the given user')
25 protected function execute(InputInterface
$input, OutputInterface
$output)
27 $io = new SymfonyStyle($input, $output);
30 if ($username = $input->getArgument('username')) {
32 $userId = $this->getContainer()
33 ->get('wallabag_user.user_repository')
34 ->findOneByUserName($username)
36 } catch (NoResultException
$e) {
37 $io->error(sprintf('User "%s" not found.', $username));
43 $entryRepository = $this->getContainer()->get('wallabag_core.entry_repository');
44 $entryIds = $entryRepository->findAllEntriesIdByUserId($userId);
46 $nbEntries = count($entryIds);
48 $io->success('No entry to reload.');
55 "You're going to reload %s entries. Depending on the number of entry to reload, this could be a very long process.",
60 if (!$io->confirm('Are you sure you want to proceed?')) {
64 $progressBar = $io->createProgressBar($nbEntries);
66 $contentProxy = $this->getContainer()->get('wallabag_core.content_proxy');
67 $em = $this->getContainer()->get('doctrine')->getManager();
68 $dispatcher = $this->getContainer()->get('event_dispatcher');
70 $progressBar->start();
71 foreach ($entryIds as $entryId) {
72 $entry = $entryRepository->find($entryId);
74 $contentProxy->updateEntry($entry, $entry->getUrl());
78 $dispatcher->dispatch(EntrySavedEvent
::NAME
, new EntrySavedEvent($entry));
79 $progressBar->advance();
83 $progressBar->finish();
86 $io->success('Done.');