aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-08-22 11:21:04 +0200
committerGitHub <noreply@github.com>2017-08-22 11:21:04 +0200
commit54171dd796a6cedc076357e4eb62e6dc1ce6dd64 (patch)
tree9de9c091b90603ab73e8c264bd1fd7a26af35dbe /src/Wallabag
parent4d2758dfa0f12ff07da6cf907de7737f19219fea (diff)
parentdbf1188c5b78b7190cbfce2db00e08d5e69029ff (diff)
downloadwallabag-54171dd796a6cedc076357e4eb62e6dc1ce6dd64.tar.gz
wallabag-54171dd796a6cedc076357e4eb62e6dc1ce6dd64.tar.zst
wallabag-54171dd796a6cedc076357e4eb62e6dc1ce6dd64.zip
Merge pull request #3326 from nclsHart/reload-entry-command
Add reload entry command
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php2
-rw-r--r--src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php90
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php19
3 files changed, 109 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
index 1caaa391..b58909db 100644
--- a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
+++ b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
@@ -71,7 +71,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
71 $em = $this->getContainer()->get('doctrine.orm.entity_manager'); 71 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
72 $repo = $this->getContainer()->get('wallabag_core.entry_repository'); 72 $repo = $this->getContainer()->get('wallabag_core.entry_repository');
73 73
74 $entries = $repo->getAllEntriesIdAndUrl($user->getId()); 74 $entries = $repo->findAllEntriesIdAndUrlByUserId($user->getId());
75 75
76 $duplicatesCount = 0; 76 $duplicatesCount = 0;
77 $urls = []; 77 $urls = [];
diff --git a/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php b/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php
new file mode 100644
index 00000000..91998841
--- /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->findAllEntriesIdByUserId($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..eb5e3205 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -355,7 +355,7 @@ class EntryRepository extends EntityRepository
355 * Get id and url from all entries 355 * Get id and url from all entries
356 * Used for the clean-duplicates command. 356 * Used for the clean-duplicates command.
357 */ 357 */
358 public function getAllEntriesIdAndUrl($userId) 358 public function findAllEntriesIdAndUrlByUserId($userId)
359 { 359 {
360 $qb = $this->createQueryBuilder('e') 360 $qb = $this->createQueryBuilder('e')
361 ->select('e.id, e.url') 361 ->select('e.id, e.url')
@@ -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 findAllEntriesIdByUserId($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