Merge pull request #7230 from yguedidi/lazy-commands

Make all commands lazy
This commit is contained in:
Yassine Guedidi 2024-02-05 09:07:21 +01:00 committed by GitHub
commit 8343a2d8f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 59 additions and 82 deletions

View file

@ -250,24 +250,6 @@ services:
arguments:
$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:
arguments:
$databaseDriver: '%database_driver%'
@ -275,26 +257,6 @@ services:
$defaultSettings: '%wallabag_core.default_internal_settings%'
$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:
alias: 'httplug.client.wallabag_core.entry.download_images'

View file

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

View file

@ -16,6 +16,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class CleanDuplicatesCommand extends Command
{
protected static $defaultName = 'wallabag:clean-duplicates';
protected static $defaultDescription = 'Cleans the database for duplicates';
protected SymfonyStyle $io;
protected int $duplicates = 0;
private EntityManagerInterface $entityManager;
@ -34,8 +37,6 @@ class CleanDuplicatesCommand extends Command
protected function configure()
{
$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')
->addArgument(
'username',

View file

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

View file

@ -15,6 +15,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class GenerateUrlHashesCommand extends Command
{
protected static $defaultName = 'wallabag:generate-hashed-urls';
protected static $defaultDescription = 'Generates hashed urls for each entry';
protected OutputInterface $output;
private EntityManagerInterface $entityManager;
private EntryRepository $entryRepository;
@ -32,8 +35,6 @@ class GenerateUrlHashesCommand extends Command
protected function configure()
{
$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')
->addArgument('username', InputArgument::OPTIONAL, 'User to process entries');
}

View file

@ -29,6 +29,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class ImportCommand extends Command
{
protected static $defaultName = 'wallabag:import';
protected static $defaultDescription = 'Import entries from a JSON export';
private EntityManagerInterface $entityManager;
private TokenStorageInterface $tokenStorage;
private UserRepository $userRepository;
@ -81,8 +84,6 @@ class ImportCommand extends Command
protected function configure()
{
$this
->setName('wallabag:import')
->setDescription('Import entries from a JSON export')
->addArgument('username', InputArgument::REQUIRED, 'User to populate')
->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')

View file

@ -13,6 +13,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class RedisWorkerCommand extends Command
{
protected static $defaultName = 'wallabag:import:redis-worker';
protected static $defaultDescription = 'Launch Redis worker';
private $container;
public function __construct(ContainerInterface $container)
@ -25,8 +28,6 @@ class RedisWorkerCommand extends Command
protected function configure()
{
$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')
->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
{
protected static $defaultName = 'wallabag:install';
protected static $defaultDescription = 'wallabag installer.';
private InputInterface $defaultInput;
private SymfonyStyle $io;
private array $functionExists = [
@ -63,8 +66,6 @@ class InstallCommand extends Command
protected function configure()
{
$this
->setName('wallabag:install')
->setDescription('wallabag installer.')
->addOption(
'reset',
null,

View file

@ -12,6 +12,9 @@ use Wallabag\CoreBundle\Repository\UserRepository;
class ListUserCommand extends Command
{
protected static $defaultName = 'wallabag:user:list';
protected static $defaultDescription = 'List all users';
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
@ -24,8 +27,6 @@ class ListUserCommand extends Command
protected function configure()
{
$this
->setName('wallabag:user:list')
->setDescription('List all users')
->setHelp('This command list all existing users')
->addArgument('search', InputArgument::OPTIONAL, 'Filter list by given search term')
->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
{
protected static $defaultName = 'wallabag:entry:reload';
protected static $defaultDescription = 'Reload entries';
private EntryRepository $entryRepository;
private UserRepository $userRepository;
private EntityManagerInterface $entityManager;
@ -38,8 +41,6 @@ class ReloadEntryCommand extends Command
protected function configure()
{
$this
->setName('wallabag:entry:reload')
->setDescription('Reload entries')
->setHelp('This command reload entries')
->addArgument('username', InputArgument::OPTIONAL, 'Reload entries only for the given user')
->addOption(

View file

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

View file

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

View file

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

View file

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