2017-08-21 08:36:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\CoreBundle\Command;
|
|
|
|
|
2022-12-15 19:57:02 +00:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2017-08-21 08:36:56 +00:00
|
|
|
use Doctrine\ORM\NoResultException;
|
2022-12-15 19:57:02 +00:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
2017-08-21 08:36:56 +00:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2023-07-28 12:58:43 +00:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2017-08-21 08:36:56 +00:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2022-08-28 00:01:46 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2017-08-21 08:36:56 +00:00
|
|
|
use Wallabag\CoreBundle\Event\EntrySavedEvent;
|
2022-04-24 15:48:59 +00:00
|
|
|
use Wallabag\CoreBundle\Helper\ContentProxy;
|
2022-04-24 15:58:57 +00:00
|
|
|
use Wallabag\CoreBundle\Repository\EntryRepository;
|
2023-12-30 22:38:22 +00:00
|
|
|
use Wallabag\CoreBundle\Repository\UserRepository;
|
2017-08-21 08:36:56 +00:00
|
|
|
|
2022-12-15 19:57:02 +00:00
|
|
|
class ReloadEntryCommand extends Command
|
2017-08-21 08:36:56 +00:00
|
|
|
{
|
2024-02-02 22:24:33 +00:00
|
|
|
protected static $defaultName = 'wallabag:entry:reload';
|
|
|
|
protected static $defaultDescription = 'Reload entries';
|
|
|
|
|
2022-12-15 19:57:02 +00:00
|
|
|
private EntryRepository $entryRepository;
|
|
|
|
private UserRepository $userRepository;
|
|
|
|
private EntityManagerInterface $entityManager;
|
|
|
|
private ContentProxy $contentProxy;
|
|
|
|
private EventDispatcherInterface $dispatcher;
|
|
|
|
|
|
|
|
public function __construct(EntryRepository $entryRepository, UserRepository $userRepository, EntityManagerInterface $entityManager, ContentProxy $contentProxy, EventDispatcherInterface $dispatcher)
|
|
|
|
{
|
|
|
|
$this->entryRepository = $entryRepository;
|
|
|
|
$this->userRepository = $userRepository;
|
|
|
|
$this->entityManager = $entityManager;
|
|
|
|
$this->contentProxy = $contentProxy;
|
|
|
|
$this->dispatcher = $dispatcher;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2017-08-21 08:36:56 +00:00
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setHelp('This command reload entries')
|
|
|
|
->addArgument('username', InputArgument::OPTIONAL, 'Reload entries only for the given user')
|
2023-07-28 12:58:43 +00:00
|
|
|
->addOption(
|
|
|
|
'only-not-parsed',
|
|
|
|
null,
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
'Only reload entries which have `is_not_parsed` set to `true`'
|
|
|
|
);
|
2017-08-21 08:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$io = new SymfonyStyle($input, $output);
|
|
|
|
|
2023-07-28 12:58:43 +00:00
|
|
|
$onlyNotParsed = (bool) $input->getOption('only-not-parsed');
|
2017-08-21 08:36:56 +00:00
|
|
|
$userId = null;
|
|
|
|
if ($username = $input->getArgument('username')) {
|
|
|
|
try {
|
2022-12-15 19:57:02 +00:00
|
|
|
$userId = $this->userRepository
|
2017-08-21 08:36:56 +00:00
|
|
|
->findOneByUserName($username)
|
|
|
|
->getId();
|
|
|
|
} catch (NoResultException $e) {
|
|
|
|
$io->error(sprintf('User "%s" not found.', $username));
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-28 12:58:43 +00:00
|
|
|
$methodName = $onlyNotParsed ? 'findAllEntriesIdByUserIdAndNotParsed' : 'findAllEntriesIdByUserId';
|
|
|
|
$entryIds = $this->entryRepository->$methodName($userId);
|
2017-08-21 08:36:56 +00:00
|
|
|
|
2018-09-05 12:25:32 +00:00
|
|
|
$nbEntries = \count($entryIds);
|
2017-08-21 08:36:56 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
$progressBar->start();
|
|
|
|
foreach ($entryIds as $entryId) {
|
2022-12-15 19:57:02 +00:00
|
|
|
$entry = $this->entryRepository->find($entryId);
|
2017-08-21 08:36:56 +00:00
|
|
|
|
2022-12-15 19:57:02 +00:00
|
|
|
$this->contentProxy->updateEntry($entry, $entry->getUrl());
|
|
|
|
$this->entityManager->persist($entry);
|
|
|
|
$this->entityManager->flush();
|
2017-08-21 08:36:56 +00:00
|
|
|
|
2022-12-15 19:57:02 +00:00
|
|
|
$this->dispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
|
2017-08-21 08:36:56 +00:00
|
|
|
$progressBar->advance();
|
|
|
|
|
2022-12-15 19:57:02 +00:00
|
|
|
$this->entityManager->detach($entry);
|
2017-08-21 08:36:56 +00:00
|
|
|
}
|
|
|
|
$progressBar->finish();
|
|
|
|
|
|
|
|
$io->newLine(2);
|
|
|
|
$io->success('Done.');
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|