diff options
author | Nicolas Hart <contact@nclshart.net> | 2017-08-21 10:36:56 +0200 |
---|---|---|
committer | Nicolas Hart <contact@nclshart.net> | 2017-08-21 10:45:48 +0200 |
commit | 511f1ce1e87e0f30a455ca6ed73e008bfd557f83 (patch) | |
tree | d108bbcb2c285c7d9313fcfa4b42b7fe3fabffd2 /src/Wallabag | |
parent | 4d2758dfa0f12ff07da6cf907de7737f19219fea (diff) | |
download | wallabag-511f1ce1e87e0f30a455ca6ed73e008bfd557f83.tar.gz wallabag-511f1ce1e87e0f30a455ca6ed73e008bfd557f83.tar.zst wallabag-511f1ce1e87e0f30a455ca6ed73e008bfd557f83.zip |
Add reload entry command
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php | 90 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 17 |
2 files changed, 107 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php b/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php new file mode 100644 index 00000000..83887224 --- /dev/null +++ b/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php | |||
@@ -0,0 +1,90 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Command; | ||
4 | |||
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; | ||
12 | |||
13 | class ReloadEntryCommand extends ContainerAwareCommand | ||
14 | { | ||
15 | protected function configure() | ||
16 | { | ||
17 | $this | ||
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') | ||
22 | ; | ||
23 | } | ||
24 | |||
25 | protected function execute(InputInterface $input, OutputInterface $output) | ||
26 | { | ||
27 | $io = new SymfonyStyle($input, $output); | ||
28 | |||
29 | $userId = null; | ||
30 | if ($username = $input->getArgument('username')) { | ||
31 | try { | ||
32 | $userId = $this->getContainer() | ||
33 | ->get('wallabag_user.user_repository') | ||
34 | ->findOneByUserName($username) | ||
35 | ->getId(); | ||
36 | } catch (NoResultException $e) { | ||
37 | $io->error(sprintf('User "%s" not found.', $username)); | ||
38 | |||
39 | return 1; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | $entryRepository = $this->getContainer()->get('wallabag_core.entry_repository'); | ||
44 | $entryIds = $entryRepository->getAllEntriesId($userId); | ||
45 | |||
46 | $nbEntries = count($entryIds); | ||
47 | if (!$nbEntries) { | ||
48 | $io->success('No entry to reload.'); | ||
49 | |||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | $io->note( | ||
54 | sprintf( | ||
55 | "You're going to reload %s entries. Depending on the number of entry to reload, this could be a very long process.", | ||
56 | $nbEntries | ||
57 | ) | ||
58 | ); | ||
59 | |||
60 | if (!$io->confirm('Are you sure you want to proceed?')) { | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | $progressBar = $io->createProgressBar($nbEntries); | ||
65 | |||
66 | $contentProxy = $this->getContainer()->get('wallabag_core.content_proxy'); | ||
67 | $em = $this->getContainer()->get('doctrine')->getManager(); | ||
68 | $dispatcher = $this->getContainer()->get('event_dispatcher'); | ||
69 | |||
70 | $progressBar->start(); | ||
71 | foreach ($entryIds as $entryId) { | ||
72 | $entry = $entryRepository->find($entryId); | ||
73 | |||
74 | $contentProxy->updateEntry($entry, $entry->getUrl()); | ||
75 | $em->persist($entry); | ||
76 | $em->flush(); | ||
77 | |||
78 | $dispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | ||
79 | $progressBar->advance(); | ||
80 | |||
81 | $em->detach($entry); | ||
82 | } | ||
83 | $progressBar->finish(); | ||
84 | |||
85 | $io->newLine(2); | ||
86 | $io->success('Done.'); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | } | ||
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index d70d6ca6..9a30cd79 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -365,6 +365,23 @@ class EntryRepository extends EntityRepository | |||
365 | } | 365 | } |
366 | 366 | ||
367 | /** | 367 | /** |
368 | * @param int $userId | ||
369 | * | ||
370 | * @return array | ||
371 | */ | ||
372 | public function getAllEntriesId($userId = null) | ||
373 | { | ||
374 | $qb = $this->createQueryBuilder('e') | ||
375 | ->select('e.id'); | ||
376 | |||
377 | if (null !== $userId) { | ||
378 | $qb->where('e.user = :userid')->setParameter(':userid', $userId); | ||
379 | } | ||
380 | |||
381 | return $qb->getQuery()->getArrayResult(); | ||
382 | } | ||
383 | |||
384 | /** | ||
368 | * Find all entries by url and owner. | 385 | * Find all entries by url and owner. |
369 | * | 386 | * |
370 | * @param $url | 387 | * @param $url |