Make all commands lazy

This commit is contained in:
Yassine Guedidi 2024-02-02 23:24:33 +01:00
parent 5aeb116d83
commit 7c4ca62eae
14 changed files with 59 additions and 82 deletions

View file

@ -250,24 +250,6 @@ services:
arguments: arguments:
$baseFolder: "%kernel.project_dir%/web/assets/images" $baseFolder: "%kernel.project_dir%/web/assets/images"
Wallabag\CoreBundle\Command\CleanDownloadedImagesCommand:
tags:
- { name: console.command, command: 'wallabag:clean-downloaded-images' }
Wallabag\CoreBundle\Command\CleanDuplicatesCommand:
tags:
- { name: console.command, command: 'wallabag:clean-duplicates' }
Wallabag\CoreBundle\Command\ExportCommand:
arguments:
$projectDir: '%kernel.project_dir%'
tags:
- { name: console.command, command: 'wallabag:export' }
Wallabag\CoreBundle\Command\GenerateUrlHashesCommand:
tags:
- { name: console.command, command: 'wallabag:generate-hashed-urls' }
Wallabag\CoreBundle\Command\InstallCommand: Wallabag\CoreBundle\Command\InstallCommand:
arguments: arguments:
$databaseDriver: '%database_driver%' $databaseDriver: '%database_driver%'
@ -275,26 +257,6 @@ services:
$defaultSettings: '%wallabag_core.default_internal_settings%' $defaultSettings: '%wallabag_core.default_internal_settings%'
$defaultIgnoreOriginInstanceRules: '%wallabag_core.default_ignore_origin_instance_rules%' $defaultIgnoreOriginInstanceRules: '%wallabag_core.default_ignore_origin_instance_rules%'
Wallabag\CoreBundle\Command\ListUserCommand:
tags:
- { name: console.command, command: 'wallabag:user:list' }
Wallabag\CoreBundle\Command\ReloadEntryCommand:
tags:
- { name: console.command, command: 'wallabag:entry:reload' }
Wallabag\CoreBundle\Command\ShowUserCommand:
tags:
- { name: console.command, command: 'wallabag:user:show' }
Wallabag\CoreBundle\Command\TagAllCommand:
tags:
- { name: console.command, command: 'wallabag:tag:all' }
Wallabag\CoreBundle\Command\Import\ImportCommand:
tags:
- { name: console.command, command: 'wallabag:import' }
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'

View file

