mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-30 19:22:12 +00:00
Remove ContainerAwareCommand
from commands
And use DI to retrieve services in commands (except for `RedisWorkerCommand` where the container is injected, hard to find a better way, at least for now).
This commit is contained in:
parent
9c16dd7bd1
commit
5832482a10
14 changed files with 290 additions and 169 deletions
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Wallabag\CoreBundle\Command;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -15,8 +15,25 @@ use Wallabag\CoreBundle\Helper\ContentProxy;
|
|||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
|
||||
class ReloadEntryCommand extends ContainerAwareCommand
|
||||
class ReloadEntryCommand extends Command
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
|
@ -34,8 +51,7 @@ class ReloadEntryCommand extends ContainerAwareCommand
|
|||
$userId = null;
|
||||
if ($username = $input->getArgument('username')) {
|
||||
try {
|
||||
$userId = $this->getContainer()
|
||||
->get(UserRepository::class)
|
||||
$userId = $this->userRepository
|
||||
->findOneByUserName($username)
|
||||
->getId();
|
||||
} catch (NoResultException $e) {
|
||||
|
@ -45,8 +61,7 @@ class ReloadEntryCommand extends ContainerAwareCommand
|
|||
}
|
||||
}
|
||||
|
||||
$entryRepository = $this->getContainer()->get(EntryRepository::class);
|
||||
$entryIds = $entryRepository->findAllEntriesIdByUserId($userId);
|
||||
$entryIds = $this->entryRepository->findAllEntriesIdByUserId($userId);
|
||||
|
||||
$nbEntries = \count($entryIds);
|
||||
if (!$nbEntries) {
|
||||
|
@ -68,22 +83,18 @@ class ReloadEntryCommand extends ContainerAwareCommand
|
|||
|
||||
$progressBar = $io->createProgressBar($nbEntries);
|
||||
|
||||
$contentProxy = $this->getContainer()->get(ContentProxy::class);
|
||||
$em = $this->getContainer()->get(ManagerRegistry::class)->getManager();
|
||||
$dispatcher = $this->getContainer()->get(EventDispatcherInterface::class);
|
||||
|
||||
$progressBar->start();
|
||||
foreach ($entryIds as $entryId) {
|
||||
$entry = $entryRepository->find($entryId);
|
||||
$entry = $this->entryRepository->find($entryId);
|
||||
|
||||
$contentProxy->updateEntry($entry, $entry->getUrl());
|
||||
$em->persist($entry);
|
||||
$em->flush();
|
||||
$this->contentProxy->updateEntry($entry, $entry->getUrl());
|
||||
$this->entityManager->persist($entry);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$dispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
|
||||
$this->dispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
|
||||
$progressBar->advance();
|
||||
|
||||
$em->detach($entry);
|
||||
$this->entityManager->detach($entry);
|
||||
}
|
||||
$progressBar->finish();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue