diff --git a/app/config/services.yml b/app/config/services.yml index 3e89e29df..f1353c3b2 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -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' diff --git a/src/Wallabag/CoreBundle/Command/CleanDownloadedImagesCommand.php b/src/Wallabag/CoreBundle/Command/CleanDownloadedImagesCommand.php index b8f188deb..015a446bf 100644 --- a/src/Wallabag/CoreBundle/Command/CleanDownloadedImagesCommand.php +++ b/src/Wallabag/CoreBundle/Command/CleanDownloadedImagesCommand.php @@ -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, diff --git a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php index 865ec71ff..b590c2ab4 100644 --- a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php +++ b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php @@ -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', diff --git a/src/Wallabag/CoreBundle/Command/ExportCommand.php b/src/Wallabag/CoreBundle/Command/ExportCommand.php index 6a6e5c6a4..2f1992243 100644 --- a/src/Wallabag/CoreBundle/Command/ExportCommand.php +++ b/src/Wallabag/CoreBundle/Command/ExportCommand.php @@ -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', diff --git a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php index b1f1b7c99..56624738f 100644 --- a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php +++ b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php @@ -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'); } diff --git a/src/Wallabag/CoreBundle/Command/Import/ImportCommand.php b/src/Wallabag/CoreBundle/Command/Import/ImportCommand.php index f55c8c97f..a6b36f766 100644 --- a/src/Wallabag/CoreBundle/Command/Import/ImportCommand.php +++ b/src/Wallabag/CoreBundle/Command/Import/ImportCommand.php @@ -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') diff --git a/src/Wallabag/CoreBundle/Command/Import/RedisWorkerCommand.php b/src/Wallabag/CoreBundle/Command/Import/RedisWorkerCommand.php index 4c38058b5..00598ab2f 100644 --- a/src/Wallabag/CoreBundle/Command/Import/RedisWorkerCommand.php +++ b/src/Wallabag/CoreBundle/Command/Import/RedisWorkerCommand.php @@ -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) ; diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 877eedec3..f9dbcd1c0 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -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, diff --git a/src/Wallabag/CoreBundle/Command/ListUserCommand.php b/src/Wallabag/CoreBundle/Command/ListUserCommand.php index 3d1a23615..69a209767 100644 --- a/src/Wallabag/CoreBundle/Command/ListUserCommand.php +++ b/src/Wallabag/CoreBundle/Command/ListUserCommand.php @@ -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) diff --git a/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php b/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php index 96785940a..06444b6f8 100644 --- a/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php +++ b/src/Wallabag/CoreBundle/Command/ReloadEntryCommand.php @@ -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( diff --git a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php index f01685e8b..bd4da0f12 100644 --- a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php +++ b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php @@ -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', diff --git a/src/Wallabag/CoreBundle/Command/TagAllCommand.php b/src/Wallabag/CoreBundle/Command/TagAllCommand.php index 05a2e56ae..84b37e3ff 100644 --- a/src/Wallabag/CoreBundle/Command/TagAllCommand.php +++ b/src/Wallabag/CoreBundle/Command/TagAllCommand.php @@ -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, diff --git a/src/Wallabag/CoreBundle/Command/UpdatePicturesPathCommand.php b/src/Wallabag/CoreBundle/Command/UpdatePicturesPathCommand.php index 2e9c1d7d6..c6d1e4d49 100644 --- a/src/Wallabag/CoreBundle/Command/UpdatePicturesPathCommand.php +++ b/src/Wallabag/CoreBundle/Command/UpdatePicturesPathCommand.php @@ -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, diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index fa137f685..23b98fc0f 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -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; + } }