mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-29 20:41:03 +00:00
Merge pull request #6152 from wallabag/fix/container-aware-command
Remove `ContainerAwareCommand` from commands
This commit is contained in:
commit
8f473ecf5c
13 changed files with 284 additions and 163 deletions
|
@ -197,6 +197,17 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$baseFolder: "%kernel.project_dir%/web/assets/images"
|
$baseFolder: "%kernel.project_dir%/web/assets/images"
|
||||||
|
|
||||||
|
Wallabag\CoreBundle\Command\ExportCommand:
|
||||||
|
arguments:
|
||||||
|
$projectDir: '%kernel.project_dir%'
|
||||||
|
|
||||||
|
Wallabag\CoreBundle\Command\InstallCommand:
|
||||||
|
arguments:
|
||||||
|
$databaseDriver: '%database_driver%'
|
||||||
|
$databaseName: '%database_name%'
|
||||||
|
$defaultSettings: '%wallabag_core.default_internal_settings%'
|
||||||
|
$defaultIgnoreOriginInstanceRules: '%wallabag_core.default_ignore_origin_instance_rules%'
|
||||||
|
|
||||||
wallabag_core.entry.download_images.client:
|
wallabag_core.entry.download_images.client:
|
||||||
alias: 'httplug.client.wallabag_core.entry.download_images'
|
alias: 'httplug.client.wallabag_core.entry.download_images'
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,6 @@ parameters:
|
||||||
count: 3
|
count: 3
|
||||||
path: src/Wallabag/ApiBundle/Controller/WallabagRestController.php
|
path: src/Wallabag/ApiBundle/Controller/WallabagRestController.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getConnection\\(\\)\\.$#"
|
|
||||||
count: 5
|
|
||||||
path: src/Wallabag/CoreBundle/Command/InstallCommand.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Call to an undefined method Wallabag\\\\CoreBundle\\\\Entity\\\\RuleInterface\\:\\:getConfig\\(\\)\\.$#"
|
message: "#^Call to an undefined method Wallabag\\\\CoreBundle\\\\Entity\\\\RuleInterface\\:\\:getConfig\\(\\)\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
@ -40,11 +35,6 @@ parameters:
|
||||||
count: 10
|
count: 10
|
||||||
path: src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
|
path: src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getConnection\\(\\)\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/Wallabag/ImportBundle/Command/ImportCommand.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Call to an undefined method Wallabag\\\\ImportBundle\\\\Import\\\\ImportInterface\\:\\:setFilepath\\(\\)\\.$#"
|
message: "#^Call to an undefined method Wallabag\\\\ImportBundle\\\\Import\\\\ImportInterface\\:\\:setFilepath\\(\\)\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
@ -84,3 +74,13 @@ parameters:
|
||||||
message: "#^Property Tests\\\\Wallabag\\\\CoreBundle\\\\Helper\\\\RedirectTest\\:\\:\\$routerMock has unknown class PHPUnit_Framework_MockObject_MockObject as its type\\.$#"
|
message: "#^Property Tests\\\\Wallabag\\\\CoreBundle\\\\Helper\\\\RedirectTest\\:\\:\\$routerMock has unknown class PHPUnit_Framework_MockObject_MockObject as its type\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: tests/Wallabag/CoreBundle/Helper/RedirectTest.php
|
path: tests/Wallabag/CoreBundle/Helper/RedirectTest.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
|
||||||
|
count: 1
|
||||||
|
path: src/Wallabag/CoreBundle/Command/InstallCommand.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
|
||||||
|
count: 1
|
||||||
|
path: src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Wallabag\CoreBundle\Command;
|
namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -11,8 +11,19 @@ use Symfony\Component\Finder\Finder;
|
||||||
use Wallabag\CoreBundle\Helper\DownloadImages;
|
use Wallabag\CoreBundle\Helper\DownloadImages;
|
||||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||||
|
|
||||||
class CleanDownloadedImagesCommand extends ContainerAwareCommand
|
class CleanDownloadedImagesCommand extends Command
|
||||||
{
|
{
|
||||||
|
private EntryRepository $entryRepository;
|
||||||
|
private DownloadImages $downloadImages;
|
||||||
|
|
||||||
|
public function __construct(EntryRepository $entryRepository, DownloadImages $downloadImages)
|
||||||
|
{
|
||||||
|
$this->entryRepository = $entryRepository;
|
||||||
|
$this->downloadImages = $downloadImages;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -36,8 +47,7 @@ class CleanDownloadedImagesCommand extends ContainerAwareCommand
|
||||||
$io->text('Dry run mode <info>enabled</info> (no images will be removed)');
|
$io->text('Dry run mode <info>enabled</info> (no images will be removed)');
|
||||||
}
|
}
|
||||||
|
|
||||||
$downloadImages = $this->getContainer()->get(DownloadImages::class);
|
$baseFolder = $this->downloadImages->getBaseFolder();
|
||||||
$baseFolder = $downloadImages->getBaseFolder();
|
|
||||||
|
|
||||||
$io->text('Retrieve existing images');
|
$io->text('Retrieve existing images');
|
||||||
|
|
||||||
|
@ -58,12 +68,12 @@ class CleanDownloadedImagesCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
$io->text('Retrieve valid folders attached to a user');
|
$io->text('Retrieve valid folders attached to a user');
|
||||||
|
|
||||||
$entries = $this->getContainer()->get(EntryRepository::class)->findAllEntriesIdByUserId();
|
$entries = $this->entryRepository->findAllEntriesIdByUserId();
|
||||||
|
|
||||||
// retrieve _valid_ folders from existing entries
|
// retrieve _valid_ folders from existing entries
|
||||||
$validPaths = [];
|
$validPaths = [];
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$path = $downloadImages->getRelativePath($entry['id']);
|
$path = $this->downloadImages->getRelativePath($entry['id']);
|
||||||
|
|
||||||
if (!file_exists($baseFolder . '/' . $path)) {
|
if (!file_exists($baseFolder . '/' . $path)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\NoResultException;
|
use Doctrine\ORM\NoResultException;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -14,12 +14,22 @@ use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
use Wallabag\UserBundle\Repository\UserRepository;
|
use Wallabag\UserBundle\Repository\UserRepository;
|
||||||
|
|
||||||
class CleanDuplicatesCommand extends ContainerAwareCommand
|
class CleanDuplicatesCommand extends Command
|
||||||
{
|
{
|
||||||
/** @var SymfonyStyle */
|
protected SymfonyStyle $io;
|
||||||
protected $io;
|
protected int $duplicates = 0;
|
||||||
|
private EntityManagerInterface $entityManager;
|
||||||
|
private EntryRepository $entryRepository;
|
||||||
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
protected $duplicates = 0;
|
public function __construct(EntityManagerInterface $entityManager, EntryRepository $entryRepository, UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
$this->entryRepository = $entryRepository;
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
|
@ -52,7 +62,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
$this->io->success('Finished cleaning.');
|
$this->io->success('Finished cleaning.');
|
||||||
} else {
|
} else {
|
||||||
$users = $this->getContainer()->get(UserRepository::class)->findAll();
|
$users = $this->userRepository->findAll();
|
||||||
|
|
||||||
$this->io->text(sprintf('Cleaning through <info>%d</info> user accounts', \count($users)));
|
$this->io->text(sprintf('Cleaning through <info>%d</info> user accounts', \count($users)));
|
||||||
|
|
||||||
|
@ -68,10 +78,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
private function cleanDuplicates(User $user)
|
private function cleanDuplicates(User $user)
|
||||||
{
|
{
|
||||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
$entries = $this->entryRepository->findAllEntriesIdAndUrlByUserId($user->getId());
|
||||||
$repo = $this->getContainer()->get(EntryRepository::class);
|
|
||||||
|
|
||||||
$entries = $repo->findAllEntriesIdAndUrlByUserId($user->getId());
|
|
||||||
|
|
||||||
$duplicatesCount = 0;
|
$duplicatesCount = 0;
|
||||||
$urls = [];
|
$urls = [];
|
||||||
|
@ -82,8 +89,8 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
||||||
if (\in_array($url, $urls, true)) {
|
if (\in_array($url, $urls, true)) {
|
||||||
++$duplicatesCount;
|
++$duplicatesCount;
|
||||||
|
|
||||||
$em->remove($repo->find($entry['id']));
|
$this->entityManager->remove($this->entryRepository->find($entry['id']));
|
||||||
$em->flush(); // Flushing at the end of the loop would require the instance not being online
|
$this->entityManager->flush(); // Flushing at the end of the loop would require the instance not being online
|
||||||
} else {
|
} else {
|
||||||
$urls[] = $entry['url'];
|
$urls[] = $entry['url'];
|
||||||
}
|
}
|
||||||
|
@ -112,6 +119,6 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function getUser($username)
|
private function getUser($username)
|
||||||
{
|
{
|
||||||
return $this->getContainer()->get(UserRepository::class)->findOneByUserName($username);
|
return $this->userRepository->findOneByUserName($username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace Wallabag\CoreBundle\Command;
|
namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
use Doctrine\ORM\NoResultException;
|
use Doctrine\ORM\NoResultException;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -12,8 +12,23 @@ use Wallabag\CoreBundle\Helper\EntriesExport;
|
||||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||||
use Wallabag\UserBundle\Repository\UserRepository;
|
use Wallabag\UserBundle\Repository\UserRepository;
|
||||||
|
|
||||||
class ExportCommand extends ContainerAwareCommand
|
class ExportCommand extends Command
|
||||||
{
|
{
|
||||||
|
private EntryRepository $entryRepository;
|
||||||
|
private UserRepository $userRepository;
|
||||||
|
private EntriesExport $entriesExport;
|
||||||
|
private string $projectDir;
|
||||||
|
|
||||||
|
public function __construct(EntryRepository $entryRepository, UserRepository $userRepository, EntriesExport $entriesExport, string $projectDir)
|
||||||
|
{
|
||||||
|
$this->entryRepository = $entryRepository;
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
$this->entriesExport = $entriesExport;
|
||||||
|
$this->projectDir = $projectDir;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -38,14 +53,14 @@ class ExportCommand extends ContainerAwareCommand
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user = $this->getContainer()->get(UserRepository::class)->findOneByUserName($input->getArgument('username'));
|
$user = $this->userRepository->findOneByUserName($input->getArgument('username'));
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
$io->error(sprintf('User "%s" not found.', $input->getArgument('username')));
|
$io->error(sprintf('User "%s" not found.', $input->getArgument('username')));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries = $this->getContainer()->get(EntryRepository::class)
|
$entries = $this->entryRepository
|
||||||
->getBuilderForAllByUser($user->getId())
|
->getBuilderForAllByUser($user->getId())
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
|
@ -55,11 +70,11 @@ class ExportCommand extends ContainerAwareCommand
|
||||||
$filePath = $input->getArgument('filepath');
|
$filePath = $input->getArgument('filepath');
|
||||||
|
|
||||||
if (!$filePath) {
|
if (!$filePath) {
|
||||||
$filePath = $this->getContainer()->getParameter('kernel.project_dir') . '/' . sprintf('%s-export.json', $user->getUsername());
|
$filePath = $this->projectDir . '/' . sprintf('%s-export.json', $user->getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$data = $this->getContainer()->get(EntriesExport::class)
|
$data = $this->entriesExport
|
||||||
->setEntries($entries)
|
->setEntries($entries)
|
||||||
->updateTitle('All')
|
->updateTitle('All')
|
||||||
->updateAuthor('All')
|
->updateAuthor('All')
|
||||||
|
|
|
@ -4,19 +4,30 @@ namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\NoResultException;
|
use Doctrine\ORM\NoResultException;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Wallabag\CoreBundle\Entity\Entry;
|
|
||||||
use Wallabag\CoreBundle\Helper\UrlHasher;
|
use Wallabag\CoreBundle\Helper\UrlHasher;
|
||||||
|
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
|
use Wallabag\UserBundle\Repository\UserRepository;
|
||||||
|
|
||||||
class GenerateUrlHashesCommand extends ContainerAwareCommand
|
class GenerateUrlHashesCommand extends Command
|
||||||
{
|
{
|
||||||
/** @var OutputInterface */
|
protected OutputInterface $output;
|
||||||
protected $output;
|
private EntityManagerInterface $entityManager;
|
||||||
|
private EntryRepository $entryRepository;
|
||||||
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $entityManager, EntryRepository $entryRepository, UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
$this->entryRepository = $entryRepository;
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
|
@ -43,7 +54,7 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$users = $this->getContainer()->get('doctrine')->getRepository(User::class)->findAll();
|
$users = $this->userRepository->findAll();
|
||||||
|
|
||||||
$output->writeln(sprintf('Generating hashed urls for "%d" users', \count($users)));
|
$output->writeln(sprintf('Generating hashed urls for "%d" users', \count($users)));
|
||||||
|
|
||||||
|
@ -59,23 +70,20 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
private function generateHashedUrls(User $user)
|
private function generateHashedUrls(User $user)
|
||||||
{
|
{
|
||||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
$entries = $this->entryRepository->findByEmptyHashedUrlAndUserId($user->getId());
|
||||||
$repo = $this->getContainer()->get('doctrine')->getRepository(Entry::class);
|
|
||||||
|
|
||||||
$entries = $repo->findByEmptyHashedUrlAndUserId($user->getId());
|
|
||||||
|
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$entry->setHashedUrl(UrlHasher::hashUrl($entry->getUrl()));
|
$entry->setHashedUrl(UrlHasher::hashUrl($entry->getUrl()));
|
||||||
$em->persist($entry);
|
$this->entityManager->persist($entry);
|
||||||
|
|
||||||
if (0 === ($i % 20)) {
|
if (0 === ($i % 20)) {
|
||||||
$em->flush();
|
$this->entityManager->flush();
|
||||||
}
|
}
|
||||||
++$i;
|
++$i;
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$this->output->writeln(sprintf('Generated hashed urls for user: %s', $user->getUserName()));
|
$this->output->writeln(sprintf('Generated hashed urls for user: %s', $user->getUserName()));
|
||||||
}
|
}
|
||||||
|
@ -89,11 +97,6 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function getUser($username)
|
private function getUser($username)
|
||||||
{
|
{
|
||||||
return $this->getContainer()->get('doctrine')->getRepository(User::class)->findOneByUserName($username);
|
return $this->userRepository->findOneByUserName($username);
|
||||||
}
|
|
||||||
|
|
||||||
private function getDoctrine()
|
|
||||||
{
|
|
||||||
return $this->getContainer()->get(ManagerRegistry::class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,10 @@ namespace Wallabag\CoreBundle\Command;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use Doctrine\DBAL\Exception\DriverException;
|
use Doctrine\DBAL\Exception\DriverException;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
|
||||||
use FOS\UserBundle\Event\UserEvent;
|
use FOS\UserBundle\Event\UserEvent;
|
||||||
use FOS\UserBundle\FOSUserEvents;
|
use FOS\UserBundle\FOSUserEvents;
|
||||||
use FOS\UserBundle\Model\UserManagerInterface;
|
use FOS\UserBundle\Model\UserManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
@ -22,28 +21,37 @@ use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule;
|
||||||
use Wallabag\CoreBundle\Entity\InternalSetting;
|
use Wallabag\CoreBundle\Entity\InternalSetting;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
|
|
||||||
class InstallCommand extends ContainerAwareCommand
|
class InstallCommand extends Command
|
||||||
{
|
{
|
||||||
/**
|
private InputInterface $defaultInput;
|
||||||
* @var InputInterface
|
private SymfonyStyle $io;
|
||||||
*/
|
private array $functionExists = [
|
||||||
private $defaultInput;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var SymfonyStyle
|
|
||||||
*/
|
|
||||||
private $io;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $functionExists = [
|
|
||||||
'curl_exec',
|
'curl_exec',
|
||||||
'curl_multi_init',
|
'curl_multi_init',
|
||||||
];
|
];
|
||||||
|
|
||||||
private bool $runOtherCommands = true;
|
private bool $runOtherCommands = true;
|
||||||
|
|
||||||
|
private EntityManagerInterface $entityManager;
|
||||||
|
private EventDispatcherInterface $dispatcher;
|
||||||
|
private UserManagerInterface $userManager;
|
||||||
|
private string $databaseDriver;
|
||||||
|
private string $databaseName;
|
||||||
|
private array $defaultSettings;
|
||||||
|
private array $defaultIgnoreOriginInstanceRules;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $entityManager, EventDispatcherInterface $dispatcher, UserManagerInterface $userManager, string $databaseDriver, string $databaseName, array $defaultSettings, array $defaultIgnoreOriginInstanceRules)
|
||||||
|
{
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
$this->dispatcher = $dispatcher;
|
||||||
|
$this->userManager = $userManager;
|
||||||
|
$this->databaseDriver = $databaseDriver;
|
||||||
|
$this->databaseName = $databaseName;
|
||||||
|
$this->defaultSettings = $defaultSettings;
|
||||||
|
$this->defaultIgnoreOriginInstanceRules = $defaultIgnoreOriginInstanceRules;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
public function disableRunOtherCommands(): void
|
public function disableRunOtherCommands(): void
|
||||||
{
|
{
|
||||||
$this->runOtherCommands = false;
|
$this->runOtherCommands = false;
|
||||||
|
@ -88,8 +96,6 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
$this->io->section('Step 1 of 4: Checking system requirements.');
|
$this->io->section('Step 1 of 4: Checking system requirements.');
|
||||||
|
|
||||||
$doctrineManager = $this->getContainer()->get(ManagerRegistry::class)->getManager();
|
|
||||||
|
|
||||||
$rows = [];
|
$rows = [];
|
||||||
|
|
||||||
// testing if database driver exists
|
// testing if database driver exists
|
||||||
|
@ -98,26 +104,26 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
$status = '<info>OK!</info>';
|
$status = '<info>OK!</info>';
|
||||||
$help = '';
|
$help = '';
|
||||||
|
|
||||||
if (!\extension_loaded($this->getContainer()->getParameter('database_driver'))) {
|
if (!\extension_loaded($this->databaseDriver)) {
|
||||||
$fulfilled = false;
|
$fulfilled = false;
|
||||||
$status = '<error>ERROR!</error>';
|
$status = '<error>ERROR!</error>';
|
||||||
$help = 'Database driver "' . $this->getContainer()->getParameter('database_driver') . '" is not installed.';
|
$help = 'Database driver "' . $this->databaseDriver . '" is not installed.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows[] = [sprintf($label, $this->getContainer()->getParameter('database_driver')), $status, $help];
|
$rows[] = [sprintf($label, $this->databaseDriver), $status, $help];
|
||||||
|
|
||||||
// testing if connection to the database can be etablished
|
// testing if connection to the database can be etablished
|
||||||
$label = '<comment>Database connection</comment>';
|
$label = '<comment>Database connection</comment>';
|
||||||
$status = '<info>OK!</info>';
|
$status = '<info>OK!</info>';
|
||||||
$help = '';
|
$help = '';
|
||||||
|
|
||||||
$conn = $this->getContainer()->get(ManagerRegistry::class)->getManager()->getConnection();
|
$conn = $this->entityManager->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$conn->connect();
|
$conn->connect();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if (false === strpos($e->getMessage(), 'Unknown database')
|
if (false === strpos($e->getMessage(), 'Unknown database')
|
||||||
&& false === strpos($e->getMessage(), 'database "' . $this->getContainer()->getParameter('database_name') . '" does not exist')) {
|
&& false === strpos($e->getMessage(), 'database "' . $this->databaseName . '" does not exist')) {
|
||||||
$fulfilled = false;
|
$fulfilled = false;
|
||||||
$status = '<error>ERROR!</error>';
|
$status = '<error>ERROR!</error>';
|
||||||
$help = 'Can\'t connect to the database: ' . $e->getMessage();
|
$help = 'Can\'t connect to the database: ' . $e->getMessage();
|
||||||
|
@ -146,7 +152,7 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
// testing if PostgreSQL > 9.1
|
// testing if PostgreSQL > 9.1
|
||||||
if ($conn->isConnected() && 'postgresql' === $conn->getDatabasePlatform()->getName()) {
|
if ($conn->isConnected() && 'postgresql' === $conn->getDatabasePlatform()->getName()) {
|
||||||
// return version should be like "PostgreSQL 9.5.4 on x86_64-apple-darwin15.6.0, compiled by Apple LLVM version 8.0.0 (clang-800.0.38), 64-bit"
|
// return version should be like "PostgreSQL 9.5.4 on x86_64-apple-darwin15.6.0, compiled by Apple LLVM version 8.0.0 (clang-800.0.38), 64-bit"
|
||||||
$version = $doctrineManager->getConnection()->query('SELECT version();')->fetchColumn();
|
$version = $conn->query('SELECT version();')->fetchColumn();
|
||||||
|
|
||||||
preg_match('/PostgreSQL ([0-9\.]+)/i', $version, $matches);
|
preg_match('/PostgreSQL ([0-9\.]+)/i', $version, $matches);
|
||||||
|
|
||||||
|
@ -260,10 +266,7 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
$user = $this->userManager->createUser();
|
||||||
|
|
||||||
$userManager = $this->getContainer()->get(UserManagerInterface::class);
|
|
||||||
$user = $userManager->createUser();
|
|
||||||
\assert($user instanceof User);
|
\assert($user instanceof User);
|
||||||
|
|
||||||
$user->setUsername($this->io->ask('Username', 'wallabag'));
|
$user->setUsername($this->io->ask('Username', 'wallabag'));
|
||||||
|
@ -277,11 +280,10 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
$user->setEnabled(true);
|
$user->setEnabled(true);
|
||||||
$user->addRole('ROLE_SUPER_ADMIN');
|
$user->addRole('ROLE_SUPER_ADMIN');
|
||||||
|
|
||||||
$em->persist($user);
|
$this->entityManager->persist($user);
|
||||||
|
|
||||||
// dispatch a created event so the associated config will be created
|
// dispatch a created event so the associated config will be created
|
||||||
$event = new UserEvent($user);
|
$this->dispatcher->dispatch(new UserEvent($user), FOSUserEvents::USER_CREATED);
|
||||||
$this->getContainer()->get(EventDispatcherInterface::class)->dispatch($event, FOSUserEvents::USER_CREATED);
|
|
||||||
|
|
||||||
$this->io->text('<info>Administration successfully setup.</info>');
|
$this->io->text('<info>Administration successfully setup.</info>');
|
||||||
|
|
||||||
|
@ -291,27 +293,28 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
private function setupConfig()
|
private function setupConfig()
|
||||||
{
|
{
|
||||||
$this->io->section('Step 4 of 4: Config setup.');
|
$this->io->section('Step 4 of 4: Config setup.');
|
||||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
|
||||||
|
|
||||||
// cleanup before insert new stuff
|
// cleanup before insert new stuff
|
||||||
$em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\InternalSetting')->execute();
|
$this->entityManager->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\InternalSetting')->execute();
|
||||||
$em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule')->execute();
|
$this->entityManager->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule')->execute();
|
||||||
|
|
||||||
foreach ($this->getContainer()->getParameter('wallabag_core.default_internal_settings') as $setting) {
|
foreach ($this->defaultSettings as $setting) {
|
||||||
$newSetting = new InternalSetting();
|
$newSetting = new InternalSetting();
|
||||||
$newSetting->setName($setting['name']);
|
$newSetting->setName($setting['name']);
|
||||||
$newSetting->setValue($setting['value']);
|
$newSetting->setValue($setting['value']);
|
||||||
$newSetting->setSection($setting['section']);
|
$newSetting->setSection($setting['section']);
|
||||||
$em->persist($newSetting);
|
|
||||||
|
$this->entityManager->persist($newSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->getContainer()->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $ignore_origin_instance_rule) {
|
foreach ($this->defaultIgnoreOriginInstanceRules as $ignore_origin_instance_rule) {
|
||||||
$newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule();
|
$newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule();
|
||||||
$newIgnoreOriginInstanceRule->setRule($ignore_origin_instance_rule['rule']);
|
$newIgnoreOriginInstanceRule->setRule($ignore_origin_instance_rule['rule']);
|
||||||
$em->persist($newIgnoreOriginInstanceRule);
|
|
||||||
|
$this->entityManager->persist($newIgnoreOriginInstanceRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$this->io->text('<info>Config successfully setup.</info>');
|
$this->io->text('<info>Config successfully setup.</info>');
|
||||||
|
|
||||||
|
@ -350,7 +353,7 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
// PDO does not always close the connection after Doctrine commands.
|
// PDO does not always close the connection after Doctrine commands.
|
||||||
// See https://github.com/symfony/symfony/issues/11750.
|
// See https://github.com/symfony/symfony/issues/11750.
|
||||||
$this->getContainer()->get(ManagerRegistry::class)->getManager()->getConnection()->close();
|
$this->entityManager->getConnection()->close();
|
||||||
|
|
||||||
if (0 !== $exitCode) {
|
if (0 !== $exitCode) {
|
||||||
$this->getApplication()->setAutoExit(true);
|
$this->getApplication()->setAutoExit(true);
|
||||||
|
@ -368,7 +371,7 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function isDatabasePresent()
|
private function isDatabasePresent()
|
||||||
{
|
{
|
||||||
$connection = $this->getContainer()->get(ManagerRegistry::class)->getManager()->getConnection();
|
$connection = $this->entityManager->getConnection();
|
||||||
$databaseName = $connection->getDatabase();
|
$databaseName = $connection->getDatabase();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -389,7 +392,7 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
// custom verification for sqlite, since `getListDatabasesSQL` doesn't work for sqlite
|
// custom verification for sqlite, since `getListDatabasesSQL` doesn't work for sqlite
|
||||||
if ('sqlite' === $schemaManager->getDatabasePlatform()->getName()) {
|
if ('sqlite' === $schemaManager->getDatabasePlatform()->getName()) {
|
||||||
$params = $this->getContainer()->get(Connection::class)->getParams();
|
$params = $connection->getParams();
|
||||||
|
|
||||||
if (isset($params['path']) && file_exists($params['path'])) {
|
if (isset($params['path']) && file_exists($params['path'])) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -415,7 +418,7 @@ class InstallCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function isSchemaPresent()
|
private function isSchemaPresent()
|
||||||
{
|
{
|
||||||
$schemaManager = $this->getContainer()->get(ManagerRegistry::class)->getManager()->getConnection()->getSchemaManager();
|
$schemaManager = $this->entityManager->getConnection()->getSchemaManager();
|
||||||
|
|
||||||
return \count($schemaManager->listTableNames()) > 0 ? true : false;
|
return \count($schemaManager->listTableNames()) > 0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Wallabag\CoreBundle\Command;
|
namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
@ -10,8 +10,17 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Wallabag\UserBundle\Repository\UserRepository;
|
use Wallabag\UserBundle\Repository\UserRepository;
|
||||||
|
|
||||||
class ListUserCommand extends ContainerAwareCommand
|
class ListUserCommand extends Command
|
||||||
{
|
{
|
||||||
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
|
public function __construct(UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -27,13 +36,13 @@ class ListUserCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$users = $this->getContainer()->get(UserRepository::class)
|
$users = $this->userRepository
|
||||||
->getQueryBuilderForSearch($input->getArgument('search'))
|
->getQueryBuilderForSearch($input->getArgument('search'))
|
||||||
->setMaxResults($input->getOption('limit'))
|
->setMaxResults($input->getOption('limit'))
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
|
|
||||||
$nbUsers = $this->getContainer()->get(UserRepository::class)
|
$nbUsers = $this->userRepository
|
||||||
->getSumUsers();
|
->getSumUsers();
|
||||||
|
|
||||||
$rows = [];
|
$rows = [];
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace Wallabag\CoreBundle\Command;
|
namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\NoResultException;
|
use Doctrine\ORM\NoResultException;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -15,8 +15,25 @@ use Wallabag\CoreBundle\Helper\ContentProxy;
|
||||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||||
use Wallabag\UserBundle\Repository\UserRepository;
|
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()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -34,8 +51,7 @@ class ReloadEntryCommand extends ContainerAwareCommand
|
||||||
$userId = null;
|
$userId = null;
|
||||||
if ($username = $input->getArgument('username')) {
|
if ($username = $input->getArgument('username')) {
|
||||||
try {
|
try {
|
||||||
$userId = $this->getContainer()
|
$userId = $this->userRepository
|
||||||
->get(UserRepository::class)
|
|
||||||
->findOneByUserName($username)
|
->findOneByUserName($username)
|
||||||
->getId();
|
->getId();
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
|
@ -45,8 +61,7 @@ class ReloadEntryCommand extends ContainerAwareCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$entryRepository = $this->getContainer()->get(EntryRepository::class);
|
$entryIds = $this->entryRepository->findAllEntriesIdByUserId($userId);
|
||||||
$entryIds = $entryRepository->findAllEntriesIdByUserId($userId);
|
|
||||||
|
|
||||||
$nbEntries = \count($entryIds);
|
$nbEntries = \count($entryIds);
|
||||||
if (!$nbEntries) {
|
if (!$nbEntries) {
|
||||||
|
@ -68,22 +83,18 @@ class ReloadEntryCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
$progressBar = $io->createProgressBar($nbEntries);
|
$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();
|
$progressBar->start();
|
||||||
foreach ($entryIds as $entryId) {
|
foreach ($entryIds as $entryId) {
|
||||||
$entry = $entryRepository->find($entryId);
|
$entry = $this->entryRepository->find($entryId);
|
||||||
|
|
||||||
$contentProxy->updateEntry($entry, $entry->getUrl());
|
$this->contentProxy->updateEntry($entry, $entry->getUrl());
|
||||||
$em->persist($entry);
|
$this->entityManager->persist($entry);
|
||||||
$em->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$dispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
|
$this->dispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
|
||||||
$progressBar->advance();
|
$progressBar->advance();
|
||||||
|
|
||||||
$em->detach($entry);
|
$this->entityManager->detach($entry);
|
||||||
}
|
}
|
||||||
$progressBar->finish();
|
$progressBar->finish();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace Wallabag\CoreBundle\Command;
|
namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
use Doctrine\ORM\NoResultException;
|
use Doctrine\ORM\NoResultException;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -11,10 +11,17 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
use Wallabag\UserBundle\Repository\UserRepository;
|
use Wallabag\UserBundle\Repository\UserRepository;
|
||||||
|
|
||||||
class ShowUserCommand extends ContainerAwareCommand
|
class ShowUserCommand extends Command
|
||||||
{
|
{
|
||||||
/** @var SymfonyStyle */
|
protected SymfonyStyle $io;
|
||||||
protected $io;
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
|
public function __construct(UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
|
@ -69,6 +76,6 @@ class ShowUserCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function getUser($username)
|
private function getUser($username)
|
||||||
{
|
{
|
||||||
return $this->getContainer()->get(UserRepository::class)->findOneByUserName($username);
|
return $this->userRepository->findOneByUserName($username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace Wallabag\CoreBundle\Command;
|
namespace Wallabag\CoreBundle\Command;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\NoResultException;
|
use Doctrine\ORM\NoResultException;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -13,8 +13,21 @@ use Wallabag\CoreBundle\Helper\RuleBasedTagger;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
use Wallabag\UserBundle\Repository\UserRepository;
|
use Wallabag\UserBundle\Repository\UserRepository;
|
||||||
|
|
||||||
class TagAllCommand extends ContainerAwareCommand
|
class TagAllCommand extends Command
|
||||||
{
|
{
|
||||||
|
private EntityManagerInterface $entityManager;
|
||||||
|
private RuleBasedTagger $ruleBasedTagger;
|
||||||
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $entityManager, RuleBasedTagger $ruleBasedTagger, UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
$this->ruleBasedTagger = $ruleBasedTagger;
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -39,19 +52,17 @@ class TagAllCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
$tagger = $this->getContainer()->get(RuleBasedTagger::class);
|
|
||||||
|
|
||||||
$io->text(sprintf('Tagging entries for user <info>%s</info>...', $user->getUserName()));
|
$io->text(sprintf('Tagging entries for user <info>%s</info>...', $user->getUserName()));
|
||||||
|
|
||||||
$entries = $tagger->tagAllForUser($user);
|
$entries = $this->ruleBasedTagger->tagAllForUser($user);
|
||||||
|
|
||||||
$io->text('Persist ' . \count($entries) . ' entries... ');
|
$io->text('Persist ' . \count($entries) . ' entries... ');
|
||||||
|
|
||||||
$em = $this->getContainer()->get('doctrine')->getManager();
|
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$em->persist($entry);
|
$this->entityManager->persist($entry);
|
||||||
}
|
}
|
||||||
$em->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$io->success('Done.');
|
$io->success('Done.');
|
||||||
|
|
||||||
|
@ -67,11 +78,6 @@ class TagAllCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function getUser($username)
|
private function getUser($username)
|
||||||
{
|
{
|
||||||
return $this->getContainer()->get(UserRepository::class)->findOneByUserName($username);
|
return $this->userRepository->findOneByUserName($username);
|
||||||
}
|
|
||||||
|
|
||||||
private function getDoctrine()
|
|
||||||
{
|
|
||||||
return $this->getContainer()->get(ManagerRegistry::class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace Wallabag\ImportBundle\Command;
|
namespace Wallabag\ImportBundle\Command;
|
||||||
|
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
||||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
@ -20,9 +20,39 @@ use Wallabag\ImportBundle\Import\ReadabilityImport;
|
||||||
use Wallabag\ImportBundle\Import\WallabagV1Import;
|
use Wallabag\ImportBundle\Import\WallabagV1Import;
|
||||||
use Wallabag\ImportBundle\Import\WallabagV2Import;
|
use Wallabag\ImportBundle\Import\WallabagV2Import;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
|
use Wallabag\UserBundle\Repository\UserRepository;
|
||||||
|
|
||||||
class ImportCommand extends ContainerAwareCommand
|
class ImportCommand extends Command
|
||||||
{
|
{
|
||||||
|
private EntityManagerInterface $entityManager;
|
||||||
|
private TokenStorageInterface $tokenStorage;
|
||||||
|
private UserRepository $userRepository;
|
||||||
|
private WallabagV2Import $wallabagV2Import;
|
||||||
|
private FirefoxImport $firefoxImport;
|
||||||
|
private ChromeImport $chromeImport;
|
||||||
|
private ReadabilityImport $readabilityImport;
|
||||||
|
private InstapaperImport $instapaperImport;
|
||||||
|
private PinboardImport $pinboardImport;
|
||||||
|
private DeliciousImport $deliciousImport;
|
||||||
|
private WallabagV1Import $wallabagV1Import;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $entityManager, TokenStorageInterface $tokenStorage, UserRepository $userRepository, WallabagV2Import $wallabagV2Import, FirefoxImport $firefoxImport, ChromeImport $chromeImport, ReadabilityImport $readabilityImport, InstapaperImport $instapaperImport, PinboardImport $pinboardImport, DeliciousImport $deliciousImport, WallabagV1Import $wallabagV1Import)
|
||||||
|
{
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
$this->tokenStorage = $tokenStorage;
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
$this->wallabagV2Import = $wallabagV2Import;
|
||||||
|
$this->firefoxImport = $firefoxImport;
|
||||||
|
$this->chromeImport = $chromeImport;
|
||||||
|
$this->readabilityImport = $readabilityImport;
|
||||||
|
$this->instapaperImport = $instapaperImport;
|
||||||
|
$this->pinboardImport = $pinboardImport;
|
||||||
|
$this->deliciousImport = $deliciousImport;
|
||||||
|
$this->wallabagV1Import = $wallabagV1Import;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -45,14 +75,13 @@ class ImportCommand extends ContainerAwareCommand
|
||||||
throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath')));
|
throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$em = $this->getContainer()->get(ManagerRegistry::class)->getManager();
|
|
||||||
// Turning off doctrine default logs queries for saving memory
|
// Turning off doctrine default logs queries for saving memory
|
||||||
$em->getConnection()->getConfiguration()->setSQLLogger(null);
|
$this->entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
|
||||||
|
|
||||||
if ($input->getOption('useUserId')) {
|
if ($input->getOption('useUserId')) {
|
||||||
$entityUser = $em->getRepository(User::class)->findOneById($input->getArgument('username'));
|
$entityUser = $this->userRepository->findOneById($input->getArgument('username'));
|
||||||
} else {
|
} else {
|
||||||
$entityUser = $em->getRepository(User::class)->findOneByUsername($input->getArgument('username'));
|
$entityUser = $this->userRepository->findOneByUsername($input->getArgument('username'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\is_object($entityUser)) {
|
if (!\is_object($entityUser)) {
|
||||||
|
@ -66,33 +95,33 @@ class ImportCommand extends ContainerAwareCommand
|
||||||
'main',
|
'main',
|
||||||
$entityUser->getRoles());
|
$entityUser->getRoles());
|
||||||
|
|
||||||
$this->getContainer()->get(TokenStorageInterface::class)->setToken($token);
|
$this->tokenStorage->setToken($token);
|
||||||
$user = $this->getContainer()->get(TokenStorageInterface::class)->getToken()->getUser();
|
$user = $this->tokenStorage->getToken()->getUser();
|
||||||
|
|
||||||
switch ($input->getOption('importer')) {
|
switch ($input->getOption('importer')) {
|
||||||
case 'v2':
|
case 'v2':
|
||||||
$import = $this->getContainer()->get(WallabagV2Import::class);
|
$import = $this->wallabagV2Import;
|
||||||
break;
|
break;
|
||||||
case 'firefox':
|
case 'firefox':
|
||||||
$import = $this->getContainer()->get(FirefoxImport::class);
|
$import = $this->firefoxImport;
|
||||||
break;
|
break;
|
||||||
case 'chrome':
|
case 'chrome':
|
||||||
$import = $this->getContainer()->get(ChromeImport::class);
|
$import = $this->chromeImport;
|
||||||
break;
|
break;
|
||||||
case 'readability':
|
case 'readability':
|
||||||
$import = $this->getContainer()->get(ReadabilityImport::class);
|
$import = $this->readabilityImport;
|
||||||
break;
|
break;
|
||||||
case 'instapaper':
|
case 'instapaper':
|
||||||
$import = $this->getContainer()->get(InstapaperImport::class);
|
$import = $this->instapaperImport;
|
||||||
break;
|
break;
|
||||||
case 'pinboard':
|
case 'pinboard':
|
||||||
$import = $this->getContainer()->get(PinboardImport::class);
|
$import = $this->pinboardImport;
|
||||||
break;
|
break;
|
||||||
case 'delicious':
|
case 'delicious':
|
||||||
$import = $this->getContainer()->get(DeliciousImport::class);
|
$import = $this->deliciousImport;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$import = $this->getContainer()->get(WallabagV1Import::class);
|
$import = $this->wallabagV1Import;
|
||||||
}
|
}
|
||||||
|
|
||||||
$import->setMarkAsRead($input->getOption('markAsRead'));
|
$import->setMarkAsRead($input->getOption('markAsRead'));
|
||||||
|
@ -109,7 +138,7 @@ class ImportCommand extends ContainerAwareCommand
|
||||||
$output->writeln('<comment>' . $summary['skipped'] . ' already saved</comment>');
|
$output->writeln('<comment>' . $summary['skipped'] . ' already saved</comment>');
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->clear();
|
$this->entityManager->clear();
|
||||||
|
|
||||||
$output->writeln('End : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---');
|
$output->writeln('End : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---');
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,25 @@
|
||||||
namespace Wallabag\ImportBundle\Command;
|
namespace Wallabag\ImportBundle\Command;
|
||||||
|
|
||||||
use Simpleue\Worker\QueueWorker;
|
use Simpleue\Worker\QueueWorker;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
||||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
class RedisWorkerCommand extends ContainerAwareCommand
|
class RedisWorkerCommand extends Command
|
||||||
{
|
{
|
||||||
|
private $container;
|
||||||
|
|
||||||
|
public function __construct(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -29,13 +39,13 @@ class RedisWorkerCommand extends ContainerAwareCommand
|
||||||
|
|
||||||
$serviceName = $input->getArgument('serviceName');
|
$serviceName = $input->getArgument('serviceName');
|
||||||
|
|
||||||
if (!$this->getContainer()->has('wallabag_import.queue.redis.' . $serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.' . $serviceName)) {
|
if (!$this->container->has('wallabag_import.queue.redis.' . $serviceName) || !$this->container->has('wallabag_import.consumer.redis.' . $serviceName)) {
|
||||||
throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
|
throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$worker = new QueueWorker(
|
$worker = new QueueWorker(
|
||||||
$this->getContainer()->get('wallabag_import.queue.redis.' . $serviceName),
|
$this->container->get('wallabag_import.queue.redis.' . $serviceName),
|
||||||
$this->getContainer()->get('wallabag_import.consumer.redis.' . $serviceName),
|
$this->container->get('wallabag_import.consumer.redis.' . $serviceName),
|
||||||
(int) $input->getOption('maxIterations')
|
(int) $input->getOption('maxIterations')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue