From 511f1ce1e87e0f30a455ca6ed73e008bfd557f83 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Mon, 21 Aug 2017 10:36:56 +0200 Subject: Add reload entry command --- .../CoreBundle/Command/ReloadEntryCommand.php | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php (limited to 'src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php') 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 @@ +setName('wallabag:entry:reload') + ->setDescription('Reload entries') + ->setHelp('This command reload entries') + ->addArgument('username', InputArgument::OPTIONAL, 'Reload entries only for the given user') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new SymfonyStyle($input, $output); + + $userId = null; + if ($username = $input->getArgument('username')) { + try { + $userId = $this->getContainer() + ->get('wallabag_user.user_repository') + ->findOneByUserName($username) + ->getId(); + } catch (NoResultException $e) { + $io->error(sprintf('User "%s" not found.', $username)); + + return 1; + } + } + + $entryRepository = $this->getContainer()->get('wallabag_core.entry_repository'); + $entryIds = $entryRepository->getAllEntriesId($userId); + + $nbEntries = count($entryIds); + if (!$nbEntries) { + $io->success('No entry to reload.'); + + return 0; + } + + $io->note( + sprintf( + "You're going to reload %s entries. Depending on the number of entry to reload, this could be a very long process.", + $nbEntries + ) + ); + + if (!$io->confirm('Are you sure you want to proceed?')) { + return 0; + } + + $progressBar = $io->createProgressBar($nbEntries); + + $contentProxy = $this->getContainer()->get('wallabag_core.content_proxy'); + $em = $this->getContainer()->get('doctrine')->getManager(); + $dispatcher = $this->getContainer()->get('event_dispatcher'); + + $progressBar->start(); + foreach ($entryIds as $entryId) { + $entry = $entryRepository->find($entryId); + + $contentProxy->updateEntry($entry, $entry->getUrl()); + $em->persist($entry); + $em->flush(); + + $dispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); + $progressBar->advance(); + + $em->detach($entry); + } + $progressBar->finish(); + + $io->newLine(2); + $io->success('Done.'); + + return 0; + } +} -- cgit v1.2.3