aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php90
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php17
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
3namespace Wallabag\CoreBundle\Command;
4
5use Doctrine\ORM\NoResultException;
6use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface;
10use Symfony\Component\Console\Style\SymfonyStyle;
11use Wallabag\CoreBundle\Event\EntrySavedEvent;
12
13class 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