diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php index b4aa4e47..b58909db 100644 --- a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php +++ b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php | |||
@@ -7,13 +7,14 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |||
7 | use Symfony\Component\Console\Input\InputArgument; | 7 | use Symfony\Component\Console\Input\InputArgument; |
8 | use Symfony\Component\Console\Input\InputInterface; | 8 | use Symfony\Component\Console\Input\InputInterface; |
9 | use Symfony\Component\Console\Output\OutputInterface; | 9 | use Symfony\Component\Console\Output\OutputInterface; |
10 | use Symfony\Component\Console\Style\SymfonyStyle; | ||
10 | use Wallabag\CoreBundle\Entity\Entry; | 11 | use Wallabag\CoreBundle\Entity\Entry; |
11 | use Wallabag\UserBundle\Entity\User; | 12 | use Wallabag\UserBundle\Entity\User; |
12 | 13 | ||
13 | class CleanDuplicatesCommand extends ContainerAwareCommand | 14 | class CleanDuplicatesCommand extends ContainerAwareCommand |
14 | { | 15 | { |
15 | /** @var OutputInterface */ | 16 | /** @var SymfonyStyle */ |
16 | protected $output; | 17 | protected $io; |
17 | 18 | ||
18 | protected $duplicates = 0; | 19 | protected $duplicates = 0; |
19 | 20 | ||
@@ -32,7 +33,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand | |||
32 | 33 | ||
33 | protected function execute(InputInterface $input, OutputInterface $output) | 34 | protected function execute(InputInterface $input, OutputInterface $output) |
34 | { | 35 | { |
35 | $this->output = $output; | 36 | $this->io = new SymfonyStyle($input, $output); |
36 | 37 | ||
37 | $username = $input->getArgument('username'); | 38 | $username = $input->getArgument('username'); |
38 | 39 | ||
@@ -41,20 +42,22 @@ class CleanDuplicatesCommand extends ContainerAwareCommand | |||
41 | $user = $this->getUser($username); | 42 | $user = $this->getUser($username); |
42 | $this->cleanDuplicates($user); | 43 | $this->cleanDuplicates($user); |
43 | } catch (NoResultException $e) { | 44 | } catch (NoResultException $e) { |
44 | $output->writeln(sprintf('<error>User "%s" not found.</error>', $username)); | 45 | $this->io->error(sprintf('User "%s" not found.', $username)); |
45 | 46 | ||
46 | return 1; | 47 | return 1; |
47 | } | 48 | } |
49 | |||
50 | $this->io->success('Finished cleaning.'); | ||
48 | } else { | 51 | } else { |
49 | $users = $this->getContainer()->get('wallabag_user.user_repository')->findAll(); | 52 | $users = $this->getContainer()->get('wallabag_user.user_repository')->findAll(); |
50 | 53 | ||
51 | $output->writeln(sprintf('Cleaning through %d user accounts', count($users))); | 54 | $this->io->text(sprintf('Cleaning through <info>%d</info> user accounts', count($users))); |
52 | 55 | ||
53 | foreach ($users as $user) { | 56 | foreach ($users as $user) { |
54 | $output->writeln(sprintf('Processing user %s', $user->getUsername())); | 57 | $this->io->text(sprintf('Processing user <info>%s</info>', $user->getUsername())); |
55 | $this->cleanDuplicates($user); | 58 | $this->cleanDuplicates($user); |
56 | } | 59 | } |
57 | $output->writeln(sprintf('Finished cleaning. %d duplicates found in total', $this->duplicates)); | 60 | $this->io->success(sprintf('Finished cleaning. %d duplicates found in total', $this->duplicates)); |
58 | } | 61 | } |
59 | 62 | ||
60 | return 0; | 63 | return 0; |
@@ -68,7 +71,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand | |||
68 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); | 71 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
69 | $repo = $this->getContainer()->get('wallabag_core.entry_repository'); | 72 | $repo = $this->getContainer()->get('wallabag_core.entry_repository'); |
70 | 73 | ||
71 | $entries = $repo->getAllEntriesIdAndUrl($user->getId()); | 74 | $entries = $repo->findAllEntriesIdAndUrlByUserId($user->getId()); |
72 | 75 | ||
73 | $duplicatesCount = 0; | 76 | $duplicatesCount = 0; |
74 | $urls = []; | 77 | $urls = []; |
@@ -88,7 +91,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand | |||
88 | 91 | ||
89 | $this->duplicates += $duplicatesCount; | 92 | $this->duplicates += $duplicatesCount; |
90 | 93 | ||
91 | $this->output->writeln(sprintf('Cleaned %d duplicates for user %s', $duplicatesCount, $user->getUserName())); | 94 | $this->io->text(sprintf('Cleaned <info>%d</info> duplicates for user <info>%s</info>', $duplicatesCount, $user->getUserName())); |
92 | } | 95 | } |
93 | 96 | ||
94 | private function similarUrl($url) | 97 | private function similarUrl($url) |