From 3c73e7c7f0509fabdf1e7cc46d04183761d05d15 Mon Sep 17 00:00:00 2001 From: aryaantony92 Date: Mon, 18 Sep 2023 21:30:40 +0200 Subject: [PATCH] Improve naming of commands and use AsCommand Attribute --- src/Command/CleanupPendingOrdersCommand.php | 11 +++++------ src/Command/IndexService/BootstrapCommand.php | 13 +++++++++++-- src/Command/IndexService/EsSyncCommand.php | 9 +++++---- .../IndexService/ProcessPreparationQueueCommand.php | 7 +++++-- .../IndexService/ProcessUpdateIndexQueueCommand.php | 9 ++++++--- src/Command/IndexService/ResetQueueCommand.php | 12 ++++++++++-- src/Command/Voucher/CleanupReservationsCommand.php | 11 +++++------ src/Command/Voucher/CleanupStatisticsCommand.php | 11 +++++------ 8 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/Command/CleanupPendingOrdersCommand.php b/src/Command/CleanupPendingOrdersCommand.php index 072c4b365..969d59e44 100644 --- a/src/Command/CleanupPendingOrdersCommand.php +++ b/src/Command/CleanupPendingOrdersCommand.php @@ -19,20 +19,19 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\Cart; use Pimcore\Bundle\EcommerceFrameworkBundle\Factory; use Pimcore\Console\AbstractCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * @internal */ +#[AsCommand( + name: 'ecommerce:cleanup-pending-orders', + description: 'Cleans up orders with state pending payment after 1h -> delegates this to commit order processor', +)] class CleanupPendingOrdersCommand extends AbstractCommand { - protected function configure(): void - { - $this->setName('ecommerce:cleanup-pending-orders'); - $this->setDescription('Cleans up orders with state pending payment after 1h -> delegates this to commit order processor'); - } - protected function execute(InputInterface $input, OutputInterface $output): int { $checkoutManager = Factory::getInstance()->getCheckoutManager(new Cart()); diff --git a/src/Command/IndexService/BootstrapCommand.php b/src/Command/IndexService/BootstrapCommand.php index e01d870ba..6dfe43f77 100644 --- a/src/Command/IndexService/BootstrapCommand.php +++ b/src/Command/IndexService/BootstrapCommand.php @@ -22,6 +22,7 @@ use Pimcore\Console\Traits\Timeout; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Listing; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -29,6 +30,11 @@ /** * @internal */ +#[AsCommand( + name: 'ecommerce:index:create-or-update-indices', + description: 'Bootstrap tasks creating/updating index (for all tenants), use one of the options --create-or-update-index-structure or --update-index', + aliases: ['ecommerce:indexservice:bootstrap'] +)] class BootstrapCommand extends AbstractIndexServiceCommand { use Timeout; @@ -56,8 +62,6 @@ protected function configure(): void self::configureCommand($this); self::configureTimeout($this); $this - ->setName('ecommerce:indexservice:bootstrap') - ->setDescription('Bootstrap tasks creating/updating index (for all tenants), use one of the options --create-or-update-index-structure or --update-index') ->addOption('create-or-update-index-structure', null, InputOption::VALUE_NONE, 'Use to create or update the index structure') ->addOption('update-index', null, InputOption::VALUE_NONE, 'Use to rebuild the index data') ->addOption('object-list-class', null, InputOption::VALUE_REQUIRED, 'The object list class to use', '\\Pimcore\\Model\\DataObject\\Product\\Listing') @@ -74,6 +78,11 @@ protected function runBeforeFirstCommand(InputInterface $input, OutputInterface protected function fetchItems(InputInterface $input, OutputInterface $output): array { + // Remove in Version 2.0 + if($input->getArguments()['command'] == 'ecommerce:indexservice:bootstrap') { + $output->writeln('The command "ecommerce:indexservice:bootstrap" is deprecated and will be removed in Version 2.0. Please use "ecommerce:index:create-or-update-indices" instead.'); + + } $updateIndex = $input->getOption('update-index'); $createOrUpdateIndexStructure = $input->getOption('create-or-update-index-structure'); diff --git a/src/Command/IndexService/EsSyncCommand.php b/src/Command/IndexService/EsSyncCommand.php index 2ae347f07..1e1718623 100644 --- a/src/Command/IndexService/EsSyncCommand.php +++ b/src/Command/IndexService/EsSyncCommand.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\Factory; use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Worker\ElasticSearch\AbstractElasticSearch; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -27,6 +28,10 @@ /** * @internal */ +#[AsCommand( + name: 'ecommerce:indexservice:elasticsearch-sync', + description: 'Refresh elastic search (ES) index settings, mappings via native ES-API.' +)] class EsSyncCommand extends AbstractIndexServiceCommand { /** @@ -36,10 +41,6 @@ protected function configure(): void { parent::configure(); $this - ->setName('ecommerce:indexservice:elasticsearch-sync') - ->setDescription( - 'Refresh elastic search (ES) index settings, mappings via native ES-API.' - ) ->addArgument('mode', InputArgument::REQUIRED, 'reindex: Reindexes ES indices based on the their native reindexing API. Might be necessary when mapping has changed.'.PHP_EOL. 'update-synonyms: Activate changes in synonym files, by closing and reopening the ES index.' diff --git a/src/Command/IndexService/ProcessPreparationQueueCommand.php b/src/Command/IndexService/ProcessPreparationQueueCommand.php index 8ea706ea8..1bc512f13 100644 --- a/src/Command/IndexService/ProcessPreparationQueueCommand.php +++ b/src/Command/IndexService/ProcessPreparationQueueCommand.php @@ -22,6 +22,7 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\Model\IndexableInterface; use Pimcore\Console\Traits\Parallelization; use Pimcore\Console\Traits\Timeout; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -29,6 +30,10 @@ /** * @internal */ +#[AsCommand( + name: 'ecommerce:indexservice:process-preparation-queue', + description: 'Processes the ecommerce preparation queue based on the store table(s).', +)] class ProcessPreparationQueueCommand extends AbstractIndexServiceCommand { use Timeout; @@ -66,8 +71,6 @@ protected function configure(): void self::configureTimeout($this); $this - ->setName('ecommerce:indexservice:process-preparation-queue') - ->setDescription('Processes the ecommerce preparation queue based on the store table(s).') ->addOption('tenant', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Tenant to perform action on (defaults to all)') ; } diff --git a/src/Command/IndexService/ProcessUpdateIndexQueueCommand.php b/src/Command/IndexService/ProcessUpdateIndexQueueCommand.php index 198d8d18e..14f0343e7 100644 --- a/src/Command/IndexService/ProcessUpdateIndexQueueCommand.php +++ b/src/Command/IndexService/ProcessUpdateIndexQueueCommand.php @@ -21,6 +21,7 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Worker\ProductCentricBatchProcessingWorker; use Pimcore\Console\Traits\Parallelization; use Pimcore\Console\Traits\Timeout; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -28,6 +29,10 @@ /** * @internal */ +#[AsCommand( + name: 'ecommerce:indexservice:process-update-index-queue', + description: 'Processes the ecommerce queue / store table and updates the (search) index..', +)] class ProcessUpdateIndexQueueCommand extends AbstractIndexServiceCommand { use Timeout; @@ -70,9 +75,7 @@ protected function configure(): void self::configureTimeout($this); $this - ->setName('ecommerce:indexservice:process-update-queue') - ->setDescription('Processes the ecommerce queue / store table and updates the (search) index.') - ->addOption('tenant', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Tenant to perform action on (defaults to all)') + ->addOption('tenant', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Tenant to perform action on (defaults to all)') ; } diff --git a/src/Command/IndexService/ResetQueueCommand.php b/src/Command/IndexService/ResetQueueCommand.php index 2d616446d..c1792bfb2 100644 --- a/src/Command/IndexService/ResetQueueCommand.php +++ b/src/Command/IndexService/ResetQueueCommand.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\Factory; use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Worker\ProductCentricBatchProcessingWorker; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -26,6 +27,11 @@ /** * @internal */ +#[AsCommand( + name: 'ecommerce:index:reset-indices', + description: 'Resets the preparation or index-update queue (ONLY NEEDED if store table is out of sync)', + aliases: ['ecommerce:indexservice:reset-queue'] +)] class ResetQueueCommand extends AbstractIndexServiceCommand { /** @@ -36,8 +42,6 @@ protected function configure(): void parent::configure(); $this - ->setName('ecommerce:indexservice:reset-queue') - ->setDescription('Resets the preparation or index-update queue (ONLY NEEDED if store table is out of sync)') ->addArgument('queue', InputArgument::REQUIRED, 'Queue to reset (preparation|update-index)') ->addOption('tenant', null, InputOption::VALUE_REQUIRED, 'Tenant to perform action on. "*" means all tenants.'); } @@ -47,6 +51,10 @@ protected function configure(): void */ protected function execute(InputInterface $input, OutputInterface $output): int { + // Remove in version 2.0 + if($input->getArguments()['command'] == 'ecommerce:indexservice:reset-queue') { + $output->writeln('The command "portal-engine:update:index-recreate" is deprecated and will be removed in Version 2.0. Please use "ecommerce:index:reset-indices" instead.'); + } if (!($tenant = $input->getOption('tenant'))) { throw new \Exception('No tenant given'); } diff --git a/src/Command/Voucher/CleanupReservationsCommand.php b/src/Command/Voucher/CleanupReservationsCommand.php index d34c55568..fe283f140 100644 --- a/src/Command/Voucher/CleanupReservationsCommand.php +++ b/src/Command/Voucher/CleanupReservationsCommand.php @@ -18,20 +18,19 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\Factory; use Pimcore\Console\AbstractCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * @internal */ +#[AsCommand( + name: 'ecommerce:voucher:cleanup-reservations', + description: 'Cleans the token reservations due to sysConfig duration settings', +)] class CleanupReservationsCommand extends AbstractCommand { - protected function configure(): void - { - $this->setName('ecommerce:voucher:cleanup-reservations'); - $this->setDescription('Cleans the token reservations due to sysConfig duration settings'); - } - protected function execute(InputInterface $input, OutputInterface $output): int { $this->output->writeln('* Cleaning up reservations'); diff --git a/src/Command/Voucher/CleanupStatisticsCommand.php b/src/Command/Voucher/CleanupStatisticsCommand.php index 7bfce3368..3e306c806 100644 --- a/src/Command/Voucher/CleanupStatisticsCommand.php +++ b/src/Command/Voucher/CleanupStatisticsCommand.php @@ -18,20 +18,19 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\Factory; use Pimcore\Console\AbstractCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * @internal */ +#[AsCommand( + name: 'ecommerce:voucher:cleanup-statistics', + description: 'House keeping for Voucher Usage Statistics - cleans up all old data.', +)] class CleanupStatisticsCommand extends AbstractCommand { - protected function configure(): void - { - $this->setName('ecommerce:voucher:cleanup-statistics'); - $this->setDescription('House keeping for Voucher Usage Statistics - cleans up all old data.'); - } - protected function execute(InputInterface $input, OutputInterface $output): int { $this->output->writeln('* Cleaning up statistics');