@ -13,6 +13,9 @@ use Wallabag\CoreBundle\Repository\EntryRepository;
class CleanDownloadedImagesCommand extends Command class CleanDownloadedImagesCommand extends Command
{ {
protected static $defaultName = 'wallabag:clean-downloaded-images';
protected static $defaultDescription = 'Cleans downloaded images which are no more associated to an entry';
private EntryRepository $entryRepository; private EntryRepository $entryRepository;
private DownloadImages $downloadImages; private DownloadImages $downloadImages;
@ -27,8 +30,6 @@ class CleanDownloadedImagesCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:clean-downloaded-images')
->setDescription('Cleans downloaded images which are no more associated to an entry')
->addOption( ->addOption(
'dry-run', 'dry-run',
null, null,

View file

@ -16,6 +16,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class CleanDuplicatesCommand extends Command class CleanDuplicatesCommand extends Command
{ {
protected static $defaultName = 'wallabag:clean-duplicates';
protected static $defaultDescription = 'Cleans the database for duplicates';
protected SymfonyStyle $io; protected SymfonyStyle $io;
protected int $duplicates = 0; protected int $duplicates = 0;
private EntityManagerInterface $entityManager; private EntityManagerInterface $entityManager;
@ -34,8 +37,6 @@ class CleanDuplicatesCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:clean-duplicates')
->setDescription('Cleans the database for duplicates')
->setHelp('This command helps you to clean your articles list in case of duplicates') ->setHelp('This command helps you to clean your articles list in case of duplicates')
->addArgument( ->addArgument(
'username', 'username',

View file

@ -14,6 +14,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class ExportCommand extends Command class ExportCommand extends Command
{ {
protected static $defaultName = 'wallabag:export';
protected static $defaultDescription = 'Export all entries for an user';
private EntryRepository $entryRepository; private EntryRepository $entryRepository;
private UserRepository $userRepository; private UserRepository $userRepository;
private EntriesExport $entriesExport; private EntriesExport $entriesExport;
@ -32,8 +35,6 @@ class ExportCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:export')
->setDescription('Export all entries for an user')
->setHelp('This command helps you to export all entries for an user') ->setHelp('This command helps you to export all entries for an user')
->addArgument( ->addArgument(
'username', 'username',

View file

@ -15,6 +15,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class GenerateUrlHashesCommand extends Command class GenerateUrlHashesCommand extends Command
{ {
protected static $defaultName = 'wallabag:generate-hashed-urls';
protected static $defaultDescription = 'Generates hashed urls for each entry';
protected OutputInterface $output; protected OutputInterface $output;
private EntityManagerInterface $entityManager; private EntityManagerInterface $entityManager;
private EntryRepository $entryRepository; private EntryRepository $entryRepository;
@ -32,8 +35,6 @@ class GenerateUrlHashesCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:generate-hashed-urls')
->setDescription('Generates hashed urls for each entry')
->setHelp('This command helps you to generates hashes of the url of each entry, to check through API if an URL is already saved') ->setHelp('This command helps you to generates hashes of the url of each entry, to check through API if an URL is already saved')
->addArgument('username', InputArgument::OPTIONAL, 'User to process entries'); ->addArgument('username', InputArgument::OPTIONAL, 'User to process entries');
} }

View file

@ -29,6 +29,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class ImportCommand extends Command class ImportCommand extends Command
{ {
protected static $defaultName = 'wallabag:import';
protected static $defaultDescription = 'Import entries from a JSON export';
private EntityManagerInterface $entityManager; private EntityManagerInterface $entityManager;
private TokenStorageInterface $tokenStorage; private TokenStorageInterface $tokenStorage;
private UserRepository $userRepository; private UserRepository $userRepository;
@ -81,8 +84,6 @@ class ImportCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:import')
->setDescription('Import entries from a JSON export')
->addArgument('username', InputArgument::REQUIRED, 'User to populate') ->addArgument('username', InputArgument::REQUIRED, 'User to populate')
->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file')
->addOption('importer', null, InputOption::VALUE_OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, delicious, readability, firefox, chrome, elcurator, shaarli or pocket', 'v1') ->addOption('importer', null, InputOption::VALUE_OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, delicious, readability, firefox, chrome, elcurator, shaarli or pocket', 'v1')

View file

@ -13,6 +13,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class RedisWorkerCommand extends Command class RedisWorkerCommand extends Command
{ {
protected static $defaultName = 'wallabag:import:redis-worker';
protected static $defaultDescription = 'Launch Redis worker';
private $container; private $container;
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
@ -25,8 +28,6 @@ class RedisWorkerCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:import:redis-worker')
->setDescription('Launch Redis worker')
->addArgument('serviceName', InputArgument::REQUIRED, 'Service to use: wallabag_v1, wallabag_v2, pocket, readability, pinboard, delicious, firefox, chrome or instapaper') ->addArgument('serviceName', InputArgument::REQUIRED, 'Service to use: wallabag_v1, wallabag_v2, pocket, readability, pinboard, delicious, firefox, chrome or instapaper')
->addOption('maxIterations', '', InputOption::VALUE_OPTIONAL, 'Number of iterations before stopping', false) ->addOption('maxIterations', '', InputOption::VALUE_OPTIONAL, 'Number of iterations before stopping', false)
; ;

View file

@ -26,6 +26,9 @@ use Wallabag\CoreBundle\Entity\User;
class InstallCommand extends Command class InstallCommand extends Command
{ {
protected static $defaultName = 'wallabag:install';
protected static $defaultDescription = 'wallabag installer.';
private InputInterface $defaultInput; private InputInterface $defaultInput;
private SymfonyStyle $io; private SymfonyStyle $io;
private array $functionExists = [ private array $functionExists = [
@ -63,8 +66,6 @@ class InstallCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:install')
->setDescription('wallabag installer.')
->addOption( ->addOption(
'reset', 'reset',
null, null,

View file

@ -12,6 +12,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class ListUserCommand extends Command class ListUserCommand extends Command
{ {
protected static $defaultName = 'wallabag:user:list';
protected static $defaultDescription = 'List all users';
private UserRepository $userRepository; private UserRepository $userRepository;
public function __construct(UserRepository $userRepository) public function __construct(UserRepository $userRepository)
@ -24,8 +27,6 @@ class ListUserCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:user:list')
->setDescription('List all users')
->setHelp('This command list all existing users') ->setHelp('This command list all existing users')
->addArgument('search', InputArgument::OPTIONAL, 'Filter list by given search term') ->addArgument('search', InputArgument::OPTIONAL, 'Filter list by given search term')
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Max number of displayed users', 100) ->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Max number of displayed users', 100)

View file

@ -18,6 +18,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class ReloadEntryCommand extends Command class ReloadEntryCommand extends Command
{ {
protected static $defaultName = 'wallabag:entry:reload';
protected static $defaultDescription = 'Reload entries';
private EntryRepository $entryRepository; private EntryRepository $entryRepository;
private UserRepository $userRepository; private UserRepository $userRepository;
private EntityManagerInterface $entityManager; private EntityManagerInterface $entityManager;
@ -38,8 +41,6 @@ class ReloadEntryCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:entry:reload')
->setDescription('Reload entries')
->setHelp('This command reload entries') ->setHelp('This command reload entries')
->addArgument('username', InputArgument::OPTIONAL, 'Reload entries only for the given user') ->addArgument('username', InputArgument::OPTIONAL, 'Reload entries only for the given user')
->addOption( ->addOption(

View file

@ -13,6 +13,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class ShowUserCommand extends Command class ShowUserCommand extends Command
{ {
protected static $defaultName = 'wallabag:user:show';
protected static $defaultDescription = 'Show user details';
protected SymfonyStyle $io; protected SymfonyStyle $io;
private UserRepository $userRepository; private UserRepository $userRepository;
@ -26,8 +29,6 @@ class ShowUserCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:user:show')
->setDescription('Show user details')
->setHelp('This command shows the details for an user') ->setHelp('This command shows the details for an user')
->addArgument( ->addArgument(
'username', 'username',

View file

@ -15,6 +15,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class TagAllCommand extends Command class TagAllCommand extends Command
{ {
protected static $defaultName = 'wallabag:tag:all';
protected static $defaultDescription = 'Tag all entries using the tagging rules.';
private EntityManagerInterface $entityManager; private EntityManagerInterface $entityManager;
private RuleBasedTagger $ruleBasedTagger; private RuleBasedTagger $ruleBasedTagger;
private UserRepository $userRepository; private UserRepository $userRepository;
@ -31,8 +34,6 @@ class TagAllCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:tag:all')
->setDescription('Tag all entries using the tagging rules.')
->addArgument( ->addArgument(
'username', 'username',
InputArgument::REQUIRED, InputArgument::REQUIRED,

View file

@ -12,6 +12,9 @@ use Wallabag\CoreBundle\Repository\EntryRepository;
class UpdatePicturesPathCommand extends Command class UpdatePicturesPathCommand extends Command
{ {
protected static $defaultName = 'wallabag:update-pictures-path';
protected static $defaultDescription = 'Update the path of the pictures for each entry when you changed your wallabag instance URL.';
private EntityManagerInterface $entityManager; private EntityManagerInterface $entityManager;
private EntryRepository $entryRepository; private EntryRepository $entryRepository;
private string $wallabagUrl; private string $wallabagUrl;
@ -27,8 +30,6 @@ class UpdatePicturesPathCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setName('wallabag:update-pictures-path')
->setDescription('Update the path of the pictures for each entry when you changed your wallabag instance URL.')
->addArgument( ->addArgument(
'old-url', 'old-url',
InputArgument::REQUIRED, InputArgument::REQUIRED,

View file

@ -9,6 +9,7 @@ use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Command\LazyCommand;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
@ -86,10 +87,7 @@ class InstallCommandTest extends WallabagCoreTestCase
public function testRunInstallCommand() public function testRunInstallCommand()
{ {
$application = new Application($this->getTestClient()->getKernel()); $command = $this->getCommand();
/** @var InstallCommand $command */
$command = $application->find('wallabag:install');
// enable calling other commands for MySQL only because rollback isn't supported // enable calling other commands for MySQL only because rollback isn't supported
if (!$this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) { if (!$this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
@ -118,10 +116,7 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.'); $this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.');
} }
$application = new Application($this->getTestClient()->getKernel()); $command = $this->getCommand();
/** @var InstallCommand $command */
$command = $application->find('wallabag:install');
$command->disableRunOtherCommands(); $command->disableRunOtherCommands();
$tester = new CommandTester($command); $tester = new CommandTester($command);
@ -166,10 +161,9 @@ class InstallCommandTest extends WallabagCoreTestCase
]), new NullOutput()); ]), new NullOutput());
// start a new application to avoid lagging connexion to pgsql // start a new application to avoid lagging connexion to pgsql
$client = static::createClient(); $this->getNewClient();
$application = new Application($client->getKernel());
$command = $application->find('wallabag:install'); $command = $this->getCommand();
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->setInputs([ $tester->setInputs([
@ -195,10 +189,7 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.'); $this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.');
} }
$application = new Application($this->getTestClient()->getKernel()); $command = $this->getCommand();
/** @var InstallCommand $command */
$command = $application->find('wallabag:install');
$command->disableRunOtherCommands(); $command->disableRunOtherCommands();
$tester = new CommandTester($command); $tester = new CommandTester($command);
@ -242,7 +233,7 @@ class InstallCommandTest extends WallabagCoreTestCase
$command = $application->find('doctrine:database:create'); $command = $application->find('doctrine:database:create');
$command->run(new ArrayInput([]), new NullOutput()); $command->run(new ArrayInput([]), new NullOutput());
$command = $application->find('wallabag:install'); $command = $this->getCommand();
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->setInputs([ $tester->setInputs([
@ -265,10 +256,7 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.'); $this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.');
} }
$application = new Application($this->getTestClient()->getKernel()); $command = $this->getCommand();
/** @var InstallCommand $command */
$command = $application->find('wallabag:install');
$command->disableRunOtherCommands(); $command->disableRunOtherCommands();
$tester = new CommandTester($command); $tester = new CommandTester($command);
@ -281,4 +269,19 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->assertStringContainsString('Administration setup.', $tester->getDisplay()); $this->assertStringContainsString('Administration setup.', $tester->getDisplay());
$this->assertStringContainsString('Config setup.', $tester->getDisplay()); $this->assertStringContainsString('Config setup.', $tester->getDisplay());
} }
private function getCommand(): InstallCommand
{
$application = new Application($this->getTestClient()->getKernel());
$command = $application->find('wallabag:install');
if ($command instanceof LazyCommand) {
$command = $command->getCommand();
}
\assert($command instanceof InstallCommand);
return $command;
}
} }